Spaces:
Runtime error
Runtime error
handling larger input prompts
Browse files
app.py
CHANGED
|
@@ -39,15 +39,27 @@ def predict(message, chatbot):
|
|
| 39 |
if decoded_line.startswith('data:'):
|
| 40 |
json_line = decoded_line[5:] # Exclude the first 5 characters ('data:')
|
| 41 |
else:
|
| 42 |
-
|
| 43 |
continue
|
| 44 |
|
| 45 |
# Load as JSON
|
| 46 |
try:
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
except json.JSONDecodeError:
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
| 51 |
continue
|
| 52 |
|
| 53 |
gr.ChatInterface(predict, title=title, description=description, css=css).queue(concurrency_count=75).launch()
|
|
|
|
| 39 |
if decoded_line.startswith('data:'):
|
| 40 |
json_line = decoded_line[5:] # Exclude the first 5 characters ('data:')
|
| 41 |
else:
|
| 42 |
+
gr.Warning(f"This line does not start with 'data:': {decoded_line}")
|
| 43 |
continue
|
| 44 |
|
| 45 |
# Load as JSON
|
| 46 |
try:
|
| 47 |
+
json_obj = json.loads(json_line)
|
| 48 |
+
if 'token' in json_obj:
|
| 49 |
+
partial_message = partial_message + json_obj['token']['text']
|
| 50 |
+
yield partial_message
|
| 51 |
+
elif 'error' in json_obj:
|
| 52 |
+
yield json_obj['error'] + '. Please refresh and try again with an appropriate smaller input prompt.'
|
| 53 |
+
else:
|
| 54 |
+
gr.Warning(f"The key 'token' does not exist in this JSON object: {json_obj}")
|
| 55 |
+
|
| 56 |
+
#partial_message = partial_message + json_obj['token']['text']
|
| 57 |
+
#yield partial_message
|
| 58 |
except json.JSONDecodeError:
|
| 59 |
+
gr.Warning(f"This line is not valid JSON: {json_line}")
|
| 60 |
+
continue
|
| 61 |
+
except KeyError as e:
|
| 62 |
+
gr.Warning(f"KeyError: {e} occurred for JSON object: {json_obj}")
|
| 63 |
continue
|
| 64 |
|
| 65 |
gr.ChatInterface(predict, title=title, description=description, css=css).queue(concurrency_count=75).launch()
|