Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -478,8 +478,9 @@ def generate_abuse_score_chart(dates, scores, patterns):
|
|
478 |
x = range(len(scores))
|
479 |
plt.plot(x, scores, 'bo-', linewidth=2, markersize=8)
|
480 |
|
481 |
-
# Add labels for each point
|
482 |
for i, (score, pattern) in enumerate(zip(scores, patterns)):
|
|
|
483 |
plt.annotate(
|
484 |
f'{pattern}\n{score:.0f}%',
|
485 |
(i, score),
|
@@ -503,11 +504,11 @@ def generate_abuse_score_chart(dates, scores, patterns):
|
|
503 |
# X-axis labels
|
504 |
plt.xticks(x, dates, rotation=45)
|
505 |
|
506 |
-
# Risk level bands
|
507 |
-
plt.axhspan(0, 50, color='#90EE90', alpha=0.2) # light green
|
508 |
-
plt.axhspan(50, 70, color='#FFD700', alpha=0.2) # gold
|
509 |
-
plt.axhspan(70, 85, color='#FFA500', alpha=0.2) # orange
|
510 |
-
plt.axhspan(85, 100, color='#FF6B6B', alpha=0.2) # light red
|
511 |
|
512 |
# Add risk level labels
|
513 |
plt.text(-0.2, 25, 'Low Risk', rotation=90, va='center')
|
@@ -529,6 +530,7 @@ def generate_abuse_score_chart(dates, scores, patterns):
|
|
529 |
logger.error(f"Error generating abuse score chart: {e}")
|
530 |
return None
|
531 |
|
|
|
532 |
def analyze_composite(msg1, msg2, msg3, *answers_and_none):
|
533 |
"""Analyze multiple messages and checklist responses"""
|
534 |
logger.debug("\nπ STARTING NEW ANALYSIS")
|
@@ -915,10 +917,20 @@ def analyze_composite(msg1, msg2, msg3, *answers_and_none):
|
|
915 |
|
916 |
# Generate Timeline
|
917 |
logger.debug("\nπ Generating Timeline")
|
918 |
-
pattern_labels = [
|
919 |
-
|
920 |
-
|
921 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
922 |
timeline_image = generate_abuse_score_chart(dates_used, abuse_scores, pattern_labels)
|
923 |
logger.debug("Timeline generated successfully")
|
924 |
|
|
|
478 |
x = range(len(scores))
|
479 |
plt.plot(x, scores, 'bo-', linewidth=2, markersize=8)
|
480 |
|
481 |
+
# Add labels for each point with highest scoring pattern
|
482 |
for i, (score, pattern) in enumerate(zip(scores, patterns)):
|
483 |
+
# Get the pattern and its score
|
484 |
plt.annotate(
|
485 |
f'{pattern}\n{score:.0f}%',
|
486 |
(i, score),
|
|
|
504 |
# X-axis labels
|
505 |
plt.xticks(x, dates, rotation=45)
|
506 |
|
507 |
+
# Risk level bands with better colors
|
508 |
+
plt.axhspan(0, 50, color='#90EE90', alpha=0.2) # light green - Low Risk
|
509 |
+
plt.axhspan(50, 70, color='#FFD700', alpha=0.2) # gold - Moderate Risk
|
510 |
+
plt.axhspan(70, 85, color='#FFA500', alpha=0.2) # orange - High Risk
|
511 |
+
plt.axhspan(85, 100, color='#FF6B6B', alpha=0.2) # light red - Critical Risk
|
512 |
|
513 |
# Add risk level labels
|
514 |
plt.text(-0.2, 25, 'Low Risk', rotation=90, va='center')
|
|
|
530 |
logger.error(f"Error generating abuse score chart: {e}")
|
531 |
return None
|
532 |
|
533 |
+
|
534 |
def analyze_composite(msg1, msg2, msg3, *answers_and_none):
|
535 |
"""Analyze multiple messages and checklist responses"""
|
536 |
logger.debug("\nπ STARTING NEW ANALYSIS")
|
|
|
917 |
|
918 |
# Generate Timeline
|
919 |
logger.debug("\nπ Generating Timeline")
|
920 |
+
pattern_labels = []
|
921 |
+
for result, _ in results:
|
922 |
+
matched_scores = result[2] # Get the matched_scores from the result tuple
|
923 |
+
if matched_scores:
|
924 |
+
# Sort matched_scores by score and get the highest scoring pattern
|
925 |
+
highest_pattern = max(matched_scores, key=lambda x: x[1])
|
926 |
+
pattern_labels.append(highest_pattern[0]) # Add the pattern name
|
927 |
+
else:
|
928 |
+
pattern_labels.append("none")
|
929 |
+
|
930 |
+
logger.debug("Pattern labels for timeline:")
|
931 |
+
for i, (pattern, score) in enumerate(zip(pattern_labels, abuse_scores)):
|
932 |
+
logger.debug(f"Message {i+1}: {pattern} ({score:.1f}%)")
|
933 |
+
|
934 |
timeline_image = generate_abuse_score_chart(dates_used, abuse_scores, pattern_labels)
|
935 |
logger.debug("Timeline generated successfully")
|
936 |
|