Skip to content

Commit 9d0f2a2

Browse files
committed
Created using Colab
1 parent 09c92a3 commit 9d0f2a2

1 file changed

Lines changed: 86 additions & 4 deletions

File tree

docs/scalars_and_keras.ipynb

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"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+
},
313
{
414
"cell_type": "markdown",
515
"metadata": {
@@ -9,6 +19,75 @@
919
"##### Copyright 2019 The TensorFlow Authors."
1020
]
1121
},
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+
},
1291
{
1392
"cell_type": "code",
1493
"execution_count": null,
@@ -187,8 +266,7 @@
187266
"2. Specify a log directory\n",
188267
"3. Pass the TensorBoard callback to Keras' [Model.fit()](https://www.tensorflow.org/api_docs/python/tf/keras/models/Model#fit).\n",
189268
"\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"
192270
]
193271
},
194272
{
@@ -884,12 +962,16 @@
884962
"colab": {
885963
"name": "scalars_and_keras.ipynb",
886964
"toc_visible": true,
887-
"provenance": []
965+
"provenance": [],
966+
"gpuType": "T4",
967+
"cell_execution_strategy": "setup",
968+
"include_colab_link": true
888969
},
889970
"kernelspec": {
890971
"display_name": "Python 3",
891972
"name": "python3"
892-
}
973+
},
974+
"accelerator": "GPU"
893975
},
894976
"nbformat": 4,
895977
"nbformat_minor": 0

0 commit comments

Comments
 (0)