Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -10,25 +10,28 @@ from PIL import Image
|
|
10 |
from datetime import datetime
|
11 |
|
12 |
# --- Timeline Visualization Function ---
|
13 |
-
def
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
}
|
20 |
try:
|
21 |
parsed_dates = [datetime.strptime(d, "%Y-%m-%d") for d in dates]
|
22 |
except Exception:
|
23 |
parsed_dates = list(range(len(dates)))
|
24 |
|
25 |
-
fig, ax = plt.subplots(figsize=(
|
26 |
-
ax.
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
30 |
ax.set_xlabel("Date")
|
31 |
-
ax.set_ylabel("
|
|
|
32 |
ax.grid(True)
|
33 |
plt.tight_layout()
|
34 |
|
@@ -331,7 +334,8 @@ def analyze_composite(msg1, date1, msg2, date2, msg3, date3, *answers_and_none):
|
|
331 |
out += f"\n\n{stage_text}"
|
332 |
out += darvo_blurb
|
333 |
|
334 |
-
|
|
|
335 |
return out, timeline_image
|
336 |
|
337 |
message_date_pairs = [(gr.Textbox(label=f"Message {i+1}"), gr.Textbox(label=f"Date {i+1} (optional)", placeholder="e.g. 2025-04-22")) for i in range(3)]
|
|
|
10 |
from datetime import datetime
|
11 |
|
12 |
# --- Timeline Visualization Function ---
|
13 |
+
def generate_abuse_score_chart(dates, scores, labels):
|
14 |
+
import matplotlib.pyplot as plt
|
15 |
+
import io
|
16 |
+
from PIL import Image
|
17 |
+
from datetime import datetime
|
18 |
+
|
|
|
19 |
try:
|
20 |
parsed_dates = [datetime.strptime(d, "%Y-%m-%d") for d in dates]
|
21 |
except Exception:
|
22 |
parsed_dates = list(range(len(dates)))
|
23 |
|
24 |
+
fig, ax = plt.subplots(figsize=(8, 3))
|
25 |
+
ax.plot(parsed_dates, scores, marker='o', linestyle='-', color='darkred', linewidth=2)
|
26 |
+
|
27 |
+
for i, (x, y) in enumerate(zip(parsed_dates, scores)):
|
28 |
+
label = labels[i]
|
29 |
+
ax.text(x, y + 2, f"{label}\n{int(y)}%", ha='center', fontsize=8, color='black')
|
30 |
+
|
31 |
+
ax.set_title("Abuse Intensity Over Time")
|
32 |
ax.set_xlabel("Date")
|
33 |
+
ax.set_ylabel("Abuse Score (%)")
|
34 |
+
ax.set_ylim(0, 105)
|
35 |
ax.grid(True)
|
36 |
plt.tight_layout()
|
37 |
|
|
|
334 |
out += f"\n\n{stage_text}"
|
335 |
out += darvo_blurb
|
336 |
|
337 |
+
pattern_labels = [r[0][2][0][0] for r in results] # top label for each message
|
338 |
+
timeline_image = generate_abuse_score_chart(dates_used, abuse_scores, pattern_labels)
|
339 |
return out, timeline_image
|
340 |
|
341 |
message_date_pairs = [(gr.Textbox(label=f"Message {i+1}"), gr.Textbox(label=f"Date {i+1} (optional)", placeholder="e.g. 2025-04-22")) for i in range(3)]
|