saadawaissheikh commited on
Commit
f9fc52e
Β·
verified Β·
1 Parent(s): 1557d32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -11
app.py CHANGED
@@ -95,17 +95,36 @@ def extract_text_from_image(img_path):
95
  raw_text = pytesseract.image_to_string(image)
96
  return extract_tablet_names(raw_text)
97
 
98
- # βœ… Tablet Claim Checker
99
- def check_tablets(img):
100
- tablets = extract_text_from_image(img)
101
- if not tablets:
102
- return "❌ No tablets found in receipt."
103
- result = ""
104
- for med in tablets:
105
- question = f"Is the medicine {med} covered under the healthcare policy?"
106
- answer = qa_chain.run(question)
107
- result += f"🧾 **{med}** β†’ {answer}\n\n"
108
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
  # βœ… Gradio UI
111
  with gr.Blocks(title="Healthcare Chatbot") as app:
 
95
  raw_text = pytesseract.image_to_string(image)
96
  return extract_tablet_names(raw_text)
97
 
98
+ def check_tablets(img_path):
99
+ try:
100
+ # Step 1: Confirm image path is received
101
+ if not img_path or not os.path.exists(img_path):
102
+ return "❌ Error: Image path is invalid or file not found."
103
+
104
+ # Step 2: Run OCR
105
+ image = Image.open(img_path)
106
+ raw_text = pytesseract.image_to_string(image)
107
+
108
+ # Step 3: Extract medicine names
109
+ tablets = extract_tablet_names(raw_text)
110
+ if not tablets:
111
+ return "❌ No tablets found in the receipt text."
112
+
113
+ # Step 4: Use RAG to check each tablet
114
+ result = ""
115
+ for med in tablets:
116
+ question = f"Is the medicine {med} covered under the healthcare policy?"
117
+ try:
118
+ answer = qa_chain.run(question)
119
+ except Exception as e:
120
+ answer = f"RAG error: {str(e)}"
121
+ result += f"πŸ’Š {med} β†’ {answer}\n\n"
122
+
123
+ return result.strip()
124
+
125
+ except Exception as e:
126
+ return f"❌ Critical error during tablet check: {str(e)}"
127
+
128
 
129
  # βœ… Gradio UI
130
  with gr.Blocks(title="Healthcare Chatbot") as app: