mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-07 11:46:51 +08:00
moved the display URL from ngrok to gradio
This commit is contained in:
parent
ca3d080e07
commit
cde4623936
@ -9,9 +9,18 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"The autoreload extension is already loaded. To reload it, use:\n",
|
||||
" %reload_ext autoreload\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"%load_ext autoreload\n",
|
||||
"%autoreload 2\n",
|
||||
@ -23,7 +32,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -338,7 +347,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"execution_count": 21,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@ -353,7 +362,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"execution_count": 22,
|
||||
"metadata": {
|
||||
"scrolled": false
|
||||
},
|
||||
@ -363,8 +372,8 @@
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"NOTE: Gradio is in beta stage, please report all bugs to: a12d@stanford.edu\n",
|
||||
"Model is running locally at: http://localhost:7861/interface.html\n",
|
||||
"Model available publicly for 8 hours at: http://c5d7ed71.ngrok.io/interface.html\n"
|
||||
"Model is running locally at: http://localhost:7877/interface.html\n",
|
||||
"Model available publicly for 8 hours at: https://share.gradio.app/934834e8\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -374,14 +383,14 @@
|
||||
" <iframe\n",
|
||||
" width=\"1000\"\n",
|
||||
" height=\"500\"\n",
|
||||
" src=\"http://localhost:7861/interface.html\"\n",
|
||||
" src=\"http://localhost:7877/interface.html\"\n",
|
||||
" frameborder=\"0\"\n",
|
||||
" allowfullscreen\n",
|
||||
" ></iframe>\n",
|
||||
" "
|
||||
],
|
||||
"text/plain": [
|
||||
"<IPython.lib.display.IFrame at 0x13863bbea90>"
|
||||
"<IPython.lib.display.IFrame at 0x1d990494e10>"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
@ -13,10 +13,12 @@ from gradio import networking
|
||||
import tempfile
|
||||
import threading
|
||||
import traceback
|
||||
import urllib
|
||||
|
||||
nest_asyncio.apply()
|
||||
|
||||
LOCALHOST_IP = '127.0.0.1'
|
||||
SHARE_LINK_FORMAT = 'https://share.gradio.app/{}'
|
||||
INITIAL_WEBSOCKET_PORT = 9200
|
||||
TRY_NUM_PORTS = 100
|
||||
|
||||
@ -235,22 +237,28 @@ class Interface:
|
||||
if share:
|
||||
try:
|
||||
path_to_ngrok_server = networking.setup_ngrok(server_port, websocket_port, output_directory)
|
||||
path_to_ngrok_interface_page = path_to_ngrok_server + '/' + networking.TEMPLATE_TEMP
|
||||
if self.verbose:
|
||||
print(f"Model available publicly for 8 hours at: {path_to_ngrok_interface_page}")
|
||||
except RuntimeError:
|
||||
path_to_ngrok_server = None
|
||||
if self.verbose:
|
||||
print("Unable to create public link for interface, please check internet connection.")
|
||||
else:
|
||||
if self.verbose:
|
||||
print("To create a public link, set `share=True` in the argument to `launch()`")
|
||||
path_to_ngrok_server = None
|
||||
if is_colab: # for a colab notebook, create a public link even if share is False.
|
||||
if is_colab: # For a colab notebook, create a public link even if share is False.
|
||||
path_to_ngrok_server = networking.setup_ngrok(server_port, websocket_port, output_directory)
|
||||
path_to_ngrok_interface_page = path_to_ngrok_server + '/' + networking.TEMPLATE_TEMP
|
||||
print(f"Cannot display local interface on google colab, public link created at:"
|
||||
f"{path_to_ngrok_interface_page} and displayed below.")
|
||||
if self.verbose:
|
||||
print(f"Cannot display local interface on google colab, public link created.")
|
||||
else: # If it's not a colab notebook and share=False, print a message telling them about the share option.
|
||||
if self.verbose:
|
||||
print("To create a public link, set `share=True` in the argument to `launch()`")
|
||||
path_to_ngrok_server = None
|
||||
|
||||
if path_to_ngrok_server is not None:
|
||||
# path_to_ngrok_interface_page = path_to_ngrok_server + '/' + networking.TEMPLATE_TEMP
|
||||
url = urllib.parse.urlparse(path_to_ngrok_server)
|
||||
subdomain = url.hostname.split('.')[0]
|
||||
path_to_ngrok_interface_page = SHARE_LINK_FORMAT.format(subdomain)
|
||||
if self.verbose:
|
||||
print(f"Model available publicly for 8 hours at: {path_to_ngrok_interface_page}")
|
||||
|
||||
# Keep the server running in the background.
|
||||
asyncio.get_event_loop().run_until_complete(start_server)
|
||||
try:
|
||||
@ -272,6 +280,7 @@ class Interface:
|
||||
else:
|
||||
if inbrowser is None:
|
||||
inbrowser = False
|
||||
|
||||
if inbrowser and not is_colab:
|
||||
webbrowser.open(path_to_local_interface_page) # Open a browser tab with the interface.
|
||||
if inline:
|
||||
|
Loading…
Reference in New Issue
Block a user