|
1 | 1 | { |
2 | 2 | "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": { |
| 6 | + "id": "view-in-github", |
| 7 | + "colab_type": "text" |
| 8 | + }, |
| 9 | + "source": [ |
| 10 | + "<a href=\"https://colab.research.google.com/github/ruh-al-tarikh/Cli/blob/main/docs/scalars_and_keras.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" |
| 11 | + ] |
| 12 | + }, |
3 | 13 | { |
4 | 14 | "cell_type": "markdown", |
5 | 15 | "metadata": { |
|
9 | 19 | "##### Copyright 2019 The TensorFlow Authors." |
10 | 20 | ] |
11 | 21 | }, |
| 22 | + { |
| 23 | + "cell_type": "code", |
| 24 | + "source": [ |
| 25 | + "# @title AI prompt cell\n", |
| 26 | + "\n", |
| 27 | + "import ipywidgets as widgets\n", |
| 28 | + "from IPython.display import display, HTML, Markdown,clear_output\n", |
| 29 | + "from google.colab import ai\n", |
| 30 | + "\n", |
| 31 | + "dropdown = widgets.Dropdown(\n", |
| 32 | + " options=[],\n", |
| 33 | + " layout={'width': 'auto'}\n", |
| 34 | + ")\n", |
| 35 | + "\n", |
| 36 | + "def update_model_list(new_options):\n", |
| 37 | + " dropdown.options = new_options\n", |
| 38 | + "update_model_list(ai.list_models())\n", |
| 39 | + "\n", |
| 40 | + "text_input = widgets.Textarea(\n", |
| 41 | + " placeholder='Ask me anything....',\n", |
| 42 | + " layout={'width': 'auto', 'height': '100px'},\n", |
| 43 | + ")\n", |
| 44 | + "\n", |
| 45 | + "button = widgets.Button(\n", |
| 46 | + " description='Submit Text',\n", |
| 47 | + " disabled=False,\n", |
| 48 | + " tooltip='Click to submit the text',\n", |
| 49 | + " icon='check'\n", |
| 50 | + ")\n", |
| 51 | + "\n", |
| 52 | + "output_area = widgets.Output(\n", |
| 53 | + " layout={'width': 'auto', 'max_height': '300px','overflow_y': 'scroll'}\n", |
| 54 | + ")\n", |
| 55 | + "\n", |
| 56 | + "def on_button_clicked(b):\n", |
| 57 | + " with output_area:\n", |
| 58 | + " output_area.clear_output(wait=False)\n", |
| 59 | + " accumulated_content = \"\"\n", |
| 60 | + " for new_chunk in ai.generate_text(prompt=text_input.value, model_name=dropdown.value, stream=True):\n", |
| 61 | + " if new_chunk is None:\n", |
| 62 | + " continue\n", |
| 63 | + " accumulated_content += new_chunk\n", |
| 64 | + " clear_output(wait=True)\n", |
| 65 | + " display(Markdown(accumulated_content))\n", |
| 66 | + "\n", |
| 67 | + "button.on_click(on_button_clicked)\n", |
| 68 | + "vbox = widgets.GridBox([dropdown, text_input, button, output_area])\n", |
| 69 | + "\n", |
| 70 | + "display(HTML(\"\"\"\n", |
| 71 | + "<style>\n", |
| 72 | + ".widget-dropdown select {\n", |
| 73 | + " font-size: 18px;\n", |
| 74 | + " font-family: \"Arial\", sans-serif;\n", |
| 75 | + "}\n", |
| 76 | + ".widget-textarea textarea {\n", |
| 77 | + " font-size: 18px;\n", |
| 78 | + " font-family: \"Arial\", sans-serif;\n", |
| 79 | + "}\n", |
| 80 | + "</style>\n", |
| 81 | + "\"\"\"))\n", |
| 82 | + "display(vbox)\n" |
| 83 | + ], |
| 84 | + "metadata": { |
| 85 | + "cellView": "form", |
| 86 | + "id": "UvpcCgErRfU2" |
| 87 | + }, |
| 88 | + "execution_count": null, |
| 89 | + "outputs": [] |
| 90 | + }, |
12 | 91 | { |
13 | 92 | "cell_type": "code", |
14 | 93 | "execution_count": null, |
|
187 | 266 | "2. Specify a log directory\n", |
188 | 267 | "3. Pass the TensorBoard callback to Keras' [Model.fit()](https://www.tensorflow.org/api_docs/python/tf/keras/models/Model#fit).\n", |
189 | 268 | "\n", |
190 | | - "TensorBoard reads log data from the log directory hierarchy. In this notebook, the root log directory is ```logs/scalars```, suffixed by a timestamped subdirectory. The timestamped subdirectory enables you to easily identify and select training runs as you use TensorBoard and iterate on your model.\n", |
191 | | - "" |
| 269 | + "TensorBoard reads log data from the log directory hierarchy. In this notebook, the root log directory is ```logs/scalars```, suffixed by a timestamped subdirectory. The timestamped subdirectory enables you to easily identify and select training runs as you use TensorBoard and iterate on your model.\n" |
192 | 270 | ] |
193 | 271 | }, |
194 | 272 | { |
|
884 | 962 | "colab": { |
885 | 963 | "name": "scalars_and_keras.ipynb", |
886 | 964 | "toc_visible": true, |
887 | | - "provenance": [] |
| 965 | + "provenance": [], |
| 966 | + "gpuType": "T4", |
| 967 | + "cell_execution_strategy": "setup", |
| 968 | + "include_colab_link": true |
888 | 969 | }, |
889 | 970 | "kernelspec": { |
890 | 971 | "display_name": "Python 3", |
891 | 972 | "name": "python3" |
892 | | - } |
| 973 | + }, |
| 974 | + "accelerator": "GPU" |
893 | 975 | }, |
894 | 976 | "nbformat": 4, |
895 | 977 | "nbformat_minor": 0 |
|
0 commit comments