Spaces:
Sleeping
Sleeping
ogegadavis254
commited on
Commit
•
91d497a
1
Parent(s):
4d0c1d8
Update app.py
Browse files
app.py
CHANGED
@@ -58,8 +58,7 @@ def get_streamed_response(message, history):
|
|
58 |
|
59 |
# Check for the completion signal
|
60 |
if decoded_line == "data: [DONE]":
|
61 |
-
|
62 |
-
break
|
63 |
|
64 |
try:
|
65 |
# Decode and strip any SSE format specific prefix ("data: ")
|
@@ -68,7 +67,6 @@ def get_streamed_response(message, history):
|
|
68 |
chunk_data = json.loads(decoded_line)
|
69 |
content = chunk_data['choices'][0]['delta']['content']
|
70 |
entire_assistant_response += content # Aggregate content
|
71 |
-
yield entire_assistant_response
|
72 |
|
73 |
except json.JSONDecodeError:
|
74 |
print(f"Invalid JSON received: {decoded_line}")
|
@@ -80,13 +78,17 @@ def get_streamed_response(message, history):
|
|
80 |
print(entire_assistant_response)
|
81 |
all_message.append({"role": "assistant", "content": entire_assistant_response})
|
82 |
|
|
|
|
|
|
|
|
|
83 |
# Create a Gradio interface with customizations
|
84 |
chat_interface = gr.Interface(
|
85 |
fn=get_streamed_response,
|
|
|
|
|
86 |
title="Raxder Official AI",
|
87 |
description="Welcome to Dave, your friendly AI Therapist! Ask me anything or just have a chat. 😊",
|
88 |
-
inputs=[gr.Textbox(label="You", lines=5, placeholder="Type your message here...")],
|
89 |
-
outputs=[gr.Textbox(label="Dave", lines=5, placeholder="Dave's response will appear here...", readonly=True)],
|
90 |
theme="huggingface",
|
91 |
layout="vertical",
|
92 |
allow_flagging=False,
|
|
|
58 |
|
59 |
# Check for the completion signal
|
60 |
if decoded_line == "data: [DONE]":
|
61 |
+
return entire_assistant_response # Return the entire response at the end
|
|
|
62 |
|
63 |
try:
|
64 |
# Decode and strip any SSE format specific prefix ("data: ")
|
|
|
67 |
chunk_data = json.loads(decoded_line)
|
68 |
content = chunk_data['choices'][0]['delta']['content']
|
69 |
entire_assistant_response += content # Aggregate content
|
|
|
70 |
|
71 |
except json.JSONDecodeError:
|
72 |
print(f"Invalid JSON received: {decoded_line}")
|
|
|
78 |
print(entire_assistant_response)
|
79 |
all_message.append({"role": "assistant", "content": entire_assistant_response})
|
80 |
|
81 |
+
# Function to update the output textbox dynamically
|
82 |
+
def update_output(message):
|
83 |
+
return message
|
84 |
+
|
85 |
# Create a Gradio interface with customizations
|
86 |
chat_interface = gr.Interface(
|
87 |
fn=get_streamed_response,
|
88 |
+
inputs=[gr.Textbox(label="You", lines=5, placeholder="Type your message here...")],
|
89 |
+
outputs=update_output,
|
90 |
title="Raxder Official AI",
|
91 |
description="Welcome to Dave, your friendly AI Therapist! Ask me anything or just have a chat. 😊",
|
|
|
|
|
92 |
theme="huggingface",
|
93 |
layout="vertical",
|
94 |
allow_flagging=False,
|