mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-31 12:20:26 +08:00
tested code, ironed out some bugs
This commit is contained in:
parent
211c06b64d
commit
2682405787
@ -2,15 +2,20 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"The autoreload extension is already loaded. To reload it, use:\n",
|
||||
" %reload_ext autoreload\n"
|
||||
"ename": "SyntaxError",
|
||||
"evalue": "invalid syntax (networking.py, line 200)",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"Traceback \u001b[1;36m(most recent call last)\u001b[0m:\n",
|
||||
" File \u001b[0;32m\"C:\\Users\\islam\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py\"\u001b[0m, line \u001b[0;32m2961\u001b[0m, in \u001b[0;35mrun_code\u001b[0m\n exec(code_obj, self.user_global_ns, self.user_ns)\n",
|
||||
" File \u001b[0;32m\"<ipython-input-1-ab911fe0150a>\"\u001b[0m, line \u001b[0;32m4\u001b[0m, in \u001b[0;35m<module>\u001b[0m\n import gradio\n",
|
||||
" File \u001b[0;32m\"C:\\Users\\islam\\Repos\\gradio\\gradio\\__init__.py\"\u001b[0m, line \u001b[0;32m1\u001b[0m, in \u001b[0;35m<module>\u001b[0m\n from gradio.interface import Interface # This makes it possible to import `Interface` as `gradio.Interface`.\n",
|
||||
"\u001b[1;36m File \u001b[1;32m\"C:\\Users\\islam\\Repos\\gradio\\gradio\\interface.py\"\u001b[1;36m, line \u001b[1;32m12\u001b[1;36m, in \u001b[1;35m<module>\u001b[1;36m\u001b[0m\n\u001b[1;33m from gradio import networking\u001b[0m\n",
|
||||
"\u001b[1;36m File \u001b[1;32m\"C:\\Users\\islam\\Repos\\gradio\\gradio\\networking.py\"\u001b[1;36m, line \u001b[1;32m200\u001b[0m\n\u001b[1;33m except AccessDenied, NoSuchProcess:\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@ -28,7 +33,10 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def test(x):\n",
|
||||
" return x.upper()"
|
||||
" return x.upper()\n",
|
||||
"\n",
|
||||
"def test2(x):\n",
|
||||
" return x.lower()"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -37,17 +45,9 @@
|
||||
"metadata": {
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Model type not explicitly identified, inferred to be: python function\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"iface = gradio.Interface(input=\"textbox\", output=\"textbox\", model=test)"
|
||||
"iface = gradio.Interface(inputs=\"textbox\", outputs=\"textbox\", model=test, model_type='function')"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -60,37 +60,27 @@
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"NOTE: Gradio is in beta stage, please report all bugs to: a12d@stanford.edu\n",
|
||||
"Model available locally at: http://localhost:7861/interface.html\n",
|
||||
"Model available publicly for 8 hours at: http://3dc1c1d4.ngrok.io/interface.html\n"
|
||||
"Model available locally at: http://localhost:7860/interface.html\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:47] \"GET /interface.html HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:47] \"GET /css/bootstrap.min.css HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:47] \"GET /css/draw-a-digit.css HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:48] \"GET /js/all-io.js HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:48] \"GET /js/bootstrap.min.js HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:48] \"GET /js/bootstrap-notify.min.js HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:48] \"GET /js/textbox-input.js HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:48] \"GET /js/textbox-output.js HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:50] \"GET /interface.html HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:51] \"GET /js/all-io.js HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:51] \"GET /css/bootstrap.min.css HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:51] \"GET /css/draw-a-digit.css HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:51] \"GET /js/bootstrap.min.js HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:51] \"GET /js/bootstrap-notify.min.js HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:52] \"GET /js/textbox-output.js HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:52] \"GET /js/textbox-input.js HTTP/1.1\" 200 -\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:52] code 404, message File not found\n",
|
||||
"127.0.0.1 - - [24/Feb/2019 23:32:52] \"GET /favicon.ico HTTP/1.1\" 404 -\n"
|
||||
"ename": "NoSuchProcess",
|
||||
"evalue": "psutil.NoSuchProcess process no longer exists (pid=2744)",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[1;31mNoSuchProcess\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[1;32m<ipython-input-5-8be24579e72c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0miface\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlaunch\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mshare\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[0m",
|
||||
"\u001b[1;32m~\\Repos\\gradio\\gradio\\interface.py\u001b[0m in \u001b[0;36mlaunch\u001b[1;34m(self, share)\u001b[0m\n\u001b[0;32m 136\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 137\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mshare\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 138\u001b[1;33m \u001b[0msite_ngrok_url\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnetworking\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msetup_ngrok\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mserver_port\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mwebsocket_port\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moutput_directory\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 139\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mverbose\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 140\u001b[0m print(\"Model available publicly for 8 hours at: {}\".format(\n",
|
||||
"\u001b[1;32m~\\Repos\\gradio\\gradio\\networking.py\u001b[0m in \u001b[0;36msetup_ngrok\u001b[1;34m(server_port, websocket_port, output_directory)\u001b[0m\n\u001b[0;32m 185\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 186\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0msetup_ngrok\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mserver_port\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mwebsocket_port\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0moutput_directory\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 187\u001b[1;33m \u001b[0mkill_processes\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m4040\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m4041\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#TODO(abidlabs): better way to do this\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 188\u001b[0m \u001b[0msite_ngrok_url\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcreate_ngrok_tunnel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mserver_port\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mNGROK_TUNNELS_API_URL\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 189\u001b[0m \u001b[0msocket_ngrok_url\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcreate_ngrok_tunnel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mwebsocket_port\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mNGROK_TUNNELS_API_URL2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[1;32m~\\Repos\\gradio\\gradio\\networking.py\u001b[0m in \u001b[0;36mkill_processes\u001b[1;34m(process_ids)\u001b[0m\n\u001b[0;32m 197\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mconns\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mproc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconnections\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkind\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'inet'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 198\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mconns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mladdr\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mport\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mprocess_ids\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 199\u001b[1;33m \u001b[0mproc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msend_signal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mSIGTERM\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# or SIGKILL\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 200\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mAccessDenied\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 201\u001b[0m \u001b[1;32mpass\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\psutil\\__init__.py\u001b[0m in \u001b[0;36mwrapper\u001b[1;34m(self, *args, **kwargs)\u001b[0m\n\u001b[0;32m 282\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mwrapper\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 283\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mis_running\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--> 284\u001b[1;33m \u001b[1;32mraise\u001b[0m \u001b[0mNoSuchProcess\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpid\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_name\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 285\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mfun\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 286\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mwrapper\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[1;31mNoSuchProcess\u001b[0m: psutil.NoSuchProcess process no longer exists (pid=2744)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"iface.launch(share_link=True)"
|
||||
"iface.launch(share=True)"
|
||||
]
|
||||
}
|
||||
],
|
||||
@ -99,18 +89,6 @@
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"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.7.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
@ -50,6 +50,7 @@ class Interface:
|
||||
elif not(model_type.lower() in self.VALID_MODEL_TYPES):
|
||||
ValueError('model_type must be one of: {}'.format(self.VALID_MODEL_TYPES))
|
||||
self.model_type = model_type
|
||||
self.verbose = verbose
|
||||
|
||||
@staticmethod
|
||||
def _infer_model_type(model):
|
||||
|
@ -9,7 +9,7 @@ import io
|
||||
import sys
|
||||
import os
|
||||
import socket
|
||||
from psutil import process_iter, AccessDenied
|
||||
from psutil import process_iter, AccessDenied, NoSuchProcess
|
||||
from signal import SIGTERM # or SIGKILL
|
||||
import threading
|
||||
from http.server import HTTPServer as BaseHTTPServer, SimpleHTTPRequestHandler
|
||||
@ -78,6 +78,7 @@ def copy_files(src_dir, dest_dir):
|
||||
shutil.copy(full_file_name, dest_dir)
|
||||
|
||||
|
||||
#TODO(abidlabs): Handle the http vs. https issue that sometimes happens (a ws cannot be loaded from an https page)
|
||||
def set_socket_url_in_js(temp_dir, socket_url):
|
||||
with open(os.path.join(temp_dir, BASE_JS_FILE)) as fin:
|
||||
lines = fin.readlines()
|
||||
@ -184,6 +185,7 @@ def create_ngrok_tunnel(local_port, api_url):
|
||||
|
||||
|
||||
def setup_ngrok(server_port, websocket_port, output_directory):
|
||||
kill_processes([4040, 4041]) #TODO(abidlabs): better way to do this
|
||||
site_ngrok_url = create_ngrok_tunnel(server_port, NGROK_TUNNELS_API_URL)
|
||||
socket_ngrok_url = create_ngrok_tunnel(websocket_port, NGROK_TUNNELS_API_URL2)
|
||||
set_socket_url_in_js(output_directory, socket_ngrok_url)
|
||||
@ -196,7 +198,7 @@ def kill_processes(process_ids):
|
||||
for conns in proc.connections(kind='inet'):
|
||||
if conns.laddr.port in process_ids:
|
||||
proc.send_signal(SIGTERM) # or SIGKILL
|
||||
except AccessDenied:
|
||||
except (AccessDenied, NoSuchProcess):
|
||||
pass
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user