mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-09 02:00:44 +08:00
fix threading, launching
This commit is contained in:
parent
bd28056fed
commit
ad8512f98d
@ -1,3 +1,2 @@
|
||||
recursive-include gradio/templates *
|
||||
recursive-include gradio/static *
|
||||
include gradio/launches.json
|
||||
recursive-include gradio/static *
|
@ -7,7 +7,6 @@ gradio/embeddings.py
|
||||
gradio/inputs.py
|
||||
gradio/interface.py
|
||||
gradio/interpretation.py
|
||||
gradio/launches.json
|
||||
gradio/networking.py
|
||||
gradio/notebook.py
|
||||
gradio/outputs.py
|
||||
|
@ -3,6 +3,7 @@ This is the core file in the `gradio` package, and defines the Interface class,
|
||||
interface using the input and output types.
|
||||
"""
|
||||
|
||||
import gradio
|
||||
from gradio.inputs import InputComponent
|
||||
from gradio.outputs import OutputComponent
|
||||
from gradio import networking, strings, utils
|
||||
@ -26,7 +27,7 @@ analytics.write_key = "uxIFddIEuuUcFLf9VgH2teTEtPlWdkNy"
|
||||
analytics_url = 'https://api.gradio.app/'
|
||||
ip_address = networking.get_local_ip_address()
|
||||
|
||||
JSON_PATH = pkg_resources.resource_filename("gradio", "launches.json")
|
||||
JSON_PATH = os.path.join(os.path.dirname(gradio.__file__), "launches.json")
|
||||
|
||||
class Interface:
|
||||
"""
|
||||
@ -405,16 +406,6 @@ class Interface:
|
||||
else:
|
||||
print("Colab notebook detected. To show errors in colab notebook, set debug=True in launch()")
|
||||
|
||||
if not os.path.exists(JSON_PATH):
|
||||
with open(JSON_PATH, "w+") as j:
|
||||
launches = {"launches": 0}
|
||||
j.write(json.dumps(launches))
|
||||
else:
|
||||
with open(JSON_PATH) as j:
|
||||
launches = json.load(j)
|
||||
|
||||
if launches["launches"] in [25, 50]:
|
||||
print(strings.en["BETA_INVITE"])
|
||||
|
||||
self.share = share
|
||||
if share:
|
||||
@ -451,6 +442,8 @@ class Interface:
|
||||
if inbrowser is None:
|
||||
inbrowser = False
|
||||
|
||||
launch_counter()
|
||||
|
||||
if inbrowser and not is_colab:
|
||||
webbrowser.open(path_to_local_server) # Open a browser tab
|
||||
# with the interface.
|
||||
@ -492,13 +485,31 @@ class Interface:
|
||||
is_in_interactive_mode = bool(getattr(sys, 'ps1', sys.flags.interactive))
|
||||
if not is_in_interactive_mode:
|
||||
self.run_until_interrupted(thread, path_to_local_server)
|
||||
|
||||
launches["launches"] += 1
|
||||
with open(JSON_PATH, "w") as j:
|
||||
j.write(json.dumps(launches))
|
||||
|
||||
|
||||
return app, path_to_local_server, share_url
|
||||
|
||||
def launch_counter():
|
||||
try:
|
||||
if not os.path.exists(JSON_PATH):
|
||||
print("creating")
|
||||
launches = {"launches": 1}
|
||||
with open(JSON_PATH, "w+") as j:
|
||||
json.dump(launches, j)
|
||||
else:
|
||||
print("loading")
|
||||
with open(JSON_PATH) as j:
|
||||
launches = json.load(j)
|
||||
launches["launches"] += 1
|
||||
print(launches["launches"])
|
||||
if launches["launches"] in [25, 50]:
|
||||
print(strings.en["BETA_INVITE"])
|
||||
with open(JSON_PATH, "w") as j:
|
||||
j.write(json.dumps(launches))
|
||||
except:
|
||||
import sys
|
||||
print(sys.exc_info()[0])
|
||||
print("Not tracking launches.")
|
||||
|
||||
|
||||
def reset_all():
|
||||
for io in Interface.get_instances():
|
||||
|
@ -268,13 +268,12 @@ def start_server(interface, server_name, server_port=None):
|
||||
log.setLevel(logging.ERROR)
|
||||
if interface.save_to is not None:
|
||||
interface.save_to["port"] = port
|
||||
# thread = threading.Thread(target=app.run,
|
||||
# kwargs={"port": port, "host": server_name},
|
||||
# daemon=True)
|
||||
# thread.start()
|
||||
app.run(port=port, host=server_name)
|
||||
thread = threading.Thread(target=app.run,
|
||||
kwargs={"port": port, "host": server_name},
|
||||
daemon=True)
|
||||
thread.start()
|
||||
|
||||
return port, app, None
|
||||
return port, app, thread
|
||||
|
||||
def close_server(process):
|
||||
process.terminate()
|
||||
|
Loading…
Reference in New Issue
Block a user