mirror of
https://github.com/gradio-app/gradio.git
synced 2025-01-12 10:34:32 +08:00
url check for colab
This commit is contained in:
parent
be5741fc22
commit
6fc7bde0a5
@ -306,7 +306,8 @@ class Interface:
|
|||||||
is_colab
|
is_colab
|
||||||
): # Embed the remote interface page if on google colab;
|
): # Embed the remote interface page if on google colab;
|
||||||
# otherwise, embed the local page.
|
# otherwise, embed the local page.
|
||||||
time.sleep(1)
|
while not networking.url_ok(share_url):
|
||||||
|
time.sleep(1)
|
||||||
display(IFrame(share_url, width=1000, height=500))
|
display(IFrame(share_url, width=1000, height=500))
|
||||||
else:
|
else:
|
||||||
display(IFrame(path_to_local_server, width=1000, height=500))
|
display(IFrame(path_to_local_server, width=1000, height=500))
|
||||||
|
@ -13,6 +13,7 @@ import json
|
|||||||
from gradio.tunneling import create_tunnel
|
from gradio.tunneling import create_tunnel
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
import requests
|
||||||
|
|
||||||
INITIAL_PORT_VALUE = (
|
INITIAL_PORT_VALUE = (
|
||||||
7860
|
7860
|
||||||
@ -242,3 +243,11 @@ def setup_tunnel(local_server_port):
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise RuntimeError(str(e))
|
raise RuntimeError(str(e))
|
||||||
|
|
||||||
|
|
||||||
|
def url_ok(url):
|
||||||
|
try:
|
||||||
|
r = requests.head(url)
|
||||||
|
return r.status_code == 200
|
||||||
|
except ConnectionError:
|
||||||
|
return False
|
Loading…
Reference in New Issue
Block a user