SamanthaStorm commited on
Commit
5ebe61a
·
verified ·
1 Parent(s): a15a709

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -194,10 +194,25 @@ def analyze_message(text):
194
  # ——— 5) Composite Wrapper ————————————————————————————————————————————————
195
  def analyze_composite(uploaded_file, *texts):
196
  outputs = []
197
- # file upload
 
198
  if uploaded_file is not None:
199
- raw = uploaded_file.read()
200
- name = uploaded_file.name.lower()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  if name.endswith((".png", ".jpg", ".jpeg", ".tiff", ".bmp", ".gif")):
202
  img = Image.open(io.BytesIO(raw))
203
  content = pytesseract.image_to_string(img)
@@ -206,6 +221,7 @@ def analyze_composite(uploaded_file, *texts):
206
  content = raw.decode("utf-8")
207
  except UnicodeDecodeError:
208
  content = raw.decode("latin-1")
 
209
  r = analyze_message(content)
210
  outputs.append(
211
  "── Uploaded File ──\n"
@@ -213,7 +229,8 @@ def analyze_composite(uploaded_file, *texts):
213
  f"Active Patterns : {r['active_patterns']}\n"
214
  f"Emotional Tone : {r['tone_tag']}\n"
215
  )
216
- # text inputs
 
217
  for idx, txt in enumerate(texts, start=1):
218
  if not txt:
219
  continue
 
194
  # ——— 5) Composite Wrapper ————————————————————————————————————————————————
195
  def analyze_composite(uploaded_file, *texts):
196
  outputs = []
197
+
198
+ # 1) File upload
199
  if uploaded_file is not None:
200
+ # uploaded_file may be a file-like with .read(), or just a path string
201
+ try:
202
+ raw = uploaded_file.read()
203
+ except Exception:
204
+ # fall back to treating uploaded_file as a filesystem path
205
+ with open(uploaded_file, "rb") as f:
206
+ raw = f.read()
207
+
208
+ # get the filename (or just use the string if no .name attr)
209
+ name = (
210
+ uploaded_file.name.lower()
211
+ if hasattr(uploaded_file, "name")
212
+ else uploaded_file.lower()
213
+ )
214
+
215
+ # now branch on extension
216
  if name.endswith((".png", ".jpg", ".jpeg", ".tiff", ".bmp", ".gif")):
217
  img = Image.open(io.BytesIO(raw))
218
  content = pytesseract.image_to_string(img)
 
221
  content = raw.decode("utf-8")
222
  except UnicodeDecodeError:
223
  content = raw.decode("latin-1")
224
+
225
  r = analyze_message(content)
226
  outputs.append(
227
  "── Uploaded File ──\n"
 
229
  f"Active Patterns : {r['active_patterns']}\n"
230
  f"Emotional Tone : {r['tone_tag']}\n"
231
  )
232
+
233
+ # 2) Text‐box inputs…
234
  for idx, txt in enumerate(texts, start=1):
235
  if not txt:
236
  continue