mirror of
https://github.com/gradio-app/gradio.git
synced 2025-02-17 11:29:58 +08:00
Merge branch 'master' of https://github.com/gradio-app/gradio
This commit is contained in:
commit
0f00d062aa
@ -20,11 +20,7 @@ import copy
|
||||
|
||||
analytics.write_key = "uxIFddIEuuUcFLf9VgH2teTEtPlWdkNy"
|
||||
analytics_url = 'https://api.gradio.app/'
|
||||
try:
|
||||
ip_address = requests.get('https://api.ipify.org').text
|
||||
except requests.ConnectionError:
|
||||
ip_address = "No internet connection"
|
||||
|
||||
ip_address = networking.get_local_ip_address()
|
||||
|
||||
class Interface:
|
||||
"""
|
||||
@ -61,6 +57,7 @@ class Interface:
|
||||
title (str): a title for the interface; if provided, appears above the input and output components.
|
||||
description (str): a description for the interface; if provided, appears above the input and output components.
|
||||
thumbnail (str): path to image or src to use as display picture for models listed in gradio.app/hub
|
||||
server_name (str): to make app accessible on local network set to "0.0.0.0".
|
||||
allow_screenshot (bool): if False, users will not see a button to take a screenshot of the interface.
|
||||
allow_flagging (bool): if False, users will not see a button to flag an input and output.
|
||||
flagging_dir (str): what to name the dir where flagged data is stored.
|
||||
@ -304,7 +301,7 @@ class Interface:
|
||||
except (KeyboardInterrupt, OSError):
|
||||
print("Keyboard interruption in main thread... closing server.")
|
||||
thread.keep_running = False
|
||||
networking.url_ok(path_to_local_server)
|
||||
networking.url_ok(path_to_local_server) # Hit the server one more time to close it
|
||||
|
||||
def test_launch(self):
|
||||
for predict_fn in self.predict:
|
||||
@ -339,7 +336,7 @@ class Interface:
|
||||
networking.set_meta_tags(self.title, self.description, self.thumbnail)
|
||||
|
||||
server_port, app, thread = networking.start_server(
|
||||
self, self.server_port)
|
||||
self, self.server_name, self.server_port)
|
||||
path_to_local_server = "http://{}:{}/".format(self.server_name, server_port)
|
||||
self.server_port = server_port
|
||||
self.status = "RUNNING"
|
||||
|
@ -55,6 +55,14 @@ def set_config(config):
|
||||
app.app_globals["config"] = config
|
||||
|
||||
|
||||
def get_local_ip_address():
|
||||
try:
|
||||
ip_address = requests.get('https://api.ipify.org').text
|
||||
except requests.ConnectionError:
|
||||
ip_address = "No internet connection"
|
||||
return ip_address
|
||||
|
||||
|
||||
def get_first_available_port(initial, final):
|
||||
"""
|
||||
Gets the first open port in a specified range of port numbers
|
||||
@ -163,7 +171,7 @@ def interpret():
|
||||
def file(path):
|
||||
return send_file(os.path.join(app.cwd, path))
|
||||
|
||||
def start_server(interface, server_port=None):
|
||||
def start_server(interface, server_name, server_port=None):
|
||||
if server_port is None:
|
||||
server_port = INITIAL_PORT_VALUE
|
||||
port = get_first_available_port(
|
||||
@ -173,9 +181,9 @@ def start_server(interface, server_port=None):
|
||||
app.cwd = os.getcwd()
|
||||
log = logging.getLogger('werkzeug')
|
||||
log.setLevel(logging.ERROR)
|
||||
process = threading.Thread(target=app.run, kwargs={"port": port})
|
||||
process.start()
|
||||
return port, app, process
|
||||
thread = threading.Thread(target=app.run, kwargs={"port": port, "host": server_name}, daemon=True)
|
||||
thread.start()
|
||||
return port, app, thread
|
||||
|
||||
|
||||
def close_server(process):
|
||||
|
Loading…
Reference in New Issue
Block a user