mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-15 02:11:15 +08:00
error handling backend
This commit is contained in:
parent
9b968d3fb5
commit
67c7ae761e
@ -503,6 +503,7 @@ class Interface:
|
||||
auth = [auth]
|
||||
self.auth = auth
|
||||
self.auth_message = auth_message
|
||||
self.debug = debug or int(os.getenv('GRADIO_DEBUG', 0))==1
|
||||
|
||||
# Request key for encryption
|
||||
if self.encrypt:
|
||||
@ -584,7 +585,7 @@ class Interface:
|
||||
show_tip(self)
|
||||
|
||||
# Run server perpetually under certain circumstances
|
||||
if debug or int(os.getenv('GRADIO_DEBUG', 0))==1:
|
||||
if self.debug:
|
||||
while True:
|
||||
sys.stdout.flush()
|
||||
time.sleep(0.1)
|
||||
|
@ -26,6 +26,7 @@ from gradio import encryptor
|
||||
from gradio import queue
|
||||
from functools import wraps
|
||||
import io
|
||||
import traceback
|
||||
|
||||
INITIAL_PORT_VALUE = int(os.getenv(
|
||||
'GRADIO_SERVER_PORT', "7860")) # The http server will try to open on port 7860. If not available, 7861, 7862, etc.
|
||||
@ -177,7 +178,16 @@ 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.debug:
|
||||
try:
|
||||
prediction, durations = app.interface.process(raw_input)
|
||||
except BaseException as error:
|
||||
traceback.print_exc()
|
||||
return jsonify({"error": traceback.format_exc()})
|
||||
else:
|
||||
prediction, durations = app.interface.process(raw_input)
|
||||
# Get running average of prediction times
|
||||
avg_durations = []
|
||||
for i, duration in enumerate(durations):
|
||||
app.interface.predict_durations[i][0] += duration
|
||||
|
Loading…
Reference in New Issue
Block a user