Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -110,9 +110,11 @@ def analyze_message(text):
|
|
110 |
def analyze_composite(uploaded_file, *texts):
|
111 |
outputs = []
|
112 |
|
|
|
113 |
if uploaded_file is not None:
|
114 |
raw = uploaded_file.read()
|
115 |
name = uploaded_file.name.lower()
|
|
|
116 |
if name.endswith((".png", ".jpg", ".jpeg", ".tiff", ".bmp", ".gif")):
|
117 |
img = Image.open(io.BytesIO(raw))
|
118 |
content = pytesseract.image_to_string(img)
|
@@ -122,28 +124,35 @@ def analyze_composite(uploaded_file, *texts):
|
|
122 |
except UnicodeDecodeError:
|
123 |
content = raw.decode("latin-1")
|
124 |
|
|
|
125 |
r = analyze_message(content)
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
+ f"Emotional Tone : {r['tone_tag']}\n"
|
133 |
-
)
|
134 |
|
135 |
-
#
|
136 |
for idx, txt in enumerate(texts, start=1):
|
137 |
-
|
|
|
|
|
|
|
|
|
138 |
outputs.append(
|
139 |
f"── Message {idx} ──\n"
|
140 |
f"Emotion Profile : {r['emotion_profile']}\n"
|
141 |
f"Active Patterns : {r['active_patterns']}\n"
|
142 |
-
|
143 |
-
|
144 |
-
|
|
|
|
|
|
|
145 |
|
146 |
-
|
|
|
147 |
|
148 |
|
149 |
# ——— 6) Gradio interface ————————————————————————————————————————————————
|
|
|
110 |
def analyze_composite(uploaded_file, *texts):
|
111 |
outputs = []
|
112 |
|
113 |
+
# 1) If they uploaded a file, extract & analyze it
|
114 |
if uploaded_file is not None:
|
115 |
raw = uploaded_file.read()
|
116 |
name = uploaded_file.name.lower()
|
117 |
+
|
118 |
if name.endswith((".png", ".jpg", ".jpeg", ".tiff", ".bmp", ".gif")):
|
119 |
img = Image.open(io.BytesIO(raw))
|
120 |
content = pytesseract.image_to_string(img)
|
|
|
124 |
except UnicodeDecodeError:
|
125 |
content = raw.decode("latin-1")
|
126 |
|
127 |
+
# <-- here we define `r`
|
128 |
r = analyze_message(content)
|
129 |
+
outputs.append(
|
130 |
+
"── Uploaded File ──\n"
|
131 |
+
f"Emotion Profile : {r['emotion_profile']}\n"
|
132 |
+
f"Active Patterns : {r['active_patterns']}\n"
|
133 |
+
f"Emotional Tone : {r['tone_tag']}\n"
|
134 |
+
)
|
|
|
|
|
135 |
|
136 |
+
# 2) Then handle each of the text‐boxes
|
137 |
for idx, txt in enumerate(texts, start=1):
|
138 |
+
if not txt:
|
139 |
+
continue
|
140 |
+
|
141 |
+
# <-- and here we also define `r`
|
142 |
+
r = analyze_message(txt)
|
143 |
outputs.append(
|
144 |
f"── Message {idx} ──\n"
|
145 |
f"Emotion Profile : {r['emotion_profile']}\n"
|
146 |
f"Active Patterns : {r['active_patterns']}\n"
|
147 |
+
f"Emotional Tone : {r['tone_tag']}\n"
|
148 |
+
)
|
149 |
+
|
150 |
+
# 3) If nothing got run, prompt the user
|
151 |
+
if not outputs:
|
152 |
+
return "Please enter at least one message."
|
153 |
|
154 |
+
# 4) Otherwise join & return
|
155 |
+
return "\n".join(outputs)
|
156 |
|
157 |
|
158 |
# ——— 6) Gradio interface ————————————————————————————————————————————————
|