Spaces:
Runtime error
Runtime error
camille-vanhoffelen
commited on
Commit
•
295b0d4
1
Parent(s):
9fe387f
Better error handling in gradio
Browse files
app.py
CHANGED
@@ -52,27 +52,48 @@ class Client:
|
|
52 |
if not self.llms:
|
53 |
self.llms = create_llms()
|
54 |
|
55 |
-
messages = display_message(
|
56 |
-
role="user", message=user_input, messages=messages, save_media=True
|
57 |
-
)
|
58 |
self.last_user_input = user_input
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
return "", messages
|
60 |
|
61 |
def bot(self, messages):
|
62 |
if not self.is_init:
|
63 |
return {}, messages
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
|
78 |
css = ".json {height: 527px; overflow: scroll;} .json-holder {height: 527px; overflow: scroll;}"
|
@@ -161,7 +182,7 @@ with gr.Blocks(css=css) as demo:
|
|
161 |
"Draw me a sheep",
|
162 |
"Write a poem about sheep, then read it to me",
|
163 |
"Transcribe the audio file found at /audios/499e.flac. Then tell me how similar the transcription is to the following sentence: Sheep are nice.",
|
164 |
-
"
|
165 |
],
|
166 |
inputs=txt,
|
167 |
)
|
|
|
52 |
if not self.llms:
|
53 |
self.llms = create_llms()
|
54 |
|
|
|
|
|
|
|
55 |
self.last_user_input = user_input
|
56 |
+
try:
|
57 |
+
messages = display_message(
|
58 |
+
role="user", message=user_input, messages=messages, save_media=True
|
59 |
+
)
|
60 |
+
except Exception as e:
|
61 |
+
logger.exception("")
|
62 |
+
error_message = f"Sorry, encountered error: {e}. Please try again. Check logs if problem persists."
|
63 |
+
messages = display_message(
|
64 |
+
role="assistant",
|
65 |
+
message=error_message,
|
66 |
+
messages=messages,
|
67 |
+
save_media=False,
|
68 |
+
)
|
69 |
return "", messages
|
70 |
|
71 |
def bot(self, messages):
|
72 |
if not self.is_init:
|
73 |
return {}, messages
|
74 |
+
try:
|
75 |
+
user_input = self.last_user_input
|
76 |
+
response, task_summaries = compute(
|
77 |
+
user_input=user_input,
|
78 |
+
history=self.llm_history,
|
79 |
+
llms=self.llms,
|
80 |
+
)
|
81 |
+
messages = display_message(
|
82 |
+
role="assistant", message=response, messages=messages, save_media=False
|
83 |
+
)
|
84 |
+
self.llm_history.add(role="user", content=user_input)
|
85 |
+
self.llm_history.add(role="assistant", content="")
|
86 |
+
return task_summaries, messages
|
87 |
+
except Exception as e:
|
88 |
+
logger.exception("")
|
89 |
+
error_message = f"Sorry, encountered error: {e}. Please try again. Check logs if problem persists."
|
90 |
+
messages = display_message(
|
91 |
+
role="assistant",
|
92 |
+
message=error_message,
|
93 |
+
messages=messages,
|
94 |
+
save_media=False,
|
95 |
+
)
|
96 |
+
return [], messages
|
97 |
|
98 |
|
99 |
css = ".json {height: 527px; overflow: scroll;} .json-holder {height: 527px; overflow: scroll;}"
|
|
|
182 |
"Draw me a sheep",
|
183 |
"Write a poem about sheep, then read it to me",
|
184 |
"Transcribe the audio file found at /audios/499e.flac. Then tell me how similar the transcription is to the following sentence: Sheep are nice.",
|
185 |
+
"Tell me a joke about a sheep, then illustrate it by generating an image",
|
186 |
],
|
187 |
inputs=txt,
|
188 |
)
|