mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-17 11:29:58 +08:00
added networking methods
This commit is contained in:
parent
9ed6d3b8d7
commit
e993131a4b
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,5 +5,5 @@ staticfiles
|
||||
*.sqlite3
|
||||
.idea/*
|
||||
.ipynb_checkpoints/*
|
||||
*.h5
|
||||
.models/*
|
||||
|
||||
|
@ -2,26 +2,16 @@
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="fd73cd66-e80f-470e-a2ec-e220d3b6b864" name="Default Changelist" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/.ipynb_checkpoints/Emotion Detector-checkpoint.ipynb" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/Emotion Detector.ipynb" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/js/all-io.js" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/js/class-output.js" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/js/emotion-detector.js" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/js/sketchpad-input.js" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/js/webcam-input.js" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/model.h5" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/model2.h5" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/script.py" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/templates/all_io.html" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/templates/class_output.html" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/templates/emotion_detector.html" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/templates/sketchpad_input.html" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/templates/tmp_html.html" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/templates/webcam_input.html" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Usage.ipynb" beforeDir="false" afterPath="$PROJECT_DIR$/Usage.ipynb" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/inputs.py" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/networking.py" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/preprocessing_utils.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.ipynb_checkpoints/Emotion Detector-checkpoint.ipynb" beforeDir="false" afterPath="$PROJECT_DIR$/.ipynb_checkpoints/Emotion Detector-checkpoint.ipynb" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Emotion Detector.ipynb" beforeDir="false" afterPath="$PROJECT_DIR$/Emotion Detector.ipynb" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/gradio.py" beforeDir="false" afterPath="$PROJECT_DIR$/gradio.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/index.html" beforeDir="false" afterPath="$PROJECT_DIR$/index.html" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/model.h5" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/model2.h5" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/templates/tmp_html.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/tmp_html.html" afterDir="false" />
|
||||
</list>
|
||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@ -83,28 +73,32 @@
|
||||
<counts>
|
||||
<entry key="project.closed" value="2" />
|
||||
<entry key="project.open.time.1" value="2" />
|
||||
<entry key="project.open.time.6" value="1" />
|
||||
<entry key="project.opened" value="3" />
|
||||
<entry key="project.open.time.6" value="2" />
|
||||
<entry key="project.opened" value="4" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.extensions.open">
|
||||
<counts>
|
||||
<entry key="py" value="1" />
|
||||
<entry key="ipynb" value="1" />
|
||||
<entry key="py" value="5" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.types.open">
|
||||
<counts>
|
||||
<entry key="Python" value="1" />
|
||||
<entry key="IPNB" value="1" />
|
||||
<entry key="Python" value="5" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.extensions.edit">
|
||||
<counts>
|
||||
<entry key="py" value="72" />
|
||||
<entry key="dummy" value="10" />
|
||||
<entry key="py" value="1346" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
<usages-collector id="statistics.file.types.edit">
|
||||
<counts>
|
||||
<entry key="Python" value="72" />
|
||||
<entry key="PLAIN_TEXT" value="10" />
|
||||
<entry key="Python" value="1346" />
|
||||
</counts>
|
||||
</usages-collector>
|
||||
</session>
|
||||
@ -114,7 +108,7 @@
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/templates/draw_a_digit.html">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="255">
|
||||
<state relative-caret-position="375">
|
||||
<caret line="15" column="9" selection-start-line="15" selection-start-column="9" selection-end-line="15" selection-end-column="9" />
|
||||
</state>
|
||||
</provider>
|
||||
@ -123,7 +117,7 @@
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/index.html">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="2618">
|
||||
<state relative-caret-position="3850">
|
||||
<caret line="154" selection-start-line="154" selection-end-line="154" />
|
||||
<folding>
|
||||
<element signature="n#style#0;n#nav#0;n#body#0;n#html#0;n#!!top" expanded="true" />
|
||||
@ -138,7 +132,7 @@
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/../khateebi/quickstart.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="170">
|
||||
<state relative-caret-position="250">
|
||||
<caret line="19" selection-start-line="19" selection-end-line="19" />
|
||||
<folding>
|
||||
<element signature="e#0#37#0" expanded="true" />
|
||||
@ -150,7 +144,7 @@
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/../khateebi/templates/index.html">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="629">
|
||||
<state relative-caret-position="925">
|
||||
<caret line="37" column="32" selection-start-line="37" selection-start-column="31" selection-end-line="37" selection-end-column="41" />
|
||||
</state>
|
||||
</provider>
|
||||
@ -159,7 +153,7 @@
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/../khateebi/settings.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="102">
|
||||
<state relative-caret-position="150">
|
||||
<caret line="6" column="38" selection-start-line="6" selection-start-column="38" selection-end-line="6" selection-end-column="38" />
|
||||
</state>
|
||||
</provider>
|
||||
@ -174,11 +168,11 @@
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="true">
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/gradio.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="427">
|
||||
<caret line="107" column="33" selection-start-line="107" selection-start-column="33" selection-end-line="107" selection-end-column="33" />
|
||||
<state relative-caret-position="641">
|
||||
<caret line="194" column="47" selection-start-line="194" selection-start-column="47" selection-end-line="194" selection-end-column="47" />
|
||||
<folding>
|
||||
<element signature="e#0#35#0" expanded="true" />
|
||||
</folding>
|
||||
@ -186,20 +180,31 @@
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/css/draw-a-digit.css">
|
||||
<file pinned="false" current-in-tab="true">
|
||||
<entry file="file://$PROJECT_DIR$/networking.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="102">
|
||||
<caret line="6" column="1" selection-start-line="6" selection-start-column="1" selection-end-line="6" selection-end-column="1" />
|
||||
<state relative-caret-position="650">
|
||||
<caret line="26" column="18" lean-forward="true" selection-start-line="26" selection-start-column="18" selection-end-line="26" selection-end-column="18" />
|
||||
<folding>
|
||||
<element signature="e#0#17#0" expanded="true" />
|
||||
<marker date="1550454348542" expanded="true" signature="785:897" ph="..." />
|
||||
<marker date="1550454348542" expanded="true" signature="785:898" ph="..." />
|
||||
<marker date="1550454348542" expanded="true" signature="926:927" ph="..." />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/css/index.css">
|
||||
<entry file="file://$PROJECT_DIR$/inputs.py">
|
||||
<provider selected="true" editor-type-id="text-editor" />
|
||||
</entry>
|
||||
</file>
|
||||
<file pinned="false" current-in-tab="false">
|
||||
<entry file="file://$PROJECT_DIR$/preprocessing_utils.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="476">
|
||||
<caret line="28" column="11" selection-start-line="28" selection-start-column="11" selection-end-line="28" selection-end-column="11" />
|
||||
<state relative-caret-position="75">
|
||||
<caret line="3" column="19" selection-start-line="3" selection-start-column="4" selection-end-line="3" selection-end-column="19" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
@ -215,9 +220,6 @@
|
||||
</component>
|
||||
<component name="FindInProjectRecents">
|
||||
<findStrings>
|
||||
<find>#888</find>
|
||||
<find>on the canv</find>
|
||||
<find>offset</find>
|
||||
<find>mouseX</find>
|
||||
<find>titl</find>
|
||||
<find>predict</find>
|
||||
@ -245,6 +247,9 @@
|
||||
<find>pip ins</find>
|
||||
<find>Developed</find>
|
||||
<find>Usage</find>
|
||||
<find>server</find>
|
||||
<find>zip</find>
|
||||
<find>resize_</find>
|
||||
</findStrings>
|
||||
<replaceStrings>
|
||||
<replace>400</replace>
|
||||
@ -277,7 +282,12 @@
|
||||
<option value="$PROJECT_DIR$/css/index.css" />
|
||||
<option value="$PROJECT_DIR$/index.html" />
|
||||
<option value="$PROJECT_DIR$/../khateebi/settings.py" />
|
||||
<option value="$PROJECT_DIR$/templates/server.py" />
|
||||
<option value="$PROJECT_DIR$/server.py" />
|
||||
<option value="$PROJECT_DIR$/preprocessing_utils.py" />
|
||||
<option value="$PROJECT_DIR$/inputs.py" />
|
||||
<option value="$PROJECT_DIR$/gradio.py" />
|
||||
<option value="$PROJECT_DIR$/networking.py" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
@ -288,8 +298,8 @@
|
||||
<sorting>DEFINITION_ORDER</sorting>
|
||||
</component>
|
||||
<component name="ProjectFrameBounds" extendedState="6">
|
||||
<option name="x" value="-4" />
|
||||
<option name="y" value="-4" />
|
||||
<option name="x" value="3353" />
|
||||
<option name="y" value="189" />
|
||||
<option name="width" value="1288" />
|
||||
<option name="height" value="548" />
|
||||
</component>
|
||||
@ -309,6 +319,11 @@
|
||||
<item name="gradio" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="gradio" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
<path>
|
||||
<item name="gradio" type="b2602c69:ProjectViewProjectNode" />
|
||||
<item name="gradio" type="462c0819:PsiDirectoryNode" />
|
||||
<item name="templates" type="462c0819:PsiDirectoryNode" />
|
||||
</path>
|
||||
</expand>
|
||||
<select />
|
||||
</subPane>
|
||||
@ -321,6 +336,11 @@
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||
<property name="settings.editor.selected.configurable" value="preferences.keymap" />
|
||||
</component>
|
||||
<component name="RecentsManager">
|
||||
<key name="MoveFile.RECENT_KEYS">
|
||||
<recent name="C:\Users\islam\Repos\gradio" />
|
||||
</key>
|
||||
</component>
|
||||
<component name="RunDashboard">
|
||||
<option name="ruleStates">
|
||||
<list>
|
||||
@ -347,9 +367,10 @@
|
||||
<servers />
|
||||
</component>
|
||||
<component name="ToolWindowManager">
|
||||
<frame x="-6" y="-6" width="1513" height="1013" extended-state="6" />
|
||||
<frame x="2552" y="-8" width="2576" height="1096" extended-state="6" />
|
||||
<editor active="true" />
|
||||
<layout>
|
||||
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.14556533" />
|
||||
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.14666137" />
|
||||
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
|
||||
<window_info id="Favorites" order="2" side_tool="true" />
|
||||
<window_info anchor="bottom" id="Message" order="0" />
|
||||
@ -404,16 +425,37 @@
|
||||
<provider selected="true" editor-type-id="text-editor" />
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/../gradiome/chat.py" />
|
||||
<entry file="file://$PROJECT_DIR$/css/index.css">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="476">
|
||||
<caret line="28" column="11" selection-start-line="28" selection-start-column="11" selection-end-line="28" selection-end-column="11" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/Usage.ipynb">
|
||||
<provider selected="true" editor-type-id="ipnb-editor">
|
||||
<state>
|
||||
<selected id="0" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/css/draw-a-digit.css">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="102">
|
||||
<caret line="6" column="1" selection-start-line="6" selection-start-column="1" selection-end-line="6" selection-end-column="1" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/templates/draw_a_digit.html">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="255">
|
||||
<state relative-caret-position="375">
|
||||
<caret line="15" column="9" selection-start-line="15" selection-start-column="9" selection-end-line="15" selection-end-column="9" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/index.html">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="2618">
|
||||
<state relative-caret-position="3850">
|
||||
<caret line="154" selection-start-line="154" selection-end-line="154" />
|
||||
<folding>
|
||||
<element signature="n#style#0;n#nav#0;n#body#0;n#html#0;n#!!top" expanded="true" />
|
||||
@ -426,7 +468,7 @@
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/../khateebi/quickstart.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="170">
|
||||
<state relative-caret-position="250">
|
||||
<caret line="19" selection-start-line="19" selection-end-line="19" />
|
||||
<folding>
|
||||
<element signature="e#0#37#0" expanded="true" />
|
||||
@ -434,9 +476,16 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/../khateebi/templates/index.html">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="925">
|
||||
<caret line="37" column="32" selection-start-line="37" selection-start-column="31" selection-end-line="37" selection-end-column="41" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/../khateebi/settings.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="102">
|
||||
<state relative-caret-position="150">
|
||||
<caret line="6" column="38" selection-start-line="6" selection-start-column="38" selection-end-line="6" selection-end-column="38" />
|
||||
</state>
|
||||
</provider>
|
||||
@ -448,36 +497,38 @@
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/css/draw-a-digit.css">
|
||||
<entry file="file://$PROJECT_DIR$/preprocessing_utils.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="102">
|
||||
<caret line="6" column="1" selection-start-line="6" selection-start-column="1" selection-end-line="6" selection-end-column="1" />
|
||||
<state relative-caret-position="75">
|
||||
<caret line="3" column="19" selection-start-line="3" selection-start-column="4" selection-end-line="3" selection-end-column="19" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/css/index.css">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="476">
|
||||
<caret line="28" column="11" selection-start-line="28" selection-start-column="11" selection-end-line="28" selection-end-column="11" />
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/../khateebi/templates/index.html">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="629">
|
||||
<caret line="37" column="32" selection-start-line="37" selection-start-column="31" selection-end-line="37" selection-end-column="41" />
|
||||
</state>
|
||||
</provider>
|
||||
<entry file="file://$PROJECT_DIR$/inputs.py">
|
||||
<provider selected="true" editor-type-id="text-editor" />
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/gradio.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="427">
|
||||
<caret line="107" column="33" selection-start-line="107" selection-start-column="33" selection-end-line="107" selection-end-column="33" />
|
||||
<state relative-caret-position="641">
|
||||
<caret line="194" column="47" selection-start-line="194" selection-start-column="47" selection-end-line="194" selection-end-column="47" />
|
||||
<folding>
|
||||
<element signature="e#0#35#0" expanded="true" />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
<entry file="file://$PROJECT_DIR$/networking.py">
|
||||
<provider selected="true" editor-type-id="text-editor">
|
||||
<state relative-caret-position="650">
|
||||
<caret line="26" column="18" lean-forward="true" selection-start-line="26" selection-start-column="18" selection-end-line="26" selection-end-column="18" />
|
||||
<folding>
|
||||
<element signature="e#0#17#0" expanded="true" />
|
||||
<marker date="1550454348542" expanded="true" signature="785:897" ph="..." />
|
||||
<marker date="1550454348542" expanded="true" signature="785:898" ph="..." />
|
||||
<marker date="1550454348542" expanded="true" signature="926:927" ph="..." />
|
||||
</folding>
|
||||
</state>
|
||||
</provider>
|
||||
</entry>
|
||||
</component>
|
||||
</project>
|
@ -1,5 +1,101 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"x_train shape: (60000, 28, 28, 1)\n",
|
||||
"60000 train samples\n",
|
||||
"10000 test samples\n",
|
||||
"Train on 60000 samples, validate on 10000 samples\n",
|
||||
"Epoch 1/12\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"'''Trains a simple convnet on the MNIST dataset.\n",
|
||||
"Gets to 99.25% test accuracy after 12 epochs\n",
|
||||
"(there is still a lot of margin for parameter tuning).\n",
|
||||
"16 seconds per epoch on a GRID K520 GPU.\n",
|
||||
"'''\n",
|
||||
"\n",
|
||||
"from __future__ import print_function\n",
|
||||
"import keras\n",
|
||||
"from keras.datasets import mnist\n",
|
||||
"from keras.models import Sequential\n",
|
||||
"from keras.layers import Dense, Dropout, Flatten\n",
|
||||
"from keras.layers import Conv2D, MaxPooling2D\n",
|
||||
"from keras import backend as K\n",
|
||||
"\n",
|
||||
"batch_size = 128\n",
|
||||
"num_classes = 10\n",
|
||||
"epochs = 12\n",
|
||||
"\n",
|
||||
"# input image dimensions\n",
|
||||
"img_rows, img_cols = 28, 28\n",
|
||||
"\n",
|
||||
"# the data, split between train and test sets\n",
|
||||
"(x_train, y_train), (x_test, y_test) = mnist.load_data()\n",
|
||||
"\n",
|
||||
"if K.image_data_format() == 'channels_first':\n",
|
||||
" x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols)\n",
|
||||
" x_test = x_test.reshape(x_test.shape[0], 1, img_rows, img_cols)\n",
|
||||
" input_shape = (1, img_rows, img_cols)\n",
|
||||
"else:\n",
|
||||
" x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)\n",
|
||||
" x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)\n",
|
||||
" input_shape = (img_rows, img_cols, 1)\n",
|
||||
"\n",
|
||||
"x_train = x_train.astype('float32')\n",
|
||||
"x_test = x_test.astype('float32')\n",
|
||||
"x_train /= 255\n",
|
||||
"x_test /= 255\n",
|
||||
"print('x_train shape:', x_train.shape)\n",
|
||||
"print(x_train.shape[0], 'train samples')\n",
|
||||
"print(x_test.shape[0], 'test samples')\n",
|
||||
"\n",
|
||||
"# convert class vectors to binary class matrices\n",
|
||||
"y_train = keras.utils.to_categorical(y_train, num_classes)\n",
|
||||
"y_test = keras.utils.to_categorical(y_test, num_classes)\n",
|
||||
"\n",
|
||||
"model = Sequential()\n",
|
||||
"model.add(Conv2D(32, kernel_size=(3, 3),\n",
|
||||
" activation='relu',\n",
|
||||
" input_shape=input_shape))\n",
|
||||
"model.add(Conv2D(64, (3, 3), activation='relu'))\n",
|
||||
"model.add(MaxPooling2D(pool_size=(2, 2)))\n",
|
||||
"model.add(Dropout(0.25))\n",
|
||||
"model.add(Flatten())\n",
|
||||
"model.add(Dense(128, activation='relu'))\n",
|
||||
"model.add(Dropout(0.5))\n",
|
||||
"model.add(Dense(num_classes, activation='softmax'))\n",
|
||||
"\n",
|
||||
"model.compile(loss=keras.losses.categorical_crossentropy,\n",
|
||||
" optimizer=keras.optimizers.Adadelta(),\n",
|
||||
" metrics=['accuracy'])\n",
|
||||
"\n",
|
||||
"model.fit(x_train, y_train,\n",
|
||||
" batch_size=batch_size,\n",
|
||||
" epochs=epochs,\n",
|
||||
" verbose=1,\n",
|
||||
" validation_data=(x_test, y_test))\n",
|
||||
"score = model.evaluate(x_test, y_test, verbose=0)\n",
|
||||
"print('Test loss:', score[0])\n",
|
||||
"print('Test accuracy:', score[1])\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
@ -15,23 +111,73 @@
|
||||
],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import tensorflow as tf\n",
|
||||
"import sklearn\n",
|
||||
"import gradio\n",
|
||||
"from keras.models import Sequential\n",
|
||||
"from keras.layers import Dense, Dropout, Activation, Flatten\n",
|
||||
"from keras.layers import Conv2D, MaxPooling2D, BatchNormalization\n",
|
||||
"from keras.losses import categorical_crossentropy\n",
|
||||
"from keras.optimizers import Adam\n",
|
||||
"from keras.regularizers import l2\n",
|
||||
"from keras.callbacks import ReduceLROnPlateau, TensorBoard, EarlyStopping, ModelCheckpoint\n",
|
||||
"from keras.models import load_model\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"%load_ext autoreload\n",
|
||||
"%autoreload 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model = load_model('model.h5') # found random emotion detector model on github ''(its not very accurate)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"http://localhost:6002/templates/tmp_html.html\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"C:\\Users\\islam\\Repos\\gradio\\gradio.py:194: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system (\"html.parser\"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.\n",
|
||||
"\n",
|
||||
"The code that caused this warning is on line 194 of the file C:\\Users\\islam\\Repos\\gradio\\gradio.py. To get rid of this warning, pass the additional argument 'features=\"html.parser\"' to the BeautifulSoup constructor.\n",
|
||||
"\n",
|
||||
" input_soup = BeautifulSoup(input_page.read())\n",
|
||||
"C:\\Users\\islam\\Repos\\gradio\\gradio.py:195: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system (\"html.parser\"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.\n",
|
||||
"\n",
|
||||
"The code that caused this warning is on line 195 of the file C:\\Users\\islam\\Repos\\gradio\\gradio.py. To get rid of this warning, pass the additional argument 'features=\"html.parser\"' to the BeautifulSoup constructor.\n",
|
||||
"\n",
|
||||
" output_soup = BeautifulSoup(output_page.read())\n",
|
||||
"C:\\Users\\islam\\Repos\\gradio\\gradio.py:199: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system (\"html.parser\"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.\n",
|
||||
"\n",
|
||||
"The code that caused this warning is on line 199 of the file C:\\Users\\islam\\Repos\\gradio\\gradio.py. To get rid of this warning, pass the additional argument 'features=\"html.parser\"' to the BeautifulSoup constructor.\n",
|
||||
"\n",
|
||||
" all_io_soup = BeautifulSoup(all_io_page.read())\n",
|
||||
"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.py\", line 226, in communicate\n",
|
||||
" processed_input = self.input_interface._pre_process(await websocket.recv())\n",
|
||||
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\site-packages\\websockets\\protocol.py\", line 434, in recv\n",
|
||||
" yield from self.ensure_open()\n",
|
||||
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\site-packages\\websockets\\protocol.py\", line 646, in ensure_open\n",
|
||||
" ) from self.transfer_data_exc\n",
|
||||
"websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1001 (going away), no reason\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"iface = gradio.Interface(input='webcam',output='class',model_obj=model, model_type='keras')\n",
|
||||
"iface.launch()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
@ -41,82 +187,126 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING:tensorflow:From C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\framework\\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
|
||||
"Instructions for updating:\n",
|
||||
"Colocations handled automatically by placer.\n",
|
||||
"WARNING:tensorflow:From C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:3445: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.\n",
|
||||
"Instructions for updating:\n",
|
||||
"Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.\n",
|
||||
"WARNING:tensorflow:From C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\ops\\math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n",
|
||||
"Instructions for updating:\n",
|
||||
"Use tf.cast instead.\n"
|
||||
"serving at port 7000\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"model = load_model('model.h5') # found random emotion detector model on github ''(its not very accurate)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py:191: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system (\"lxml\"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.\n",
|
||||
"\n",
|
||||
"The code that caused this warning is on line 191 of the file C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py. To get rid of this warning, pass the additional argument 'features=\"lxml\"' to the BeautifulSoup constructor.\n",
|
||||
"\n",
|
||||
" input_soup = BeautifulSoup(input_page.read())\n",
|
||||
"C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py:192: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system (\"lxml\"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.\n",
|
||||
"\n",
|
||||
"The code that caused this warning is on line 192 of the file C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py. To get rid of this warning, pass the additional argument 'features=\"lxml\"' to the BeautifulSoup constructor.\n",
|
||||
"\n",
|
||||
" output_soup = BeautifulSoup(output_page.read())\n",
|
||||
"C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py:196: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system (\"lxml\"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.\n",
|
||||
"\n",
|
||||
"The code that caused this warning is on line 196 of the file C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py. To get rid of this warning, pass the additional argument 'features=\"lxml\"' to the BeautifulSoup constructor.\n",
|
||||
"\n",
|
||||
" all_io_soup = BeautifulSoup(all_io_page.read())\n",
|
||||
"Error in connection handler\n",
|
||||
"Exception in thread Thread-6:\n",
|
||||
"Traceback (most recent call last):\n",
|
||||
" File \"C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\websockets\\server.py\", line 169, in handler\n",
|
||||
" yield from self.ws_handler(self, path)\n",
|
||||
" File \"C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py\", line 223, in communicate\n",
|
||||
" processed_input = self.input_interface._pre_process(await websocket.recv())\n",
|
||||
" File \"C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\websockets\\protocol.py\", line 434, in recv\n",
|
||||
" yield from self.ensure_open()\n",
|
||||
" File \"C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\websockets\\protocol.py\", line 646, in ensure_open\n",
|
||||
" ) from self.transfer_data_exc\n",
|
||||
"websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1001 (going away), no reason\n",
|
||||
"Error in connection handler\n",
|
||||
"Traceback (most recent call last):\n",
|
||||
" File \"C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\websockets\\server.py\", line 169, in handler\n",
|
||||
" yield from self.ws_handler(self, path)\n",
|
||||
" File \"C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py\", line 223, in communicate\n",
|
||||
" processed_input = self.input_interface._pre_process(await websocket.recv())\n",
|
||||
" File \"C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\websockets\\protocol.py\", line 434, in recv\n",
|
||||
" yield from self.ensure_open()\n",
|
||||
" File \"C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\websockets\\protocol.py\", line 646, in ensure_open\n",
|
||||
" ) from self.transfer_data_exc\n",
|
||||
"websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1001 (going away), no reason\n"
|
||||
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\threading.py\", line 916, in _bootstrap_inner\n",
|
||||
" self.run()\n",
|
||||
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\threading.py\", line 864, in run\n",
|
||||
" self._target(*self._args, **self._kwargs)\n",
|
||||
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\socketserver.py\", line 236, in serve_forever\n",
|
||||
" ready = selector.select(poll_interval)\n",
|
||||
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\selectors.py\", line 323, in select\n",
|
||||
" r, w, _ = self._select(self._readers, self._writers, [], timeout)\n",
|
||||
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\selectors.py\", line 314, in _select\n",
|
||||
" r, w, x = select.select(r, w, w, timeout)\n",
|
||||
"OSError: [WinError 10038] An operation was attempted on something that is not a socket\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"iface = gradio.Interface(input='sketchpad',output='class',model_obj=model, model_type='keras')\n",
|
||||
"iface.launch()"
|
||||
"import http.server\n",
|
||||
"import socketserver\n",
|
||||
"import os\n",
|
||||
"import threading\n",
|
||||
"\n",
|
||||
"TEMPLATE_DIRECTORY = 'templates'\n",
|
||||
"PORT = 7000\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"web_dir = os.path.realpath(TEMPLATE_DIRECTORY)\n",
|
||||
"os.chdir(web_dir)\n",
|
||||
"Handler = http.server.SimpleHTTPRequestHandler\n",
|
||||
"\n",
|
||||
"with socketserver.TCPServer((\"\", PORT), Handler) as httpd:\n",
|
||||
" print(\"serving at port\", PORT)\n",
|
||||
" t = threading.Thread(target=httpd.serve_forever)\n",
|
||||
" t.start()\n",
|
||||
"\n",
|
||||
"path_to_server = 'localhost:{}/'.format(PORT)\n",
|
||||
"os.chdir('..') # TODO(abidlabs): make this better\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"serving at port 7000\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import http.server\n",
|
||||
"import socketserver\n",
|
||||
"import os\n",
|
||||
"import threading\n",
|
||||
"\n",
|
||||
"TEMPLATE_DIRECTORY = 'templates'\n",
|
||||
"PORT = 7000\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"web_dir = os.path.realpath(TEMPLATE_DIRECTORY)\n",
|
||||
"os.chdir(web_dir)\n",
|
||||
"Handler = http.server.SimpleHTTPRequestHandler\n",
|
||||
"\n",
|
||||
"with socketserver.TCPServer((\"\", PORT), Handler) as httpd:\n",
|
||||
" print(\"serving at port\", PORT)\n",
|
||||
" httpd.serve_forever()\n",
|
||||
"# t = threading.Thread(target=httpd.serve_forever)\n",
|
||||
"# t.start()\n",
|
||||
"\n",
|
||||
"path_to_server = 'localhost:{}/'.format(PORT)\n",
|
||||
"os.chdir('..') # TODO(abidlabs): make this better "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import subprocess"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"<subprocess.Popen at 0x16a3f8aa390>"
|
||||
]
|
||||
},
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"subprocess.Popen(['python', '-m', 'http.server', '6001'])"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"display_name": "Python 3.6 (tensorflow)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
"name": "tensorflow"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
@ -128,7 +318,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.7.1"
|
||||
"version": "3.6.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
@ -1,5 +1,12 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
@ -15,23 +22,73 @@
|
||||
],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import tensorflow as tf\n",
|
||||
"import sklearn\n",
|
||||
"import gradio\n",
|
||||
"from keras.models import Sequential\n",
|
||||
"from keras.layers import Dense, Dropout, Activation, Flatten\n",
|
||||
"from keras.layers import Conv2D, MaxPooling2D, BatchNormalization\n",
|
||||
"from keras.losses import categorical_crossentropy\n",
|
||||
"from keras.optimizers import Adam\n",
|
||||
"from keras.regularizers import l2\n",
|
||||
"from keras.callbacks import ReduceLROnPlateau, TensorBoard, EarlyStopping, ModelCheckpoint\n",
|
||||
"from keras.models import load_model\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"%load_ext autoreload\n",
|
||||
"%autoreload 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model = load_model('model.h5') # found random emotion detector model on github ''(its not very accurate)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"http://localhost:6002/templates/tmp_html.html\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"C:\\Users\\islam\\Repos\\gradio\\gradio.py:194: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system (\"html.parser\"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.\n",
|
||||
"\n",
|
||||
"The code that caused this warning is on line 194 of the file C:\\Users\\islam\\Repos\\gradio\\gradio.py. To get rid of this warning, pass the additional argument 'features=\"html.parser\"' to the BeautifulSoup constructor.\n",
|
||||
"\n",
|
||||
" input_soup = BeautifulSoup(input_page.read())\n",
|
||||
"C:\\Users\\islam\\Repos\\gradio\\gradio.py:195: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system (\"html.parser\"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.\n",
|
||||
"\n",
|
||||
"The code that caused this warning is on line 195 of the file C:\\Users\\islam\\Repos\\gradio\\gradio.py. To get rid of this warning, pass the additional argument 'features=\"html.parser\"' to the BeautifulSoup constructor.\n",
|
||||
"\n",
|
||||
" output_soup = BeautifulSoup(output_page.read())\n",
|
||||
"C:\\Users\\islam\\Repos\\gradio\\gradio.py:199: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system (\"html.parser\"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.\n",
|
||||
"\n",
|
||||
"The code that caused this warning is on line 199 of the file C:\\Users\\islam\\Repos\\gradio\\gradio.py. To get rid of this warning, pass the additional argument 'features=\"html.parser\"' to the BeautifulSoup constructor.\n",
|
||||
"\n",
|
||||
" all_io_soup = BeautifulSoup(all_io_page.read())\n",
|
||||
"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.py\", line 226, in communicate\n",
|
||||
" processed_input = self.input_interface._pre_process(await websocket.recv())\n",
|
||||
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\site-packages\\websockets\\protocol.py\", line 434, in recv\n",
|
||||
" yield from self.ensure_open()\n",
|
||||
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\site-packages\\websockets\\protocol.py\", line 646, in ensure_open\n",
|
||||
" ) from self.transfer_data_exc\n",
|
||||
"websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1001 (going away), no reason\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"iface = gradio.Interface(input='webcam',output='class',model_obj=model, model_type='keras')\n",
|
||||
"iface.launch()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
@ -41,71 +98,126 @@
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"WARNING:tensorflow:From C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\framework\\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
|
||||
"Instructions for updating:\n",
|
||||
"Colocations handled automatically by placer.\n",
|
||||
"WARNING:tensorflow:From C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:3445: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version.\n",
|
||||
"Instructions for updating:\n",
|
||||
"Please use `rate` instead of `keep_prob`. Rate should be set to `rate = 1 - keep_prob`.\n",
|
||||
"WARNING:tensorflow:From C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\ops\\math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.\n",
|
||||
"Instructions for updating:\n",
|
||||
"Use tf.cast instead.\n"
|
||||
"serving at port 7000\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"model = load_model('model.h5') # found random emotion detector model on github ''(its not very accurate)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py:191: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system (\"lxml\"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.\n",
|
||||
"\n",
|
||||
"The code that caused this warning is on line 191 of the file C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py. To get rid of this warning, pass the additional argument 'features=\"lxml\"' to the BeautifulSoup constructor.\n",
|
||||
"\n",
|
||||
" input_soup = BeautifulSoup(input_page.read())\n",
|
||||
"C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py:192: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system (\"lxml\"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.\n",
|
||||
"\n",
|
||||
"The code that caused this warning is on line 192 of the file C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py. To get rid of this warning, pass the additional argument 'features=\"lxml\"' to the BeautifulSoup constructor.\n",
|
||||
"\n",
|
||||
" output_soup = BeautifulSoup(output_page.read())\n",
|
||||
"C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py:196: UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system (\"lxml\"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.\n",
|
||||
"\n",
|
||||
"The code that caused this warning is on line 196 of the file C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py. To get rid of this warning, pass the additional argument 'features=\"lxml\"' to the BeautifulSoup constructor.\n",
|
||||
"\n",
|
||||
" all_io_soup = BeautifulSoup(all_io_page.read())\n",
|
||||
"Error in connection handler\n",
|
||||
"Exception in thread Thread-6:\n",
|
||||
"Traceback (most recent call last):\n",
|
||||
" File \"C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\websockets\\server.py\", line 169, in handler\n",
|
||||
" yield from self.ws_handler(self, path)\n",
|
||||
" File \"C:\\Users\\ALI\\Desktop\\gradiome\\gradio.py\", line 223, in communicate\n",
|
||||
" processed_input = self.input_interface._pre_process(await websocket.recv())\n",
|
||||
" File \"C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\websockets\\protocol.py\", line 434, in recv\n",
|
||||
" yield from self.ensure_open()\n",
|
||||
" File \"C:\\Users\\ALI\\Anaconda3\\lib\\site-packages\\websockets\\protocol.py\", line 646, in ensure_open\n",
|
||||
" ) from self.transfer_data_exc\n",
|
||||
"websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1001 (going away), no reason\n"
|
||||
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\threading.py\", line 916, in _bootstrap_inner\n",
|
||||
" self.run()\n",
|
||||
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\threading.py\", line 864, in run\n",
|
||||
" self._target(*self._args, **self._kwargs)\n",
|
||||
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\socketserver.py\", line 236, in serve_forever\n",
|
||||
" ready = selector.select(poll_interval)\n",
|
||||
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\selectors.py\", line 323, in select\n",
|
||||
" r, w, _ = self._select(self._readers, self._writers, [], timeout)\n",
|
||||
" File \"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\selectors.py\", line 314, in _select\n",
|
||||
" r, w, x = select.select(r, w, w, timeout)\n",
|
||||
"OSError: [WinError 10038] An operation was attempted on something that is not a socket\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"iface = gradio.Interface(input='webcam',output='class',model_obj=model, model_type='keras')\n",
|
||||
"iface.launch()"
|
||||
"import http.server\n",
|
||||
"import socketserver\n",
|
||||
"import os\n",
|
||||
"import threading\n",
|
||||
"\n",
|
||||
"TEMPLATE_DIRECTORY = 'templates'\n",
|
||||
"PORT = 7000\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"web_dir = os.path.realpath(TEMPLATE_DIRECTORY)\n",
|
||||
"os.chdir(web_dir)\n",
|
||||
"Handler = http.server.SimpleHTTPRequestHandler\n",
|
||||
"\n",
|
||||
"with socketserver.TCPServer((\"\", PORT), Handler) as httpd:\n",
|
||||
" print(\"serving at port\", PORT)\n",
|
||||
" t = threading.Thread(target=httpd.serve_forever)\n",
|
||||
" t.start()\n",
|
||||
"\n",
|
||||
"path_to_server = 'localhost:{}/'.format(PORT)\n",
|
||||
"os.chdir('..') # TODO(abidlabs): make this better\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"serving at port 7000\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import http.server\n",
|
||||
"import socketserver\n",
|
||||
"import os\n",
|
||||
"import threading\n",
|
||||
"\n",
|
||||
"TEMPLATE_DIRECTORY = 'templates'\n",
|
||||
"PORT = 7000\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"web_dir = os.path.realpath(TEMPLATE_DIRECTORY)\n",
|
||||
"os.chdir(web_dir)\n",
|
||||
"Handler = http.server.SimpleHTTPRequestHandler\n",
|
||||
"\n",
|
||||
"with socketserver.TCPServer((\"\", PORT), Handler) as httpd:\n",
|
||||
" print(\"serving at port\", PORT)\n",
|
||||
" httpd.serve_forever()\n",
|
||||
"# t = threading.Thread(target=httpd.serve_forever)\n",
|
||||
"# t.start()\n",
|
||||
"\n",
|
||||
"path_to_server = 'localhost:{}/'.format(PORT)\n",
|
||||
"os.chdir('..') # TODO(abidlabs): make this better "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import subprocess"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"<subprocess.Popen at 0x16a3f8aa390>"
|
||||
]
|
||||
},
|
||||
"execution_count": 8,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"subprocess.Popen(['python', '-m', 'http.server', '6001'])"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"display_name": "Python 3.6 (tensorflow)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
"name": "tensorflow"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
@ -117,7 +229,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.7.1"
|
||||
"version": "3.6.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
121
Test Notebook.ipynb
Normal file
121
Test Notebook.ipynb
Normal file
@ -0,0 +1,121 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"The autoreload extension is already loaded. To reload it, use:\n",
|
||||
" %reload_ext autoreload\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"import sklearn\n",
|
||||
"import gradio\n",
|
||||
"from keras.models import load_model\n",
|
||||
"\n",
|
||||
"%load_ext autoreload\n",
|
||||
"%autoreload 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"C:\\Users\\islam\\Anaconda3\\envs\\tensorflow\\lib\\site-packages\\keras\\engine\\saving.py:327: UserWarning: Error in loading the saved optimizer state. As a result, your model is starting with a freshly initialized optimizer.\n",
|
||||
" warnings.warn('Error in loading the saved optimizer '\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"model = load_model('.models/mnist-cnn.h5')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"http://localhost:6002/templates/tmp_html.html\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ename": "OSError",
|
||||
"evalue": "[Errno 10048] error while attempting to bind on address ('127.0.0.1', 5680): only one usage of each socket address (protocol/network address/port) is normally permitted",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[1;31mOSError\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[1;32m~\\Anaconda3\\envs\\tensorflow\\lib\\asyncio\\base_events.py\u001b[0m in \u001b[0;36mcreate_server\u001b[1;34m(self, protocol_factory, host, port, family, flags, sock, backlog, ssl, reuse_address, reuse_port)\u001b[0m\n\u001b[0;32m 1050\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1051\u001b[1;33m \u001b[0msock\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbind\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msa\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1052\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mOSError\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0merr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[1;31mOSError\u001b[0m: [WinError 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted",
|
||||
"\nDuring handling of the above exception, another exception occurred:\n",
|
||||
"\u001b[1;31mOSError\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[1;32m<ipython-input-5-277844517c06>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0miface\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgradio\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mInterface\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'sketchpad'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0moutput\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'class'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mmodel_obj\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmodel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmodel_type\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'keras'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0miface\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlaunch\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
|
||||
"\u001b[1;32m~\\Repos\\gradio\\gradio.py\u001b[0m in \u001b[0;36mlaunch\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 244\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 245\u001b[0m \u001b[0mstart_server\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mwebsockets\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mserve\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcommunicate\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mLOCALHOST_IP\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mSOCKET_PORT\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 246\u001b[1;33m \u001b[0masyncio\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_event_loop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun_until_complete\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstart_server\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 247\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 248\u001b[0m \u001b[0masyncio\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_event_loop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrun_forever\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[1;32m~\\Anaconda3\\envs\\tensorflow\\lib\\site-packages\\nest_asyncio.py\u001b[0m in \u001b[0;36mrun_until_complete\u001b[1;34m(self, future)\u001b[0m\n\u001b[0;32m 57\u001b[0m \u001b[1;32mwhile\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdone\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 58\u001b[0m \u001b[0mrun_once\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 59\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 60\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 61\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_run_until_complete_orig\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfuture\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[1;32m~\\Anaconda3\\envs\\tensorflow\\lib\\asyncio\\tasks.py\u001b[0m in \u001b[0;36m_step\u001b[1;34m(***failed resolving arguments***)\u001b[0m\n\u001b[0;32m 178\u001b[0m \u001b[1;31m# We use the `send` method directly, because coroutines\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 179\u001b[0m \u001b[1;31m# don't have `__iter__` and `__next__` methods.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 180\u001b[1;33m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcoro\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 181\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 182\u001b[0m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcoro\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mthrow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mexc\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[1;32m~\\Anaconda3\\envs\\tensorflow\\lib\\asyncio\\tasks.py\u001b[0m in \u001b[0;36m_wrap_awaitable\u001b[1;34m(awaitable)\u001b[0m\n\u001b[0;32m 535\u001b[0m \u001b[0mthat\u001b[0m \u001b[0mwill\u001b[0m \u001b[0mlater\u001b[0m \u001b[0mbe\u001b[0m \u001b[0mwrapped\u001b[0m \u001b[1;32min\u001b[0m \u001b[0ma\u001b[0m \u001b[0mTask\u001b[0m \u001b[0mby\u001b[0m \u001b[0mensure_future\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 536\u001b[0m \"\"\"\n\u001b[1;32m--> 537\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;32myield\u001b[0m \u001b[1;32mfrom\u001b[0m \u001b[0mawaitable\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__await__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 538\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 539\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[1;32m~\\Anaconda3\\envs\\tensorflow\\lib\\site-packages\\websockets\\py35\\server.py\u001b[0m in \u001b[0;36m__await_impl__\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;31m# Duplicated with __iter__ because Python 3.7 requires an async function\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[1;31m# (as explained in __await__ below) which Python 3.4 doesn't support.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 13\u001b[1;33m \u001b[0mserver\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mawait\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_creating_server\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 14\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mws_server\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwrap\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mserver\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 15\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mws_server\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[1;32m~\\Anaconda3\\envs\\tensorflow\\lib\\asyncio\\base_events.py\u001b[0m in \u001b[0;36mcreate_server\u001b[1;34m(self, protocol_factory, host, port, family, flags, sock, backlog, ssl, reuse_address, reuse_port)\u001b[0m\n\u001b[0;32m 1053\u001b[0m raise OSError(err.errno, 'error while attempting '\n\u001b[0;32m 1054\u001b[0m \u001b[1;34m'to bind on address %r: %s'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1055\u001b[1;33m % (sa, err.strerror.lower()))\n\u001b[0m\u001b[0;32m 1056\u001b[0m \u001b[0mcompleted\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1057\u001b[0m \u001b[1;32mfinally\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[1;31mOSError\u001b[0m: [Errno 10048] error while attempting to bind on address ('127.0.0.1', 5680): only one usage of each socket address (protocol/network address/port) is normally permitted"
|
||||
]
|
||||
},
|
||||
{
|
||||
"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.py\", line 231, in communicate\n",
|
||||
" processed_output = self.output_interface._post_process(prediction)\n",
|
||||
" File \"C:\\Users\\islam\\Repos\\gradio\\gradio.py\", line 165, in _post_process\n",
|
||||
" return emotion_dict[prediction]\n",
|
||||
"KeyError: 7\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"iface = gradio.Interface(input='sketchpad',output='class',model_obj=model, model_type='keras')\n",
|
||||
"iface.launch()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3.6 (tensorflow)",
|
||||
"language": "python",
|
||||
"name": "tensorflow"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.6.7"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
100
gradio.py
100
gradio.py
@ -9,6 +9,8 @@ import numpy as np
|
||||
import os
|
||||
import webbrowser
|
||||
from bs4 import BeautifulSoup
|
||||
import networking
|
||||
import preprocessing_utils
|
||||
|
||||
nest_asyncio.apply()
|
||||
|
||||
@ -16,61 +18,6 @@ LOCALHOST_IP = '127.0.0.1'
|
||||
SOCKET_PORT = 5680
|
||||
|
||||
|
||||
|
||||
import requests, zipfile, io
|
||||
|
||||
def resize_and_crop(img, size, crop_type='top'):
|
||||
"""
|
||||
Resize and crop an image to fit the specified size.
|
||||
args:
|
||||
img_path: path for the image to resize.
|
||||
modified_path: path to store the modified image.
|
||||
size: `(width, height)` tuple.
|
||||
crop_type: can be 'top', 'middle' or 'bottom', depending on this
|
||||
value, the image will cropped getting the 'top/left', 'midle' or
|
||||
'bottom/rigth' of the image to fit the size.
|
||||
raises:
|
||||
Exception: if can not open the file in img_path of there is problems
|
||||
to save the image.
|
||||
ValueError: if an invalid `crop_type` is provided.
|
||||
"""
|
||||
# Get current and desired ratio for the images
|
||||
img_ratio = img.size[0] / float(img.size[1])
|
||||
ratio = size[0] / float(size[1])
|
||||
# The image is scaled/cropped vertically or horizontally depending on the ratio
|
||||
if ratio > img_ratio:
|
||||
img = img.resize((size[0], size[0] * img.size[1] / img.size[0]),
|
||||
Image.ANTIALIAS)
|
||||
# Crop in the top, middle or bottom
|
||||
if crop_type == 'top':
|
||||
box = (0, 0, img.size[0], size[1])
|
||||
elif crop_type == 'middle':
|
||||
box = (0, (img.size[1] - size[1]) / 2, img.size[0], (img.size[1] + size[1]) / 2)
|
||||
elif crop_type == 'bottom':
|
||||
box = (0, img.size[1] - size[1], img.size[0], img.size[1])
|
||||
else:
|
||||
raise ValueError('ERROR: invalid value for crop_type')
|
||||
img = img.crop(box)
|
||||
elif ratio < img_ratio:
|
||||
img = img.resize((size[1] * img.size[0] / img.size[1], size[1]),
|
||||
Image.ANTIALIAS)
|
||||
# Crop in the top, middle or bottom
|
||||
if crop_type == 'top':
|
||||
box = (0, 0, size[0], img.size[1])
|
||||
elif crop_type == 'middle':
|
||||
box = ((img.size[0] - size[0]) / 2, 0, (img.size[0] + size[0]) / 2, img.size[1])
|
||||
elif crop_type == 'bottom':
|
||||
box = (img.size[0] - size[0], 0, img.size[0], img.size[1])
|
||||
else:
|
||||
raise ValueError('ERROR: invalid value for crop_type')
|
||||
img = img.crop(box)
|
||||
else:
|
||||
img = img.resize((size[0], size[1]),
|
||||
Image.ANTIALIAS)
|
||||
# If the scale is the same, we do not need to crop
|
||||
return img
|
||||
|
||||
|
||||
class AbstractInput(ABC):
|
||||
"""
|
||||
An abstract class for defining the methods that all gradio inputs should have.
|
||||
@ -79,7 +26,7 @@ class AbstractInput(ABC):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
|
||||
|
||||
@abstractmethod
|
||||
def _get_template_path(self):
|
||||
"""
|
||||
@ -131,8 +78,8 @@ class Sketchpad(AbstractInput):
|
||||
image_encoded = content.split(',')[1]
|
||||
body = base64.decodebytes(image_encoded.encode('utf-8'))
|
||||
im = Image.open(BytesIO(base64.b64decode(image_encoded))).convert('L')
|
||||
im = resize_and_crop(im, (28, 28))
|
||||
array = np.array(im).flatten().reshape(1, -1)
|
||||
im = preprocessing_utils.resize_and_crop(im, (28, 28))
|
||||
array = np.array(im).flatten().reshape(1, 28, 28, 1)
|
||||
return array
|
||||
|
||||
|
||||
@ -148,10 +95,11 @@ class Webcam(AbstractInput):
|
||||
image_encoded = content.split(',')[1]
|
||||
body = base64.decodebytes(image_encoded.encode('utf-8'))
|
||||
im = Image.open(BytesIO(base64.b64decode(image_encoded))).convert('L')
|
||||
im = resize_and_crop(im, (48, 48))
|
||||
im = preprocessing_utils.resize_and_crop(im, (48, 48))
|
||||
array = np.array(im).flatten().reshape(1,48,48,1)
|
||||
return array
|
||||
|
||||
|
||||
class Class(AbstractOutput):
|
||||
|
||||
def _get_template_path(self):
|
||||
@ -160,8 +108,7 @@ class Class(AbstractOutput):
|
||||
def _post_process(self, prediction):
|
||||
"""
|
||||
"""
|
||||
emotion_dict = {0: "Angry", 1: "Disgust", 2: "Fear", 3: "Happy", 4: "Sad", 5: "Surprise", 6: "Neutral"}
|
||||
return emotion_dict[prediction]
|
||||
return prediction
|
||||
|
||||
registry = {
|
||||
'webcam':Webcam,
|
||||
@ -169,9 +116,11 @@ registry = {
|
||||
'class' :Class,
|
||||
}
|
||||
|
||||
|
||||
class Interface():
|
||||
"""
|
||||
"""
|
||||
build_template_path = 'templates/tmp_html.html'
|
||||
|
||||
def __init__(self, input, output, model_obj, model_type, **model_params):
|
||||
"""
|
||||
@ -190,29 +139,31 @@ class Interface():
|
||||
output_template_path = self.output_interface._get_template_path()
|
||||
input_page = open(input_template_path)
|
||||
output_page = open(output_template_path)
|
||||
input_soup = BeautifulSoup(input_page.read())
|
||||
output_soup = BeautifulSoup(output_page.read())
|
||||
input_soup = BeautifulSoup(input_page.read(), features="html.parser")
|
||||
output_soup = BeautifulSoup(output_page.read(), features="html.parser")
|
||||
|
||||
all_io_url = 'templates/all_io.html'
|
||||
all_io_page = open(all_io_url)
|
||||
all_io_soup = BeautifulSoup(all_io_page.read())
|
||||
all_io_soup = BeautifulSoup(all_io_page.read(), features="html.parser")
|
||||
input_tag = all_io_soup.find("div", {"id": "input"})
|
||||
output_tag = all_io_soup.find("div", {"id": "output"})
|
||||
|
||||
input_tag.replace_with(input_soup)
|
||||
output_tag.replace_with(output_soup)
|
||||
|
||||
f = open("templates/tmp_html.html", "w")
|
||||
f = open(self.build_template_path, "w")
|
||||
f.write(str(all_io_soup.prettify))
|
||||
return 'templates/tmp_html.html'
|
||||
return self.build_template_path
|
||||
|
||||
def predict(self, array):
|
||||
if self.model_type=='sklearn':
|
||||
return self.model_obj.predict(array)[0]
|
||||
elif self.model_type=='keras':
|
||||
return self.model_obj.predict(array)[0].argmax()
|
||||
elif self.model_type=='func':
|
||||
return self.model_obj(array)
|
||||
else:
|
||||
raise ValueError('model_type must be sklearn.')
|
||||
raise ValueError('model_type must be one of: "sklearn" or "keras" or "func".')
|
||||
|
||||
|
||||
async def communicate(self, websocket, path):
|
||||
@ -227,12 +178,23 @@ class Interface():
|
||||
processed_output = self.output_interface._post_process(prediction)
|
||||
await websocket.send(str(processed_output))
|
||||
|
||||
def launch(self):
|
||||
def launch(self, share_link=True):
|
||||
"""
|
||||
Standard method shared by interfaces that launches a websocket at a specified IP address.
|
||||
"""
|
||||
webbrowser.open('file://' + os.path.realpath(self._build_template()))
|
||||
path_to_server = networking.start_simple_server()
|
||||
path_to_template = self._build_template()
|
||||
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s' # TODO(abidlabs): remove
|
||||
|
||||
print(path_to_server + path_to_template)
|
||||
webbrowser.get(chrome_path).open(path_to_server + path_to_template) # TODO(abidlabs): fix this
|
||||
|
||||
start_server = websockets.serve(self.communicate, LOCALHOST_IP, SOCKET_PORT)
|
||||
|
||||
if share_link:
|
||||
ngrok_url = networking.setup_ngrok()
|
||||
print("Model accessiable for 8 hours at: {}".format(ngrok_url))
|
||||
|
||||
asyncio.get_event_loop().run_until_complete(start_server)
|
||||
try:
|
||||
asyncio.get_event_loop().run_forever()
|
||||
|
30
networking.py
Normal file
30
networking.py
Normal file
@ -0,0 +1,30 @@
|
||||
import subprocess
|
||||
import requests
|
||||
import zipfile
|
||||
import io
|
||||
import sys
|
||||
|
||||
INITIAL_PORT_VALUE = '6002'
|
||||
NGROK_ZIP_URLS = {
|
||||
"linux": "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip",
|
||||
"darwin": "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-darwin-amd64.zip",
|
||||
"win32": "https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-windows-amd64.zip",
|
||||
}
|
||||
|
||||
def start_simple_server():
|
||||
subprocess.Popen(['python', '-m', 'http.server', INITIAL_PORT_VALUE])
|
||||
return 'http://localhost:{}/'.format(INITIAL_PORT_VALUE)
|
||||
|
||||
def download_ngrok():
|
||||
try:
|
||||
zip_file_url = NGROK_ZIP_URLS[sys.platform]
|
||||
except KeyError:
|
||||
print("Sorry, we don't currently support your operating system, please leave us a note on GitHub, and we'll look into it!")
|
||||
return
|
||||
|
||||
r = requests.get(zip_file_url)
|
||||
z = zipfile.ZipFile(io.BytesIO(r.content))
|
||||
z.extractall("gradio/")
|
||||
|
||||
|
||||
def setup_ngrok(local_port):
|
53
preprocessing_utils.py
Normal file
53
preprocessing_utils.py
Normal file
@ -0,0 +1,53 @@
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def resize_and_crop(img, size, crop_type='top'):
|
||||
"""
|
||||
Resize and crop an image to fit the specified size.
|
||||
args:
|
||||
img_path: path for the image to resize.
|
||||
modified_path: path to store the modified image.
|
||||
size: `(width, height)` tuple.
|
||||
crop_type: can be 'top', 'middle' or 'bottom', depending on this
|
||||
value, the image will cropped getting the 'top/left', 'midle' or
|
||||
'bottom/rigth' of the image to fit the size.
|
||||
raises:
|
||||
Exception: if can not open the file in img_path of there is problems
|
||||
to save the image.
|
||||
ValueError: if an invalid `crop_type` is provided.
|
||||
"""
|
||||
# Get current and desired ratio for the images
|
||||
img_ratio = img.size[0] / float(img.size[1])
|
||||
ratio = size[0] / float(size[1])
|
||||
# The image is scaled/cropped vertically or horizontally depending on the ratio
|
||||
if ratio > img_ratio:
|
||||
img = img.resize((size[0], size[0] * img.size[1] / img.size[0]),
|
||||
Image.ANTIALIAS)
|
||||
# Crop in the top, middle or bottom
|
||||
if crop_type == 'top':
|
||||
box = (0, 0, img.size[0], size[1])
|
||||
elif crop_type == 'middle':
|
||||
box = (0, (img.size[1] - size[1]) / 2, img.size[0], (img.size[1] + size[1]) / 2)
|
||||
elif crop_type == 'bottom':
|
||||
box = (0, img.size[1] - size[1], img.size[0], img.size[1])
|
||||
else:
|
||||
raise ValueError('ERROR: invalid value for crop_type')
|
||||
img = img.crop(box)
|
||||
elif ratio < img_ratio:
|
||||
img = img.resize((size[1] * img.size[0] / img.size[1], size[1]),
|
||||
Image.ANTIALIAS)
|
||||
# Crop in the top, middle or bottom
|
||||
if crop_type == 'top':
|
||||
box = (0, 0, size[0], img.size[1])
|
||||
elif crop_type == 'middle':
|
||||
box = ((img.size[0] - size[0]) / 2, 0, (img.size[0] + size[0]) / 2, img.size[1])
|
||||
elif crop_type == 'bottom':
|
||||
box = (img.size[0] - size[0], 0, img.size[0], img.size[1])
|
||||
else:
|
||||
raise ValueError('ERROR: invalid value for crop_type')
|
||||
img = img.crop(box)
|
||||
else:
|
||||
img = img.resize((size[0], size[1]),
|
||||
Image.ANTIALIAS)
|
||||
# If the scale is the same, we do not need to crop
|
||||
return img
|
@ -1,8 +1,12 @@
|
||||
<bound method Tag.prettify of <!DOCTYPE html>
|
||||
<html><head><script src="../js/all-io.js"></script>
|
||||
<bound method Tag.prettify of
|
||||
<!DOCTYPE doctype html>
|
||||
|
||||
<script src="../js/all-io.js"></script>
|
||||
<script crossorigin="anonymous" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
|
||||
<script src="../js/bootstrap.min.js"></script>
|
||||
<script src="../js/bootstrap-notify.min.js"></script>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport"/>
|
||||
<meta content="" name="description"/>
|
||||
@ -12,7 +16,8 @@
|
||||
<link href="../css/bootstrap.min.css" rel="stylesheet"/>
|
||||
<link href="../css/draw-a-digit.css" rel="stylesheet"/>
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
|
||||
</head><body>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
|
||||
<a class="navbar-brand" href="#">Gradio</a>
|
||||
<button aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation" class="navbar-toggler" data-target="#navbarsExampleDefault" data-toggle="collapse" type="button">
|
||||
@ -25,7 +30,7 @@
|
||||
<!--<li class="nav-item">-->
|
||||
<!--<a class="nav-link" href="#">Help</a>-->
|
||||
<!--</li>-->
|
||||
<li class="nav-item ">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="http://www.siliconprep.com"><em>Gradio</em>, a tool by Silicon School</a>
|
||||
</li>
|
||||
</ul>
|
||||
@ -35,35 +40,27 @@
|
||||
<div class="row">
|
||||
<!-- INPUT
|
||||
====================================================================================================================================================== -->
|
||||
<html><body><div class="col-6">
|
||||
<h5>Webcam Input:</h5>
|
||||
<canvas height="400" id="canvas" style="background-color:black" width="400">
|
||||
<video id="video" playsinline="" style=" -moz-transform: scaleX(-1);
|
||||
-o-transform: scaleX(-1);
|
||||
-webkit-transform: scaleX(-1);
|
||||
transform: scaleX(-1);
|
||||
display: none;
|
||||
">
|
||||
</video>
|
||||
</canvas><br/>
|
||||
<div class="col-6">
|
||||
<h5>Sketch Pad Input: (Use your cursor to draw)</h5>
|
||||
<canvas height="400" id="canvas" width="400"></canvas><br/>
|
||||
<div aria-label="Basic example" class="btn-group" role="group">
|
||||
<button class="btn btn-primary" id="capture-button" type="button">Capture</button>
|
||||
<!-- <button type="button" class="btn btn-primary" id="submit-button">Recognize</button> -->
|
||||
<button class="btn btn-primary" id="submit-button" type="button">Recognize</button>
|
||||
<button class="btn btn-secondary" id="clear-button" type="button">Clear</button>
|
||||
</div>
|
||||
</div>
|
||||
<script src="../js/webcam-input.js"></script>
|
||||
</body></html>
|
||||
<script src="../js/sketchpad-input.js"></script>
|
||||
|
||||
<!-- OUTPUT
|
||||
====================================================================================================================================================== -->
|
||||
<html><body><div class="col-6">
|
||||
<div class="col-6">
|
||||
<h5>Text Output:</h5>
|
||||
<canvas height="400" id="predict_canvas" style="background-color:black" width="400"></canvas><br/>
|
||||
</div>
|
||||
<script src="../js/class-output.js"></script>
|
||||
</body></html>
|
||||
|
||||
</div>
|
||||
</main><!-- /.container -->
|
||||
</main></body></html>
|
||||
<!-- /.container -->
|
||||
<footer class="footer">
|
||||
<div class="container">
|
||||
<span class="text-muted">
|
||||
@ -82,5 +79,6 @@
|
||||
<!-- Bootstrap core JavaScript
|
||||
================================================== -->
|
||||
<!-- Placed at the end of the document so the pages load faster -->
|
||||
</body></html>
|
||||
|
||||
|
||||
>
|
Loading…
Reference in New Issue
Block a user