SamanthaStorm commited on
Commit
6df76eb
Β·
verified Β·
1 Parent(s): 9e6201d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -7
app.py CHANGED
@@ -1522,9 +1522,19 @@ def format_results_for_new_ui(analysis_output, timeline_image, safety_plan):
1522
  else:
1523
  risk_level = 'low'
1524
 
1525
- # Extract detected patterns
1526
  patterns = []
1527
  in_patterns_section = False
 
 
 
 
 
 
 
 
 
 
1528
  for line in lines:
1529
  if 'πŸ” Detected Patterns:' in line:
1530
  in_patterns_section = True
@@ -1539,18 +1549,35 @@ def format_results_for_new_ui(analysis_output, timeline_image, safety_plan):
1539
  else:
1540
  continue
1541
 
1542
- # Extract pattern names
1543
- pattern_text = line.split(':', 1)[1].strip() if ':' in line else line
1544
- pattern_names = [p.strip().split('(')[0] for p in pattern_text.split(',')]
 
 
 
 
 
 
1545
 
1546
- for pattern_name in pattern_names:
1547
- if pattern_name:
 
 
 
 
 
 
 
 
 
 
1548
  patterns.append({
1549
- 'name': pattern_name.title(),
1550
  'severity': severity,
1551
  'description': get_pattern_description(pattern_name)
1552
  })
1553
  elif line.strip() and not line.startswith(('❗', '⚠️', 'πŸ“')) and in_patterns_section:
 
1554
  break
1555
 
1556
  # Generate personalized recommendations
 
1522
  else:
1523
  risk_level = 'low'
1524
 
1525
+ # FIXED: Extract detected patterns properly
1526
  patterns = []
1527
  in_patterns_section = False
1528
+
1529
+ # Define valid pattern names to filter against
1530
+ valid_patterns = {
1531
+ "recovery phase", "control", "gaslighting", "guilt tripping", "dismissiveness",
1532
+ "blame shifting", "nonabusive", "projection", "insults",
1533
+ "contradictory statements", "obscure language",
1534
+ "veiled threats", "stalking language", "false concern",
1535
+ "false equivalence", "future faking"
1536
+ }
1537
+
1538
  for line in lines:
1539
  if 'πŸ” Detected Patterns:' in line:
1540
  in_patterns_section = True
 
1549
  else:
1550
  continue
1551
 
1552
+ # Extract pattern text after the severity indicator
1553
+ if ':' in line:
1554
+ pattern_text = line.split(':', 1)[1].strip()
1555
+ else:
1556
+ pattern_text = line[2:].strip() # Remove emoji and space
1557
+
1558
+ # Parse individual patterns from the text
1559
+ # Handle format like "blame shifting (1x), projection (2x)"
1560
+ pattern_parts = pattern_text.split(',')
1561
 
1562
+ for part in pattern_parts:
1563
+ # Clean up the pattern name
1564
+ pattern_name = part.strip()
1565
+
1566
+ # Remove count indicators like "(1x)", "(2x)", etc.
1567
+ pattern_name = re.sub(r'\s*\(\d+x?\)', '', pattern_name)
1568
+
1569
+ # Remove any remaining special characters and clean
1570
+ pattern_name = pattern_name.strip().lower()
1571
+
1572
+ # Only add if it's a valid pattern name
1573
+ if pattern_name in valid_patterns:
1574
  patterns.append({
1575
+ 'name': pattern_name.replace('_', ' ').title(),
1576
  'severity': severity,
1577
  'description': get_pattern_description(pattern_name)
1578
  })
1579
  elif line.strip() and not line.startswith(('❗', '⚠️', 'πŸ“')) and in_patterns_section:
1580
+ # Exit patterns section when we hit a non-pattern line
1581
  break
1582
 
1583
  # Generate personalized recommendations