Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -106,15 +106,13 @@ def analyze_message(text):
|
|
106 |
}
|
107 |
|
108 |
|
109 |
-
# ——— 5) Composite wrapper (handles .txt or image + text boxes) ——————————————————————
|
110 |
def analyze_composite(uploaded_file, *texts):
|
111 |
outputs = []
|
112 |
|
113 |
-
# 1)
|
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,37 +122,33 @@ def analyze_composite(uploaded_file, *texts):
|
|
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"
|
132 |
-
f"
|
133 |
-
f"
|
|
|
134 |
)
|
135 |
|
136 |
-
# 2)
|
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"
|
146 |
-
f"
|
147 |
-
f"
|
|
|
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 ————————————————————————————————————————————————
|
159 |
message_inputs = [gr.Textbox(label=f"Message {i+1}") for i in range(3)]
|
160 |
|
|
|
106 |
}
|
107 |
|
108 |
|
|
|
109 |
def analyze_composite(uploaded_file, *texts):
|
110 |
outputs = []
|
111 |
|
112 |
+
# 1) Uploaded file block
|
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 |
except UnicodeDecodeError:
|
123 |
content = raw.decode("latin-1")
|
124 |
|
|
|
125 |
r = analyze_message(content)
|
126 |
outputs.append(
|
127 |
"── Uploaded File ──\n"
|
128 |
+
f"Matched Phrases : {r['matched_phrases']}\n"
|
129 |
+
f"Emotion Profile : {r['emotion_profile']}\n"
|
130 |
+
f"Active Patterns : {r['active_patterns']}\n"
|
131 |
+
f"Emotional Tone : {r['tone_tag']}\n" # <-- use r['tone_tag']
|
132 |
)
|
133 |
|
134 |
+
# 2) Text-box blocks
|
135 |
for idx, txt in enumerate(texts, start=1):
|
136 |
if not txt:
|
137 |
continue
|
|
|
|
|
138 |
r = analyze_message(txt)
|
139 |
outputs.append(
|
140 |
f"── Message {idx} ──\n"
|
141 |
+
f"Matched Phrases : {r['matched_phrases']}\n"
|
142 |
+
f"Emotion Profile : {r['emotion_profile']}\n"
|
143 |
+
f"Active Patterns : {r['active_patterns']}\n"
|
144 |
+
f"Emotional Tone : {r['tone_tag']}\n" # <-- and here, too
|
145 |
)
|
146 |
|
|
|
147 |
if not outputs:
|
148 |
return "Please enter at least one message."
|
149 |
|
|
|
150 |
return "\n".join(outputs)
|
151 |
|
|
|
152 |
# ——— 6) Gradio interface ————————————————————————————————————————————————
|
153 |
message_inputs = [gr.Textbox(label=f"Message {i+1}") for i in range(3)]
|
154 |
|