handle model closing

This commit is contained in:
Abubakar Abid 2019-02-17 20:34:57 -08:00
parent 835f17f2ba
commit 7b23941de8
5 changed files with 108 additions and 134 deletions

217
.idea/workspace.xml generated
View File

@ -4,10 +4,9 @@
<list default="true" id="fd73cd66-e80f-470e-a2ec-e220d3b6b864" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Test Notebook.ipynb" beforeDir="false" afterPath="$PROJECT_DIR$/Test Notebook.ipynb" afterDir="false" />
<change beforePath="$PROJECT_DIR$/css/draw-a-digit.css" beforeDir="false" afterPath="$PROJECT_DIR$/css/draw-a-digit.css" afterDir="false" />
<change beforePath="$PROJECT_DIR$/gradio.py" beforeDir="false" afterPath="$PROJECT_DIR$/gradio.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/js/all-io.js" beforeDir="false" afterPath="$PROJECT_DIR$/js/all-io.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/templates/all_io.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/all_io.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/templates/tmp_html.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/tmp_html.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/networking.py" beforeDir="false" afterPath="$PROJECT_DIR$/networking.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
@ -77,18 +76,18 @@
<counts>
<entry key="css" value="3" />
<entry key="gitignore" value="1" />
<entry key="html" value="1" />
<entry key="html" value="2" />
<entry key="ipynb" value="1" />
<entry key="js" value="2" />
<entry key="js" value="3" />
<entry key="py" value="6" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="CSS" value="3" />
<entry key="HTML" value="1" />
<entry key="HTML" value="2" />
<entry key="IPNB" value="1" />
<entry key="JavaScript" value="2" />
<entry key="JavaScript" value="3" />
<entry key="PLAIN_TEXT" value="1" />
<entry key="Python" value="6" />
</counts>
@ -99,58 +98,28 @@
<entry key="dummy" value="10" />
<entry key="gitignore" value="2" />
<entry key="html" value="112" />
<entry key="js" value="98" />
<entry key="py" value="2099" />
<entry key="js" value="104" />
<entry key="py" value="2672" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="CSS" value="11" />
<entry key="HTML" value="112" />
<entry key="JavaScript" value="98" />
<entry key="JavaScript" value="104" />
<entry key="PLAIN_TEXT" value="12" />
<entry key="Python" value="2099" />
<entry key="Python" value="2672" />
</counts>
</usages-collector>
</session>
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<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="50">
<caret line="2" column="23" selection-start-line="2" selection-start-column="23" selection-end-line="2" selection-end-column="23" />
</state>
</provider>
</entry>
</file>
<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="350">
<caret line="14" column="17" selection-start-line="14" selection-start-column="17" selection-end-line="14" selection-end-column="17" />
</state>
</provider>
</entry>
</file>
<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="400">
<caret line="16" column="7" lean-forward="true" selection-start-line="16" selection-start-column="7" selection-end-line="16" selection-end-column="7" />
<folding>
<element signature="e#0#14#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/templates/all_io.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="375">
<caret line="24" column="11" selection-start-line="24" selection-start-column="11" selection-end-line="24" selection-end-column="11" />
<state relative-caret-position="-1100">
<caret line="1" column="15" lean-forward="true" selection-start-line="1" selection-start-column="15" selection-end-line="1" selection-end-column="15" />
<folding>
<element signature="n#style#0;n#div#0;n#body#0;n#html#0;n#!!top" expanded="true" />
<element signature="n#style#0;n#span#0;n#strong#0;n#em#0;n#li#0;n#ul#1;n#div#0;n#nav#0;n#body#0;n#html#0;n#!!top" expanded="true" />
@ -160,19 +129,46 @@
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/js/all-io.js">
<entry file="file://$PROJECT_DIR$/gradio.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="75">
<caret line="3" column="13" lean-forward="true" selection-start-line="3" selection-start-column="13" selection-end-line="3" selection-end-column="13" />
<state relative-caret-position="441">
<caret line="91" column="116" selection-start-line="91" selection-start-column="52" selection-end-line="91" selection-end-column="116" />
<folding>
<element signature="e#0#14#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/networking.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="435">
<caret line="34" column="26" lean-forward="true" selection-start-line="34" selection-start-column="26" selection-end-line="34" selection-end-column="26" />
<folding>
<element signature="e#0#17#0" expanded="true" />
<marker date="1550464345323" expanded="true" signature="925:1028" ph="..." />
<marker date="1550464345323" expanded="true" signature="925:1029" ph="..." />
<marker date="1550464345323" expanded="true" signature="1058:1062" ph="..." />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/js/all-io.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="300">
<caret line="12" column="13" lean-forward="true" selection-start-line="12" selection-start-column="13" selection-end-line="12" selection-end-column="13" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/css/draw-a-digit.css">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="564">
<caret line="52" column="4" selection-start-line="52" selection-start-column="4" selection-end-line="52" selection-end-column="4" />
<state relative-caret-position="489">
<caret line="49" column="15" lean-forward="true" selection-start-line="49" selection-start-column="15" selection-end-line="49" selection-end-column="15" />
</state>
</provider>
</entry>
@ -195,22 +191,6 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/networking.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="450">
<caret line="18" column="29" selection-start-line="18" selection-start-column="29" selection-end-line="18" selection-end-column="29" />
<folding>
<element signature="e#0#17#0" expanded="true" />
<marker date="1550455679994" expanded="true" signature="856:959" ph="..." />
<marker date="1550455679994" expanded="true" signature="856:960" ph="..." />
<marker date="1550455679994" expanded="true" signature="988:989" ph="..." />
<marker date="1550455679994" expanded="true" signature="988:993" ph="..." />
</folding>
</state>
</provider>
</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">
@ -231,7 +211,6 @@
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>help</find>
<find>width</find>
<find>submit</find>
<find>clear</find>
@ -261,6 +240,7 @@
<find>base</find>
<find>ws</find>
<find>&lt;em</find>
<find>6002</find>
</findStrings>
<replaceStrings>
<replace>400</replace>
@ -296,14 +276,14 @@
<option value="$PROJECT_DIR$/templates/server.py" />
<option value="$PROJECT_DIR$/server.py" />
<option value="$PROJECT_DIR$/preprocessing_utils.py" />
<option value="$PROJECT_DIR$/networking.py" />
<option value="$PROJECT_DIR$/.gitignore" />
<option value="$PROJECT_DIR$/inputs.py" />
<option value="$PROJECT_DIR$/outputs.py" />
<option value="$PROJECT_DIR$/gradio.py" />
<option value="$PROJECT_DIR$/js/all-io.js" />
<option value="$PROJECT_DIR$/templates/all_io.html" />
<option value="$PROJECT_DIR$/css/draw-a-digit.css" />
<option value="$PROJECT_DIR$/js/all-io.js" />
<option value="$PROJECT_DIR$/gradio.py" />
<option value="$PROJECT_DIR$/networking.py" />
</list>
</option>
</component>
@ -335,21 +315,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="css" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="gradio" type="b2602c69:ProjectViewProjectNode" />
<item name="gradio" type="462c0819:PsiDirectoryNode" />
<item name="js" 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>
@ -509,27 +479,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/networking.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="450">
<caret line="18" column="29" selection-start-line="18" selection-start-column="29" selection-end-line="18" selection-end-column="29" />
<folding>
<element signature="e#0#17#0" expanded="true" />
<marker date="1550455679994" expanded="true" signature="856:959" ph="..." />
<marker date="1550455679994" expanded="true" signature="856:960" ph="..." />
<marker date="1550455679994" expanded="true" signature="988:989" ph="..." />
<marker date="1550455679994" expanded="true" signature="988:993" ph="..." />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../khateebi/settings.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="350">
<caret line="14" column="17" selection-start-line="14" selection-start-column="17" selection-end-line="14" selection-end-column="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/inputs.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="50">
@ -544,23 +493,6 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/gradio.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="400">
<caret line="16" column="7" lean-forward="true" selection-start-line="16" selection-start-column="7" selection-end-line="16" selection-end-column="7" />
<folding>
<element signature="e#0#14#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../khateebi/templates/index.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="50">
<caret line="2" column="23" selection-start-line="2" selection-start-column="23" selection-end-line="2" selection-end-column="23" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/webcam-input.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="300">
@ -575,10 +507,31 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../khateebi/templates/index.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="50">
<caret line="2" column="23" selection-start-line="2" selection-start-column="23" selection-end-line="2" selection-end-column="23" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../khateebi/settings.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="350">
<caret line="14" column="17" selection-start-line="14" selection-start-column="17" selection-end-line="14" selection-end-column="17" />
</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="489">
<caret line="49" column="15" lean-forward="true" selection-start-line="49" selection-start-column="15" selection-end-line="49" selection-end-column="15" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/templates/all_io.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="375">
<caret line="24" column="11" selection-start-line="24" selection-start-column="11" selection-end-line="24" selection-end-column="11" />
<state relative-caret-position="-1100">
<caret line="1" column="15" lean-forward="true" selection-start-line="1" selection-start-column="15" selection-end-line="1" selection-end-column="15" />
<folding>
<element signature="n#style#0;n#div#0;n#body#0;n#html#0;n#!!top" expanded="true" />
<element signature="n#style#0;n#span#0;n#strong#0;n#em#0;n#li#0;n#ul#1;n#div#0;n#nav#0;n#body#0;n#html#0;n#!!top" expanded="true" />
@ -586,17 +539,33 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/all-io.js">
<entry file="file://$PROJECT_DIR$/gradio.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="75">
<caret line="3" column="13" lean-forward="true" selection-start-line="3" selection-start-column="13" selection-end-line="3" selection-end-column="13" />
<state relative-caret-position="441">
<caret line="91" column="116" selection-start-line="91" selection-start-column="52" selection-end-line="91" selection-end-column="116" />
<folding>
<element signature="e#0#14#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/css/draw-a-digit.css">
<entry file="file://$PROJECT_DIR$/networking.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="564">
<caret line="52" column="4" selection-start-line="52" selection-start-column="4" selection-end-line="52" selection-end-column="4" />
<state relative-caret-position="435">
<caret line="34" column="26" lean-forward="true" selection-start-line="34" selection-start-column="26" selection-end-line="34" selection-end-column="26" />
<folding>
<element signature="e#0#17#0" expanded="true" />
<marker date="1550464345323" expanded="true" signature="925:1028" ph="..." />
<marker date="1550464345323" expanded="true" signature="925:1029" ph="..." />
<marker date="1550464345323" expanded="true" signature="1058:1062" ph="..." />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/js/all-io.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="300">
<caret line="12" column="13" lean-forward="true" selection-start-line="12" selection-start-column="13" selection-end-line="12" selection-end-column="13" />
</state>
</provider>
</entry>

