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,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))

View File

@ -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