Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,13 +23,12 @@ def chatbot(messages):
|
|
23 |
)
|
24 |
|
25 |
response = chat_completion.choices[0].message.content
|
26 |
-
messages.append(
|
27 |
-
messages.append({"role": "assistant", "content": response}) # Appending bot response
|
28 |
return messages
|
29 |
except Exception as e:
|
30 |
# Capture the specific error message for debugging
|
31 |
print(f"Error Details: {str(e)}") # Print error details in the console (logs)
|
32 |
-
messages.append(
|
33 |
return messages
|
34 |
|
35 |
# Function to reset the chat
|
@@ -47,10 +46,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
47 |
"""
|
48 |
)
|
49 |
|
50 |
-
with gr.Row():
|
51 |
chatbot_ui = gr.Chatbot(label="Chat Interface", height=400)
|
52 |
-
|
53 |
-
with gr.Row():
|
54 |
user_input = gr.Textbox(
|
55 |
label="Type Your Message",
|
56 |
placeholder="Ask me something...",
|
@@ -60,7 +59,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
60 |
send_button = gr.Button("Send", variant="primary")
|
61 |
clear_button = gr.Button("Clear Chat")
|
62 |
|
63 |
-
with gr.Row():
|
64 |
gr.Examples(
|
65 |
examples=["Hello!", "Tell me a joke.", "What's the weather like?"],
|
66 |
inputs=user_input,
|
@@ -72,4 +71,3 @@ with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
|
72 |
|
73 |
# Launch the Gradio app
|
74 |
iface.launch()
|
75 |
-
|
|
|
23 |
)
|
24 |
|
25 |
response = chat_completion.choices[0].message.content
|
26 |
+
messages.append((user_input, response)) # Append user input and bot response as a tuple
|
|
|
27 |
return messages
|
28 |
except Exception as e:
|
29 |
# Capture the specific error message for debugging
|
30 |
print(f"Error Details: {str(e)}") # Print error details in the console (logs)
|
31 |
+
messages.append((None, f"An error occurred: {str(e)}")) # Show the error in chat as a tuple
|
32 |
return messages
|
33 |
|
34 |
# Function to reset the chat
|
|
|
46 |
"""
|
47 |
)
|
48 |
|
49 |
+
with gr.Row():
|
50 |
chatbot_ui = gr.Chatbot(label="Chat Interface", height=400)
|
51 |
+
|
52 |
+
with gr.Row():
|
53 |
user_input = gr.Textbox(
|
54 |
label="Type Your Message",
|
55 |
placeholder="Ask me something...",
|
|
|
59 |
send_button = gr.Button("Send", variant="primary")
|
60 |
clear_button = gr.Button("Clear Chat")
|
61 |
|
62 |
+
with gr.Row():
|
63 |
gr.Examples(
|
64 |
examples=["Hello!", "Tell me a joke.", "What's the weather like?"],
|
65 |
inputs=user_input,
|
|
|
71 |
|
72 |
# Launch the Gradio app
|
73 |
iface.launch()
|
|