Merge pull request #308 from gradio-app/abidlabs/errors

Piping errors
This commit is contained in:
Dawood Khan 2021-10-21 16:50:53 -04:00 committed by GitHub
commit 65c4924f9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -512,7 +512,9 @@ class Interface:
print("PASSED")
continue
def launch(self, inline=None, inbrowser=None, share=False, debug=False, auth=None, auth_message=None, private_endpoint=None, prevent_thread_lock=False):
def launch(self, inline=None, inbrowser=None, share=False, debug=False,
auth=None, auth_message=None, private_endpoint=None,
prevent_thread_lock=False, show_error=True):
"""
Launches the webserver that serves the UI for the interface.
Parameters:
@ -526,6 +528,7 @@ class Interface:
app (flask.Flask): Flask app object
path_to_local_server (str): Locally accessible link
share_url (str): Publicly accessible link (if share=True)
show_error (bool): show prediction errors in console
"""
# Alert user if a more recent version of the library exists
utils.version_check()
@ -550,6 +553,7 @@ class Interface:
self.server_port = server_port
self.status = "RUNNING"
self.server = app
self.show_error = show_error
# Count number of launches
launch_counter()

View File

@ -175,7 +175,15 @@ def enable_sharing(path):
@login_check
def predict():
raw_input = request.json["data"]
prediction, durations = app.interface.process(raw_input)
# If in debug mode, capture any errors made and pipe to front end
if app.interface.show_error:
try:
prediction, durations = app.interface.process(raw_input)
except BaseException as error:
traceback.print_exc()
return jsonify({"error": traceback.format_exc()}), 500
else:
prediction, durations = app.interface.process(raw_input)
avg_durations = []
for i, duration in enumerate(durations):
app.interface.predict_durations[i][0] += duration