Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|