Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,10 +3,11 @@ import cv2
|
|
3 |
import numpy as np
|
4 |
import tempfile
|
5 |
import os
|
6 |
-
import easyocr
|
7 |
from PIL import Image, ImageDraw, ImageFont
|
8 |
from deep_translator import GoogleTranslator
|
9 |
import base64
|
|
|
10 |
|
11 |
from langchain.prompts import PromptTemplate
|
12 |
from langchain.chains import LLMChain
|
@@ -110,10 +111,10 @@ def save_text_as_image(text, file_path):
|
|
110 |
|
111 |
set_background("background_img.jpg")
|
112 |
|
113 |
-
# OCR
|
114 |
-
@st.cache_resource
|
115 |
-
def load_easyocr_reader():
|
116 |
-
|
117 |
|
118 |
st.sidebar.title("💊 MediAssist")
|
119 |
st.sidebar.markdown("Analyze prescriptions with ease using AI")
|
@@ -155,10 +156,17 @@ if uploaded_file:
|
|
155 |
dilated_path = orig_path.replace(".png", "_dilated.png")
|
156 |
cv2.imwrite(dilated_path, dilated)
|
157 |
|
158 |
-
|
159 |
-
|
|
|
|
|
|
|
160 |
text = "\n".join(text_list)
|
161 |
|
|
|
|
|
|
|
|
|
162 |
col1, col2 = st.columns([1, 2])
|
163 |
with col1:
|
164 |
st.image(dilated, caption="🧾 Preprocessed Prescription", channels="GRAY", use_container_width=True)
|
|
|
3 |
import numpy as np
|
4 |
import tempfile
|
5 |
import os
|
6 |
+
# import easyocr
|
7 |
from PIL import Image, ImageDraw, ImageFont
|
8 |
from deep_translator import GoogleTranslator
|
9 |
import base64
|
10 |
+
from paddleocr import PaddleOCR
|
11 |
|
12 |
from langchain.prompts import PromptTemplate
|
13 |
from langchain.chains import LLMChain
|
|
|
111 |
|
112 |
set_background("background_img.jpg")
|
113 |
|
114 |
+
# # OCR
|
115 |
+
# @st.cache_resource
|
116 |
+
# def load_easyocr_reader():
|
117 |
+
# return easyocr.Reader(['en'])
|
118 |
|
119 |
st.sidebar.title("💊 MediAssist")
|
120 |
st.sidebar.markdown("Analyze prescriptions with ease using AI")
|
|
|
156 |
dilated_path = orig_path.replace(".png", "_dilated.png")
|
157 |
cv2.imwrite(dilated_path, dilated)
|
158 |
|
159 |
+
|
160 |
+
ocr = PaddleOCR(use_angle_cls=True, lang='en') # use_angle_cls for better orientation handling
|
161 |
+
result = ocr.ocr(dilated_path, cls=True)
|
162 |
+
text_list = [line[1][0] for line in result[0]] # Extract only text
|
163 |
+
|
164 |
text = "\n".join(text_list)
|
165 |
|
166 |
+
# reader = easyocr.Reader(['en'])
|
167 |
+
# text_list = reader.readtext(dilated, detail=0)
|
168 |
+
# text = "\n".join(text_list)
|
169 |
+
|
170 |
col1, col2 = st.columns([1, 2])
|
171 |
with col1:
|
172 |
st.image(dilated, caption="🧾 Preprocessed Prescription", channels="GRAY", use_container_width=True)
|