Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -22,29 +22,24 @@ def user(user_message, history: list):
|
|
22 |
|
23 |
|
24 |
def bot(history: list, user_message):
|
25 |
-
|
26 |
-
full_response = "" # Store the complete response
|
27 |
|
28 |
-
def streamer(subword):
|
29 |
-
nonlocal full_response
|
30 |
-
full_response += subword
|
31 |
-
history[-1]['content'] = full_response
|
32 |
yield history
|
33 |
return ov_genai.StreamingStatus.RUNNING
|
34 |
|
35 |
-
|
36 |
-
# Initialize the bot message in history
|
37 |
history.append({"role": "assistant", "content": ""})
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
# yield history
|
47 |
-
|
48 |
|
49 |
with gr.Blocks() as demo:
|
50 |
chatbot = gr.Chatbot(type="messages")
|
|
|
22 |
|
23 |
|
24 |
def bot(history: list, user_message):
|
25 |
+
full_response = ""
|
|
|
26 |
|
27 |
+
def streamer(subword):
|
28 |
+
nonlocal full_response
|
29 |
+
full_response += subword
|
30 |
+
history[-1]['content'] = full_response
|
31 |
yield history
|
32 |
return ov_genai.StreamingStatus.RUNNING
|
33 |
|
|
|
|
|
34 |
history.append({"role": "assistant", "content": ""})
|
35 |
|
36 |
+
try:
|
37 |
+
for updated_history in pipe.generate(user_message, streamer=streamer, max_new_tokens=100):
|
38 |
+
yield updated_history
|
39 |
+
except Exception as e:
|
40 |
+
print(f"Error during OpenVINO generation: {e}") # Log the error!
|
41 |
+
history[-1]['content'] = "An error occurred while generating the response."
|
42 |
+
yield history
|
|
|
|
|
43 |
|
44 |
with gr.Blocks() as demo:
|
45 |
chatbot = gr.Chatbot(type="messages")
|