2019-04-10 12:41:39 +08:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2019-04-11 02:30:01 +08:00
|
|
|
"execution_count": null,
|
2019-04-10 12:41:39 +08:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"import tensorflow as tf\n",
|
|
|
|
"import gradio"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2019-04-11 02:30:01 +08:00
|
|
|
"execution_count": null,
|
2019-04-10 12:41:39 +08:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"(x_train, y_train),(x_test, y_test) = tf.keras.datasets.mnist.load_data()\n",
|
|
|
|
"x_train, x_test = x_train / 255.0, x_test / 255.0"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 3,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"model = tf.keras.models.Sequential([\n",
|
|
|
|
" tf.keras.layers.Flatten(),\n",
|
|
|
|
" tf.keras.layers.Dense(512, activation=tf.nn.relu),\n",
|
|
|
|
" tf.keras.layers.Dropout(0.2),\n",
|
|
|
|
" tf.keras.layers.Dense(10, activation=tf.nn.softmax)\n",
|
|
|
|
"])\n",
|
|
|
|
"\n",
|
|
|
|
"model.compile(optimizer='adam',\n",
|
|
|
|
" loss='sparse_categorical_crossentropy',\n",
|
|
|
|
" metrics=['accuracy'])"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 4,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "stdout",
|
|
|
|
"output_type": "stream",
|
|
|
|
"text": [
|
|
|
|
"Epoch 1/1\n",
|
2019-04-11 02:30:01 +08:00
|
|
|
"60000/60000 [==============================] - 24s 407us/step - loss: 0.2171 - acc: 0.9355\n"
|
2019-04-10 12:41:39 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"text/plain": [
|
2019-04-11 02:30:01 +08:00
|
|
|
"<tensorflow.python.keras.callbacks.History at 0x23bf7b1ae10>"
|
2019-04-10 12:41:39 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
"execution_count": 4,
|
|
|
|
"metadata": {},
|
|
|
|
"output_type": "execute_result"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
|
|
|
"model.fit(x_train, y_train, epochs=1)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 5,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"iface = gradio.Interface(inputs=\"sketchpad\", outputs=\"label\", model=model, model_type='keras')"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 6,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "stdout",
|
|
|
|
"output_type": "stream",
|
|
|
|
"text": [
|
|
|
|
"No validation samples for this interface... skipping validation.\n",
|
|
|
|
"NOTE: Gradio is in beta stage, please report all bugs to: contact.gradio@gmail.com\n",
|
2019-04-11 02:30:01 +08:00
|
|
|
"Model is running locally at: http://localhost:7860/\n",
|
2019-04-10 12:41:39 +08:00
|
|
|
"To create a public link, set `share=True` in the argument to `launch()`\n"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"text/html": [
|
|
|
|
"\n",
|
|
|
|
" <iframe\n",
|
|
|
|
" width=\"1000\"\n",
|
|
|
|
" height=\"500\"\n",
|
2019-04-11 02:30:01 +08:00
|
|
|
" src=\"http://localhost:7860/\"\n",
|
2019-04-10 12:41:39 +08:00
|
|
|
" frameborder=\"0\"\n",
|
|
|
|
" allowfullscreen\n",
|
|
|
|
" ></iframe>\n",
|
|
|
|
" "
|
|
|
|
],
|
|
|
|
"text/plain": [
|
2019-04-11 02:30:01 +08:00
|
|
|
"<IPython.lib.display.IFrame at 0x23bf7900160>"
|
2019-04-10 12:41:39 +08:00
|
|
|
]
|
|
|
|
},
|
|
|
|
"metadata": {},
|
|
|
|
"output_type": "display_data"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"text/plain": [
|
2019-04-11 02:30:01 +08:00
|
|
|
"(<gradio.networking.serve_files_in_background.<locals>.HTTPServer at 0x23bf9174b70>,\n",
|
|
|
|
" 'http://localhost:7860/',\n",
|
2019-04-10 12:41:39 +08:00
|
|
|
" None)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
"execution_count": 6,
|
|
|
|
"metadata": {},
|
|
|
|
"output_type": "execute_result"
|
2019-04-11 02:30:01 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "stderr",
|
|
|
|
"output_type": "stream",
|
|
|
|
"text": [
|
|
|
|
"Error in connection handler\n",
|
|
|
|
"Traceback (most recent call last):\n",
|
|
|
|
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\site-packages\\websockets\\server.py\", line 169, in handler\n",
|
|
|
|
" yield from self.ws_handler(self, path)\n",
|
|
|
|
" File \"C:\\Users\\islam\\Repos\\gradio\\gradio\\interface.py\", line 114, in communicate\n",
|
|
|
|
" msg = json.loads(await websocket.recv())\n",
|
|
|
|
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\json\\__init__.py\", line 354, in loads\n",
|
|
|
|
" return _default_decoder.decode(s)\n",
|
|
|
|
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\json\\decoder.py\", line 339, in decode\n",
|
|
|
|
" obj, end = self.raw_decode(s, idx=_w(s, 0).end())\n",
|
|
|
|
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\json\\decoder.py\", line 357, in raw_decode\n",
|
|
|
|
" raise JSONDecodeError(\"Expecting value\", s, err.value) from None\n",
|
|
|
|
"json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)\n"
|
|
|
|
]
|
2019-04-10 12:41:39 +08:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
|
|
|
"iface.launch(inline=True, share=False)"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata": {
|
|
|
|
"kernelspec": {
|
2019-04-11 07:39:43 +08:00
|
|
|
"display_name": "Python 3",
|
2019-04-10 12:41:39 +08:00
|
|
|
"language": "python",
|
2019-04-11 07:39:43 +08:00
|
|
|
"name": "python3"
|
2019-04-10 12:41:39 +08:00
|
|
|
},
|
|
|
|
"language_info": {
|
|
|
|
"codemirror_mode": {
|
|
|
|
"name": "ipython",
|
|
|
|
"version": 3
|
|
|
|
},
|
|
|
|
"file_extension": ".py",
|
|
|
|
"mimetype": "text/x-python",
|
|
|
|
"name": "python",
|
|
|
|
"nbconvert_exporter": "python",
|
|
|
|
"pygments_lexer": "ipython3",
|
2019-04-11 07:39:43 +08:00
|
|
|
"version": "3.7.1"
|
2019-04-10 12:41:39 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"nbformat": 4,
|
|
|
|
"nbformat_minor": 2
|
|
|
|
}
|