SamanthaStorm commited on
Commit
8ac43b3
·
verified ·
1 Parent(s): a3a4fa0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -28
app.py CHANGED
@@ -1,8 +1,8 @@
1
- import subprocess
 
2
 
3
- # debug line: will show up in your Container logs
4
- res = subprocess.run(["which", "tesseract"], capture_output=True, text=True)
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
- # uploaded_file may be a file-like with .read(), or just a path string
 
 
 
 
 
 
 
 
208
  try:
209
- raw = uploaded_file.read()
210
- except Exception:
211
- # fall back to treating uploaded_file as a filesystem path
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
- # now branch on extension
223
- if name.endswith((".png", ".jpg", ".jpeg", ".tiff", ".bmp", ".gif")):
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"