View File

@ -52,8 +52,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Model available locally at: http://localhost:6002/templates/tmp_html.html\n",
"Model available publicly for 8 hours at: https://57d2bd20.ngrok.io/templates/tmp_html.html\n"
"Model available locally at: http://localhost:7860/templates/tmp_html.html\n",
"Model available publicly for 8 hours at: http://b8464aec.ngrok.io/templates/tmp_html.html\n"
]
}
],

View File

@ -10,7 +10,7 @@ import networking
nest_asyncio.apply()
LOCALHOST_IP = '127.0.0.1'
SOCKET_PORT = 5680
INITIAL_WEBSOCKET_PORT = 9200
class Interface():
@ -42,10 +42,10 @@ class Interface():
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(self.build_template_path, "w")
f.write(str(all_io_soup.prettify))
return self.build_template_path
@ -83,10 +83,14 @@ class Interface():
server_port = networking.start_simple_server()
path_to_server = 'http://localhost:{}/'.format(server_port)
path_to_template = self._build_template()
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s' # TODO(abidlabs): try otherwise general
webbrowser.get(chrome_path).open(path_to_server + path_to_template)
start_server = websockets.serve(self.communicate, LOCALHOST_IP, SOCKET_PORT)
webbrowser.open(path_to_server + path_to_template)
try:
start_server = websockets.serve(self.communicate, LOCALHOST_IP, INITIAL_WEBSOCKET_PORT)
except OSError:
print("Error: port 9200 is already taken. Please close the process running on 9200 "
"and try running gradio again.") # TODO(abidlabs): increment port number until free port is found
print("Model available locally at: {}".format(path_to_server + path_to_template))
if share_link:

View File

@ -1,5 +1,5 @@
try {
var ws = new WebSocket("ws://127.0.0.1:5680/")
var ws = new WebSocket("ws://127.0.0.1:9200/")
ws.onerror = function(evt) {
notifyError(evt)
};

View File

@ -5,7 +5,7 @@ import io
import sys
import os
INITIAL_PORT_VALUE = 6002
INITIAL_PORT_VALUE = 7860
LOCALHOST_PREFIX = 'localhost:'
NGROK_TUNNELS_URL = "http://localhost:4040/api/tunnels"
NGROK_ZIP_URLS = {
@ -15,6 +15,7 @@ NGROK_ZIP_URLS = {
}
def start_simple_server():
# TODO(abidlabs): increment port number until free port is found
subprocess.Popen(['python', '-m', 'http.server', str(INITIAL_PORT_VALUE)])
return INITIAL_PORT_VALUE