Update app.py
Browse files
app.py
CHANGED
@@ -2,24 +2,26 @@ import gradio as gr
|
|
2 |
|
3 |
# Define a function to respond to user input
|
4 |
def respond(message, history):
|
5 |
-
#
|
6 |
response = "You said: " + message
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
return history
|
9 |
|
10 |
# Create the Gradio interface
|
11 |
with gr.Blocks() as demo:
|
12 |
gr.Markdown("# Chatbot Interface")
|
13 |
-
|
|
|
|
|
14 |
user_input = gr.Textbox(label="Your Message", placeholder="Type something...")
|
15 |
submit_btn = gr.Button("Send")
|
16 |
|
17 |
# Define the behavior of the submit button
|
18 |
-
submit_btn.click(
|
19 |
-
fn=respond,
|
20 |
-
inputs=[user_input, chatbot_interface],
|
21 |
-
outputs=chatbot_interface
|
22 |
-
)
|
23 |
|
24 |
# Launch the Gradio application
|
25 |
demo.launch()
|
@@ -27,7 +29,6 @@ demo.launch()
|
|
27 |
|
28 |
|
29 |
|
30 |
-
|
31 |
'''
|
32 |
|
33 |
import gradio as gr
|
|
|
2 |
|
3 |
# Define a function to respond to user input
|
4 |
def respond(message, history):
|
5 |
+
# Create a response based on the user's message
|
6 |
response = "You said: " + message
|
7 |
+
|
8 |
+
# Append the message and response to history
|
9 |
+
history.append({"role": "user", "content": message})
|
10 |
+
history.append({"role": "assistant", "content": response})
|
11 |
+
|
12 |
return history
|
13 |
|
14 |
# Create the Gradio interface
|
15 |
with gr.Blocks() as demo:
|
16 |
gr.Markdown("# Chatbot Interface")
|
17 |
+
|
18 |
+
# Initialize chatbot with the new message type
|
19 |
+
chatbot_interface = gr.Chatbot(type='messages') # Specify type='messages'
|
20 |
user_input = gr.Textbox(label="Your Message", placeholder="Type something...")
|
21 |
submit_btn = gr.Button("Send")
|
22 |
|
23 |
# Define the behavior of the submit button
|
24 |
+
submit_btn.click(fn=respond, inputs=[user_input, chatbot_interface], outputs=chatbot_interface)
|
|
|
|
|
|
|
|
|
25 |
|
26 |
# Launch the Gradio application
|
27 |
demo.launch()
|
|
|
29 |
|
30 |
|
31 |
|
|
|
32 |
'''
|
33 |
|
34 |
import gradio as gr
|