Update app.py
Browse files
app.py
CHANGED
|
@@ -240,8 +240,6 @@ def diabetes_bot(query, pdf_file=None):
|
|
| 240 |
return answer + usage_message
|
| 241 |
|
| 242 |
# Gradio interface
|
| 243 |
-
import gradio as gr
|
| 244 |
-
|
| 245 |
def chat_wrapper(query, pdf, history):
|
| 246 |
# Initialize history if empty
|
| 247 |
if history is None:
|
|
@@ -251,9 +249,10 @@ def chat_wrapper(query, pdf, history):
|
|
| 251 |
return history, "", None, history
|
| 252 |
# Call your existing diabetes_bot function to generate an answer
|
| 253 |
answer = diabetes_bot(query, pdf)
|
| 254 |
-
# Append the new interaction
|
| 255 |
-
history.append(
|
| 256 |
-
|
|
|
|
| 257 |
return history, "", None, history
|
| 258 |
|
| 259 |
def clear_all():
|
|
@@ -280,18 +279,18 @@ with gr.Blocks() as app:
|
|
| 280 |
"""
|
| 281 |
)
|
| 282 |
|
| 283 |
-
# Chatbot component to
|
| 284 |
-
chatbot = gr.Chatbot(label="Conversation"
|
| 285 |
|
| 286 |
# Input row for query and PDF file (with PDF box sized smaller)
|
| 287 |
with gr.Row():
|
| 288 |
-
query_input = gr.Textbox(label="Ask a Question", placeholder="Type your diabetes-related query here...", lines=
|
| 289 |
with gr.Column(scale=0.5):
|
| 290 |
pdf_input = gr.File(label="Upload a PDF (optional, max 10 pages)", file_types=[".pdf"])
|
| 291 |
|
| 292 |
# Row for Submit and Clear buttons
|
| 293 |
with gr.Row():
|
| 294 |
-
submit_button = gr.Button("
|
| 295 |
clear_button = gr.Button("Clear")
|
| 296 |
|
| 297 |
# State to maintain conversation history
|
|
@@ -304,7 +303,7 @@ with gr.Blocks() as app:
|
|
| 304 |
outputs=[chatbot, query_input, pdf_input, state]
|
| 305 |
)
|
| 306 |
|
| 307 |
-
# Clear all
|
| 308 |
clear_button.click(
|
| 309 |
fn=clear_all,
|
| 310 |
inputs=[],
|
|
|
|
| 240 |
return answer + usage_message
|
| 241 |
|
| 242 |
# Gradio interface
|
|
|
|
|
|
|
| 243 |
def chat_wrapper(query, pdf, history):
|
| 244 |
# Initialize history if empty
|
| 245 |
if history is None:
|
|
|
|
| 249 |
return history, "", None, history
|
| 250 |
# Call your existing diabetes_bot function to generate an answer
|
| 251 |
answer = diabetes_bot(query, pdf)
|
| 252 |
+
# Append the new interaction as a message-style tuple (role, content)
|
| 253 |
+
history.append({"role": "user", "content": query})
|
| 254 |
+
history.append({"role": "assistant", "content": answer})
|
| 255 |
+
# Return the updated conversation and clear the query and pdf inputs
|
| 256 |
return history, "", None, history
|
| 257 |
|
| 258 |
def clear_all():
|
|
|
|
| 279 |
"""
|
| 280 |
)
|
| 281 |
|
| 282 |
+
# Create a Chatbot component with type set to "messages" and a specified height
|
| 283 |
+
chatbot = gr.Chatbot(label="Conversation", type="messages", height=400)
|
| 284 |
|
| 285 |
# Input row for query and PDF file (with PDF box sized smaller)
|
| 286 |
with gr.Row():
|
| 287 |
+
query_input = gr.Textbox(label="Ask a Question", placeholder="Type your diabetes-related query here...", lines=2)
|
| 288 |
with gr.Column(scale=0.5):
|
| 289 |
pdf_input = gr.File(label="Upload a PDF (optional, max 10 pages)", file_types=[".pdf"])
|
| 290 |
|
| 291 |
# Row for Submit and Clear buttons
|
| 292 |
with gr.Row():
|
| 293 |
+
submit_button = gr.Button("Submit", variant="primary")
|
| 294 |
clear_button = gr.Button("Clear")
|
| 295 |
|
| 296 |
# State to maintain conversation history
|
|
|
|
| 303 |
outputs=[chatbot, query_input, pdf_input, state]
|
| 304 |
)
|
| 305 |
|
| 306 |
+
# Clear all components including conversation history
|
| 307 |
clear_button.click(
|
| 308 |
fn=clear_all,
|
| 309 |
inputs=[],
|