Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -213,26 +213,19 @@ def analyze_composite(uploaded_file, *texts):
|
|
213 |
|
214 |
# get the filename (or just lowercase the string if it's a path)
|
215 |
name = (
|
216 |
-
uploaded_file.name.lower()
|
217 |
-
if hasattr(uploaded_file, "name")
|
218 |
-
else uploaded_file.lower()
|
219 |
)
|
220 |
-
|
221 |
-
# branch on extension
|
222 |
-
if name.endswith((".png", ".jpg", ".jpeg", ".tiff", ".bmp", ".gif")):
|
223 |
img = Image.open(io.BytesIO(raw))
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
# content = "\n".join(texts)
|
228 |
-
content = pytesseract.image_to_string(img)
|
229 |
else:
|
230 |
try:
|
231 |
content = raw.decode("utf-8")
|
232 |
except UnicodeDecodeError:
|
233 |
content = raw.decode("latin-1")
|
234 |
|
235 |
-
# now analyze that extracted content
|
236 |
r = analyze_message(content)
|
237 |
outputs.append(
|
238 |
"── Uploaded File ──\n"
|
@@ -240,8 +233,6 @@ def analyze_composite(uploaded_file, *texts):
|
|
240 |
f"Active Patterns : {r['active_patterns']}\n"
|
241 |
f"Emotional Tone : {r['tone_tag']}\n"
|
242 |
)
|
243 |
-
|
244 |
-
# 2) Handle any text‐box inputs
|
245 |
for idx, txt in enumerate(texts, start=1):
|
246 |
if not txt:
|
247 |
continue
|
@@ -252,18 +243,16 @@ def analyze_composite(uploaded_file, *texts):
|
|
252 |
f"Active Patterns : {r['active_patterns']}\n"
|
253 |
f"Emotional Tone : {r['tone_tag']}\n"
|
254 |
)
|
255 |
-
|
256 |
-
# 3) No input guard
|
257 |
if not outputs:
|
258 |
return "Please enter at least one message."
|
259 |
-
|
260 |
-
# 4) Return combined results
|
261 |
return "\n".join(outputs)
|
262 |
-
|
263 |
-
|
|
|
264 |
iface = gr.Interface(
|
265 |
fn=analyze_composite,
|
266 |
-
inputs=[gr.File(file_types=[".txt",
|
|
|
267 |
outputs=gr.Textbox(label="Analysis"),
|
268 |
title="Tether Analyzer (extended tone tags)",
|
269 |
description="Emotion profiling, pattern tags, and a wide set of nuanced tone categories—no abuse score or DARVO."
|
|
|
213 |
|
214 |
# get the filename (or just lowercase the string if it's a path)
|
215 |
name = (
|
216 |
+
uploaded_file.name.lower() if hasattr(uploaded_file, "name") else uploaded_file.lower()
|
|
|
|
|
217 |
)
|
218 |
+
if name.endswith((".png",".jpg",".jpeg",".tiff",".bmp",".gif")):
|
|
|
|
|
219 |
img = Image.open(io.BytesIO(raw))
|
220 |
+
arr = np.array(img.convert("RGB"))
|
221 |
+
texts_ocr = ocr_reader.readtext(arr, detail=0)
|
222 |
+
content = "\n".join(texts_ocr)
|
|
|
|
|
223 |
else:
|
224 |
try:
|
225 |
content = raw.decode("utf-8")
|
226 |
except UnicodeDecodeError:
|
227 |
content = raw.decode("latin-1")
|
228 |
|
|
|
229 |
r = analyze_message(content)
|
230 |
outputs.append(
|
231 |
"── Uploaded File ──\n"
|
|
|
233 |
f"Active Patterns : {r['active_patterns']}\n"
|
234 |
f"Emotional Tone : {r['tone_tag']}\n"
|
235 |
)
|
|
|
|
|
236 |
for idx, txt in enumerate(texts, start=1):
|
237 |
if not txt:
|
238 |
continue
|
|
|
243 |
f"Active Patterns : {r['active_patterns']}\n"
|
244 |
f"Emotional Tone : {r['tone_tag']}\n"
|
245 |
)
|
|
|
|
|
246 |
if not outputs:
|
247 |
return "Please enter at least one message."
|
|
|
|
|
248 |
return "\n".join(outputs)
|
249 |
+
|
250 |
+
# ——— 7) Gradio interface ———————————————————————————————————————————————
|
251 |
+
message_inputs = [gr.Textbox(label="Message")]
|
252 |
iface = gr.Interface(
|
253 |
fn=analyze_composite,
|
254 |
+
inputs=[gr.File(file_types=[".txt",".png",".jpg",".jpeg"], label="Upload text or image")]
|
255 |
+
+ ] + message_inputs,
|
256 |
outputs=gr.Textbox(label="Analysis"),
|
257 |
title="Tether Analyzer (extended tone tags)",
|
258 |
description="Emotion profiling, pattern tags, and a wide set of nuanced tone categories—no abuse score or DARVO."
|