Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
-
import
|
|
|
2 |
|
3 |
-
#
|
4 |
-
|
5 |
-
print("🔍 TESSERACT PATH:", repr(res.stdout.strip()), "— stderr:", repr(res.stderr.strip()))
|
6 |
import gradio as gr
|
7 |
import torch
|
8 |
from transformers import pipeline as hf_pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
@@ -204,32 +204,22 @@ def analyze_composite(uploaded_file, *texts):
|
|
204 |
|
205 |
# 1) File upload
|
206 |
if uploaded_file is not None:
|
207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
try:
|
209 |
-
|
210 |
-
except
|
211 |
-
|
212 |
-
with open(uploaded_file, "rb") as f:
|
213 |
-
raw = f.read()
|
214 |
-
|
215 |
-
# get the filename (or just use the string if no .name attr)
|
216 |
-
name = (
|
217 |
-
uploaded_file.name.lower()
|
218 |
-
if hasattr(uploaded_file, "name")
|
219 |
-
else uploaded_file.lower()
|
220 |
-
)
|
221 |
|
222 |
-
|
223 |
-
|
224 |
-
img = Image.open(io.BytesIO(raw))
|
225 |
-
content = pytesseract.image_to_string(img)
|
226 |
-
else:
|
227 |
-
try:
|
228 |
-
content = raw.decode("utf-8")
|
229 |
-
except UnicodeDecodeError:
|
230 |
-
content = raw.decode("latin-1")
|
231 |
-
|
232 |
-
r = analyze_message(content)
|
233 |
outputs.append(
|
234 |
"── Uploaded File ──\n"
|
235 |
f"Emotion Profile : {r['emotion_profile']}\n"
|
|
|
1 |
+
import easyocr
|
2 |
+
import numpy as np
|
3 |
|
4 |
+
# create a reader once
|
5 |
+
ocr_reader = easyocr.Reader(["en"], gpu=False)
|
|
|
6 |
import gradio as gr
|
7 |
import torch
|
8 |
from transformers import pipeline as hf_pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
|
|
204 |
|
205 |
# 1) File upload
|
206 |
if uploaded_file is not None:
|
207 |
+
# ... read `raw` exactly as you have it now ...
|
208 |
+
|
209 |
+
name = (uploaded_file.name if hasattr(uploaded_file, "name") else uploaded_file).lower()
|
210 |
+
if name.endswith((".png",".jpg",".jpeg",".tiff",".bmp",".gif")):
|
211 |
+
img = Image.open(io.BytesIO(raw))
|
212 |
+
arr = np.array(img.convert("RGB"))
|
213 |
+
texts = ocr_reader.readtext(arr, detail=0)
|
214 |
+
content = "\n".join(texts)
|
215 |
+
else:
|
216 |
try:
|
217 |
+
content = raw.decode("utf-8")
|
218 |
+
except:
|
219 |
+
content = raw.decode("latin-1")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
|
221 |
+
r = analyze_message(content)
|
222 |
+
outputs.append(…)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
outputs.append(
|
224 |
"── Uploaded File ──\n"
|
225 |
f"Emotion Profile : {r['emotion_profile']}\n"
|