url check for colab

This commit is contained in:
aliabd 2020-07-02 12:27:00 -07:00
parent be5741fc22
commit 6fc7bde0a5
2 changed files with 11 additions and 1 deletions

View File

@ -306,6 +306,7 @@ class Interface:
is_colab
): # Embed the remote interface page if on google colab;
# otherwise, embed the local page.
while not networking.url_ok(share_url):
time.sleep(1)
display(IFrame(share_url, width=1000, height=500))
else:

View File

@ -13,6 +13,7 @@ import json
from gradio.tunneling import create_tunnel
import urllib.request
from shutil import copyfile
import requests
INITIAL_PORT_VALUE = (
7860
@ -242,3 +243,11 @@ def setup_tunnel(local_server_port):
except Exception as e:
raise RuntimeError(str(e))
def url_ok(url):
try:
r = requests.head(url)
return r.status_code == 200
except ConnectionError:
return False