princemaxp commited on
Commit
cc9ac5d
Β·
verified Β·
1 Parent(s): 3426ab1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -13,17 +13,16 @@ def analyze_email(file_path, export_pdf=False):
13
  if file_path is None:
14
  return "<p style='color:red;'>Please upload a .eml file to analyze.</p>", None
15
 
16
- # Updated analyzer returns summary (dict) and details (dict)
17
- summary, details = analyze(file_path)
18
 
19
- # Extract score, attack type, verdict
20
- attack_score = summary.get("Attack Score", "0")
21
- attack_type = summary.get("Attack Type", "Unknown")
22
- verdict = summary.get("Final Verdict", "Safe")
23
 
24
- # Cap score at 100
25
- score_val = int("".join(filter(str.isdigit, attack_score)))
26
- if score_val > 100:
27
  score_val = 100
28
 
29
  # Verdict color
@@ -36,11 +35,19 @@ def analyze_email(file_path, export_pdf=False):
36
  verdict_color = "#f1c40f"
37
 
38
  # Extract sections
39
- tags = details.get("Attack Analysis Tags", [])
40
- findings = details.get("Detailed Findings", [])
41
- highlighted_body = details.get("Highlighted Body", [])
 
 
 
 
42
 
43
- # HTML Report
 
 
 
 
44
  html = f"""
45
  <div style='font-family: Arial, sans-serif; padding: 20px; max-width: 800px; margin:auto;'>
46
  <h2 style="color:#2c3e50;">πŸ“§ Email Security Report</h2>
@@ -52,7 +59,7 @@ def analyze_email(file_path, export_pdf=False):
52
  </div>
53
  <p><b>Attack Type:</b> {attack_type}</p>
54
  <p><b>Final Verdict:</b> <span style="background:{verdict_color}; color:white; padding:4px 10px; border-radius:6px;">
55
- {verdict}
56
  </span></p>
57
  <details style="margin-top:15px;">
58
  <summary>πŸ”– Attack Analysis Tags ({len(tags)})</summary>
 
13
  if file_path is None:
14
  return "<p style='color:red;'>Please upload a .eml file to analyze.</p>", None
15
 
16
+ results = analyze(file_path)
 
17
 
18
+ # Extract basic verdict info
19
+ attack_score = results[0]
20
+ attack_type = results[1]
21
+ verdict = results[2]
22
 
23
+ # Correct handling of attack_score (already int)
24
+ score_val = int(attack_score)
25
+ if score_val > 100:
26
  score_val = 100
27
 
28
  # Verdict color
 
35
  verdict_color = "#f1c40f"
36
 
37
  # Extract sections
38
+ try:
39
+ tags_index = results.index("---- Attack Analysis Tags ----")
40
+ findings_index = results.index("---- Detailed Findings ----")
41
+ body_index = results.index("---- Highlighted Body ----")
42
+ except ValueError:
43
+ html = "<pre>" + "\n".join(results) + "</pre>"
44
+ return html, None
45
 
46
+ tags = results[tags_index + 1 : findings_index]
47
+ findings = results[findings_index + 1 : body_index]
48
+ highlighted_body = results[body_index + 1 :]
49
+
50
+ # HTML Report with collapsible sections
51
  html = f"""
52
  <div style='font-family: Arial, sans-serif; padding: 20px; max-width: 800px; margin:auto;'>
53
  <h2 style="color:#2c3e50;">πŸ“§ Email Security Report</h2>
 
59
  </div>
60
  <p><b>Attack Type:</b> {attack_type}</p>
61
  <p><b>Final Verdict:</b> <span style="background:{verdict_color}; color:white; padding:4px 10px; border-radius:6px;">
62
+ {verdict.replace('Final Verdict:', '').strip()}
63
  </span></p>
64
  <details style="margin-top:15px;">
65
  <summary>πŸ”– Attack Analysis Tags ({len(tags)})</summary>