Shriharsh commited on
Commit
1f56954
·
verified ·
1 Parent(s): 674726b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -25
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.Markdown(
248
  """
249
- # Diabetes Research ChatBot Powered By Gemini 1.5 Flash And Pinecone 🩺
250
- **Powered by the latest diabetes research, Running on Gemini 1.5 Flash API**
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=3)
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("Submit")
269
  clear_button = gr.Button("Clear")
270
-
271
- output = gr.Textbox(label="Answer", lines=15)
272
-
273
- # Function to clear inputs and output
274
- def clear_all():
275
- return "", None, ""
276
-
277
  submit_button.click(
278
- fn=diabetes_bot,
279
- inputs=[query_input, pdf_input],
280
- outputs=output
281
  )
282
-
 
283
  clear_button.click(
284
  fn=clear_all,
285
  inputs=[],
286
- outputs=[query_input, pdf_input, output]
287
  )
288
 
289
- # Launch the app
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()