Update app.py
Browse files
app.py
CHANGED
|
@@ -240,51 +240,75 @@ def diabetes_bot(query, pdf_file=None):
|
|
| 240 |
return answer + usage_message
|
| 241 |
|
| 242 |
# Gradio interface
|
|
|
|
| 243 |
|
| 244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
|
| 246 |
with gr.Blocks() as app:
|
| 247 |
-
gr.
|
| 248 |
"""
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
Ask questions about diabetes directly or upload a research paper (up to 10 pages) for specific Q&A.
|
| 252 |
-
|
| 253 |
<br>
|
| 254 |
-
<div style="border: 1px solid #ccc; border-radius: 5px; padding: 10px; background-color: #f9f9f9;">
|
| 255 |
<strong>Disclaimer:</strong>
|
| 256 |
The information provided by this chatbot is for research and informational purposes only and is not intended to substitute professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition.
|
| 257 |
</div>
|
| 258 |
<br>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
"""
|
| 260 |
)
|
| 261 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
with gr.Row():
|
| 263 |
-
query_input = gr.Textbox(label="Ask a Question", placeholder="Type your diabetes-related query here...", lines=
|
| 264 |
with gr.Column(scale=0.5):
|
| 265 |
pdf_input = gr.File(label="Upload a PDF (optional, max 10 pages)", file_types=[".pdf"])
|
| 266 |
-
|
|
|
|
| 267 |
with gr.Row():
|
| 268 |
-
submit_button = gr.Button("
|
| 269 |
clear_button = gr.Button("Clear")
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
return "", None, ""
|
| 276 |
-
|
| 277 |
submit_button.click(
|
| 278 |
-
fn=
|
| 279 |
-
inputs=[query_input, pdf_input],
|
| 280 |
-
outputs=
|
| 281 |
)
|
| 282 |
-
|
|
|
|
| 283 |
clear_button.click(
|
| 284 |
fn=clear_all,
|
| 285 |
inputs=[],
|
| 286 |
-
outputs=[query_input, pdf_input,
|
| 287 |
)
|
| 288 |
|
| 289 |
-
|
| 290 |
-
app.launch()
|
|
|
|
| 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:
|
| 248 |
+
history = []
|
| 249 |
+
# If no query is provided, return the current history without changes
|
| 250 |
+
if query.strip() == "":
|
| 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 to the history as a tuple (user, bot)
|
| 255 |
+
history.append((query, answer))
|
| 256 |
+
# Return the updated conversation, and clear the query and pdf inputs
|
| 257 |
+
return history, "", None, history
|
| 258 |
+
|
| 259 |
+
def clear_all():
|
| 260 |
+
# Clear conversation history and inputs
|
| 261 |
+
return [], "", None, []
|
| 262 |
|
| 263 |
with gr.Blocks() as app:
|
| 264 |
+
gr.HTML(
|
| 265 |
"""
|
| 266 |
+
<h1 style="text-align:center;">Diabetes Research ChatBot Powered By Gemini 1.5 Flash And Pinecone 🩺</h1>
|
| 267 |
+
<p style="text-align:center;"><strong>Powered by the latest diabetes research, Running on Gemini 1.5 Flash API</strong></p>
|
| 268 |
+
<p style="text-align:center;">Ask questions about diabetes directly or upload a research paper (up to 10 pages) for specific Q&A.</p>
|
|
|
|
| 269 |
<br>
|
| 270 |
+
<div style="border: 1px solid #ccc; border-radius: 5px; padding: 10px; background-color: #f9f9f9; margin:auto; width:80%;">
|
| 271 |
<strong>Disclaimer:</strong>
|
| 272 |
The information provided by this chatbot is for research and informational purposes only and is not intended to substitute professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition.
|
| 273 |
</div>
|
| 274 |
<br>
|
| 275 |
+
<p style="text-align:center;">Example Queries:</p>
|
| 276 |
+
<ul style="text-align:center;">
|
| 277 |
+
<li>"What is new with type 2 diabetes management research?"</li>
|
| 278 |
+
<li>"Tell me about new treatments in diabetes if any."</li>
|
| 279 |
+
</ul>
|
| 280 |
"""
|
| 281 |
)
|
| 282 |
+
|
| 283 |
+
# Chatbot component to display conversation history
|
| 284 |
+
chatbot = gr.Chatbot(label="Conversation").style(height=400)
|
| 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=4)
|
| 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("Ask", variant="primary")
|
| 295 |
clear_button = gr.Button("Clear")
|
| 296 |
+
|
| 297 |
+
# State to maintain conversation history
|
| 298 |
+
state = gr.State([])
|
| 299 |
+
|
| 300 |
+
# On submit, update the conversation and clear inputs; outputs: chatbot, query_input, pdf_input, state
|
|
|
|
|
|
|
| 301 |
submit_button.click(
|
| 302 |
+
fn=chat_wrapper,
|
| 303 |
+
inputs=[query_input, pdf_input, state],
|
| 304 |
+
outputs=[chatbot, query_input, pdf_input, state]
|
| 305 |
)
|
| 306 |
+
|
| 307 |
+
# Clear all the components including conversation history
|
| 308 |
clear_button.click(
|
| 309 |
fn=clear_all,
|
| 310 |
inputs=[],
|
| 311 |
+
outputs=[chatbot, query_input, pdf_input, state]
|
| 312 |
)
|
| 313 |
|
| 314 |
+
app.launch()
|
|
|