kseth9852 commited on
Commit
72935fc
·
verified ·
1 Parent(s): 2f20dee
Files changed (1) hide show
  1. app.py +15 -21
app.py CHANGED
@@ -4,6 +4,9 @@ from transformers import pipeline
4
  from gtts import gTTS
5
  import tempfile
6
  import os
 
 
 
7
 
8
  # Streamlit page setup
9
  st.set_page_config(page_title="Health Report Analyzer", page_icon="🩺")
@@ -25,21 +28,6 @@ def extract_text(file):
25
  def load_explainer():
26
  return pipeline("text2text-generation", model="google/flan-t5-large")
27
 
28
- # Doctor recommendation based on keywords
29
- def doctor_suggestion(term):
30
- doctor_map = {
31
- "creatinine": ("nephrologist", "This test usually relates to kidney function."),
32
- "hemoglobin": ("hematologist", "This test is related to red blood cells and anemia."),
33
- "platelets": ("hematologist", "Platelet levels affect blood clotting."),
34
- "cholesterol": ("cardiologist", "High cholesterol can increase risk of heart disease."),
35
- "ecg": ("cardiologist", "This test checks heart activity and rhythm."),
36
- "ct scan": ("radiologist", "A CT scan helps visualize internal body structures.")
37
- }
38
- for key in doctor_map:
39
- if key in term.lower():
40
- return doctor_map[key]
41
- return None, None
42
-
43
  # Main logic
44
  if uploaded_file:
45
  text_data = extract_text(uploaded_file)
@@ -75,12 +63,6 @@ if uploaded_file:
75
  st.success("Explanation:")
76
  st.write(response)
77
 
78
- # Doctor suggestion
79
- doctor, note = doctor_suggestion(user_question)
80
- if doctor:
81
- st.markdown(f"🩺 **You should consider seeing a {doctor}.**")
82
- st.markdown(f"📌 _Note: {note}_")
83
-
84
  # Text-to-speech using gTTS
85
  tts = gTTS(text=response)
86
  temp_audio = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
@@ -90,5 +72,17 @@ if uploaded_file:
90
  audio_bytes = audio_file.read()
91
  st.audio(audio_bytes, format='audio/mp3')
92
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  else:
94
  st.info("Upload a PDF Health Report to begin.")
 
4
  from gtts import gTTS
5
  import tempfile
6
  import os
7
+ import qrcode
8
+ from PIL import Image
9
+ import io
10
 
11
  # Streamlit page setup
12
  st.set_page_config(page_title="Health Report Analyzer", page_icon="🩺")
 
28
  def load_explainer():
29
  return pipeline("text2text-generation", model="google/flan-t5-large")
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  # Main logic
32
  if uploaded_file:
33
  text_data = extract_text(uploaded_file)
 
63
  st.success("Explanation:")
64
  st.write(response)
65
 
 
 
 
 
 
 
66
  # Text-to-speech using gTTS
67
  tts = gTTS(text=response)
68
  temp_audio = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3")
 
72
  audio_bytes = audio_file.read()
73
  st.audio(audio_bytes, format='audio/mp3')
74
 
75
+ # Generate QR Code for the explanation text
76
+ if st.button("📱 Generate QR Code to Share Explanation"):
77
+ qr = qrcode.QRCode(version=1, box_size=10, border=5)
78
+ qr.add_data(response[:300]) # Keep text short for QR
79
+ qr.make(fit=True)
80
+
81
+ img = qr.make_image(fill='black', back_color='white')
82
+
83
+ buf = io.BytesIO()
84
+ img.save(buf)
85
+ st.image(buf.getvalue(), caption="Scan to Read Explanation", use_column_width=False)
86
+
87
  else:
88
  st.info("Upload a PDF Health Report to begin.")