isana25 commited on
Commit
aec8fe3
·
verified ·
1 Parent(s): e5b5613

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -13
app.py CHANGED
@@ -26,12 +26,12 @@ thread.start()
26
 
27
  def answer_question(question, context):
28
  if not question.strip():
29
- return "Please ask a valid question."
30
  input_data = {"question": question, "context": context if context.strip() else "medical symptoms and health conditions"}
31
  result = qa_pipeline(input_data)
32
  answer = result['answer']
33
  score = result['score']
34
- return f"Answer: {answer}\nConfidence Score: {score:.2f}"
35
 
36
  def get_vitals():
37
  hr = vitals["heart_rate"]
@@ -41,27 +41,45 @@ def get_vitals():
41
  alerts.append("⚠️ High heart rate detected!")
42
  if bp > 140:
43
  alerts.append("⚠️ High blood pressure detected!")
44
- alert_text = "\n".join(alerts) if alerts else "Vitals are within normal range."
45
- return f"Heart Rate: {hr} bpm\nBlood Pressure (Systolic): {bp} mmHg\n{alert_text}"
46
 
47
- with gr.Blocks() as demo:
48
- gr.Markdown("# 🧠 Doctor TWIN – The Virtual Healthcare Companion")
49
- gr.Markdown("Your personalized physician in the digital realm.")
 
 
 
 
 
 
50
 
51
  with gr.Tabs():
52
  with gr.TabItem("Virtual Consultation"):
53
- question_input = gr.Textbox(label="Your Question", lines=2, placeholder="Type your health question here...")
54
- context_input = gr.Textbox(label="Context (optional)", lines=4, placeholder="Add symptoms or details...")
55
- answer_output = gr.Textbox(label="Answer", lines=4)
 
 
 
 
 
 
56
  submit_btn = gr.Button("Get Answer")
57
  submit_btn.click(answer_question, inputs=[question_input, context_input], outputs=answer_output)
58
 
59
  with gr.TabItem("Monitoring & Alerts"):
60
- vitals_output = gr.Textbox(label="Simulated Vitals & Alerts", lines=6)
 
 
 
 
 
 
61
  refresh_btn = gr.Button("Refresh Vitals")
62
  refresh_btn.click(get_vitals, outputs=vitals_output)
63
 
64
- # Initialize vitals output on load
65
- vitals_output.value = get_vitals()
66
 
67
  demo.launch()
 
26
 
27
  def answer_question(question, context):
28
  if not question.strip():
29
+ return "Please enter a valid health-related question to get an answer."
30
  input_data = {"question": question, "context": context if context.strip() else "medical symptoms and health conditions"}
31
  result = qa_pipeline(input_data)
32
  answer = result['answer']
33
  score = result['score']
34
+ return f"🩺 Answer:\n{answer}\n\n🔍 Confidence Score: {score:.2f}"
35
 
36
  def get_vitals():
37
  hr = vitals["heart_rate"]
 
41
  alerts.append("⚠️ High heart rate detected!")
42
  if bp > 140:
43
  alerts.append("⚠️ High blood pressure detected!")
44
+ alert_text = "\n".join(alerts) if alerts else "Vitals are within normal range."
45
+ return f"💓 Heart Rate: {hr} bpm\n🩸 Blood Pressure (Systolic): {bp} mmHg\n\n{alert_text}"
46
 
47
+ with gr.Blocks(title="Doctor TWIN – Virtual Healthcare Companion") as demo:
48
+ gr.Markdown("# 🧠 Doctor TWIN – Your Virtual Healthcare Companion")
49
+ gr.Markdown(
50
+ "Welcome! This app helps you get instant answers to your health questions "
51
+ "and simulates monitoring of vital signs like heart rate and blood pressure.\n\n"
52
+ "**Use the tabs below to navigate between:**\n"
53
+ "- **Virtual Consultation:** Ask health-related questions and get AI-generated answers.\n"
54
+ "- **Monitoring & Alerts:** See simulated live vital signs and get alerts if values are out of range."
55
+ )
56
 
57
  with gr.Tabs():
58
  with gr.TabItem("Virtual Consultation"):
59
+ gr.Markdown(
60
+ "**How to use Virtual Consultation:**\n"
61
+ "1. Type a clear, health-related question.\n"
62
+ "2. Optionally provide additional context (like symptoms or relevant info).\n"
63
+ "3. Click **Get Answer** to receive an AI-generated response."
64
+ )
65
+ question_input = gr.Textbox(label="Your Health Question", lines=2, placeholder="e.g., What are common causes of fatigue?")
66
+ context_input = gr.Textbox(label="Additional Context (optional)", lines=4, placeholder="e.g., I feel tired mostly in the afternoon and have trouble sleeping.")
67
+ answer_output = gr.Textbox(label="Answer", lines=6, interactive=False)
68
  submit_btn = gr.Button("Get Answer")
69
  submit_btn.click(answer_question, inputs=[question_input, context_input], outputs=answer_output)
70
 
71
  with gr.TabItem("Monitoring & Alerts"):
72
+ gr.Markdown(
73
+ "**Simulated Monitoring & Alerts:**\n"
74
+ "This section shows simulated vital signs data updating every few seconds.\n"
75
+ "Click **Refresh Vitals** to update the values.\n"
76
+ "Watch for alerts indicating if vitals exceed safe thresholds."
77
+ )
78
+ vitals_output = gr.Textbox(label="Simulated Vitals & Alerts", lines=6, interactive=False)
79
  refresh_btn = gr.Button("Refresh Vitals")
80
  refresh_btn.click(get_vitals, outputs=vitals_output)
81
 
82
+ # Initialize vitals output on load
83
+ vitals_output.value = get_vitals()
84
 
85
  demo.launch()