Spaces:
Sleeping
Sleeping
Update app.py
Browse filestrying gradio chatbot
app.py
CHANGED
|
@@ -92,16 +92,29 @@ agent = CodeAgent(
|
|
| 92 |
theme = gr.themes.Soft()
|
| 93 |
ui_component = GradioUI(agent) # if this returns a component
|
| 94 |
|
| 95 |
-
def get_text(question):
|
| 96 |
-
response = agent.run(question)
|
| 97 |
-
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
with gr.Blocks(theme=theme) as demo:
|
| 100 |
gr.Markdown("# Chat with BookBrain 📚🤯")
|
| 101 |
|
| 102 |
-
input_box = gr.Textbox(label="Enter your question for BookBrain")
|
| 103 |
-
output_box = gr.Textbox(label="Response")
|
|
|
|
|
|
|
| 104 |
submit_btn = gr.Button("Submit")
|
| 105 |
-
submit_btn.click(fn=get_text, inputs=input_box, outputs=output_box)
|
|
|
|
|
|
|
| 106 |
|
| 107 |
demo.launch()
|
|
|
|
| 92 |
theme = gr.themes.Soft()
|
| 93 |
ui_component = GradioUI(agent) # if this returns a component
|
| 94 |
|
| 95 |
+
# def get_text(question):
|
| 96 |
+
# response = agent.run(question)
|
| 97 |
+
# return response
|
| 98 |
+
|
| 99 |
+
def chat_fn(user_message, history):
|
| 100 |
+
# Initialize history if it's empty
|
| 101 |
+
history = history or []
|
| 102 |
+
# Call your agent to get a response
|
| 103 |
+
response = agent.run(user_message)
|
| 104 |
+
# Append the new exchange as a tuple (user_message, response)
|
| 105 |
+
history.append((user_message, response))
|
| 106 |
+
return history
|
| 107 |
|
| 108 |
with gr.Blocks(theme=theme) as demo:
|
| 109 |
gr.Markdown("# Chat with BookBrain 📚🤯")
|
| 110 |
|
| 111 |
+
#input_box = gr.Textbox(label="Enter your question for BookBrain")
|
| 112 |
+
#output_box = gr.Textbox(label="Response")
|
| 113 |
+
chatbot = gr.Chatbot(label="Chat")
|
| 114 |
+
user_input = gr.Textbox(label="Your question", placeholder="Ask your question here...", show_label=True)
|
| 115 |
submit_btn = gr.Button("Submit")
|
| 116 |
+
#submit_btn.click(fn=get_text, inputs=input_box, outputs=output_box)
|
| 117 |
+
user_input.submit(chat_fn, inputs=[user_input, chatbot], outputs=chatbot)
|
| 118 |
+
submit_btn.click(chat_fn, inputs=[user_input, chatbot], outputs=chatbot)
|
| 119 |
|
| 120 |
demo.launch()
|