princemaxp commited on
Commit
e09248b
·
verified ·
1 Parent(s): c731f7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -26
app.py CHANGED
@@ -15,22 +15,17 @@ def analyze_email(file_path, export_pdf=False):
15
 
16
  results = analyze(file_path)
17
 
18
- # Ensure results has at least 3 elements
19
- if len(results) < 3:
20
- html = "<pre>" + "\n".join(results) + "</pre>"
21
- return html, None
22
 
23
- # Extract basic verdict info safely
24
- attack_score = results[0] if len(results) > 0 else 0
25
- attack_type = results[1] if len(results) > 1 else "Unknown"
26
- verdict = results[2] if len(results) > 2 else "Safe"
27
 
28
  # Correct handling of attack_score
29
- try:
30
- score_val = int(attack_score)
31
- except:
32
- score_val = 0
33
- if score_val > 100:
34
  score_val = 100
35
 
36
  # Verdict color
@@ -43,21 +38,19 @@ def analyze_email(file_path, export_pdf=False):
43
  verdict_color = "#f1c40f"
44
 
45
  # Extract sections safely
46
- tags, findings, highlighted_body = [], [], []
47
  try:
48
- tags_index = results.index("---- Attack Analysis Tags ----")
49
- findings_index = results.index("---- Detailed Findings ----")
50
- body_index = results.index("---- Highlighted Body ----")
51
- tags = results[tags_index + 1 : findings_index]
52
- findings = results[findings_index + 1 : body_index]
53
- highlighted_body = results[body_index + 1 :]
54
  except ValueError:
55
- # Sections not found, fallback to full report
56
- html = "<pre>" + "\n".join(results) + "</pre>"
57
- pdf_path = html_to_pdf(html) if export_pdf else None
58
- return html, pdf_path
59
 
60
- # HTML Report with collapsible sections
 
 
 
 
61
  html = f"""
62
  <div style='font-family: Arial, sans-serif; padding: 20px; max-width: 800px; margin:auto;'>
63
  <h2 style="color:#2c3e50;">📧 Email Security Report</h2>
@@ -92,7 +85,10 @@ def analyze_email(file_path, export_pdf=False):
92
  </div>
93
  """
94
 
95
- pdf_path = html_to_pdf(html) if export_pdf else None
 
 
 
96
  return html, pdf_path
97
 
98
  # Gradio Interface
 
15
 
16
  results = analyze(file_path)
17
 
18
+ # Ensure all items are strings
19
+ results_str = [str(r) for r in results]
 
 
20
 
21
+ # Extract basic verdict info
22
+ attack_score = results_str[0]
23
+ attack_type = results_str[1]
24
+ verdict = results_str[2]
25
 
26
  # Correct handling of attack_score
27
+ score_val = int(attack_score)
28
+ if score_val > 100:
 
 
 
29
  score_val = 100
30
 
31
  # Verdict color
 
38
  verdict_color = "#f1c40f"
39
 
40
  # Extract sections safely
 
41
  try:
42
+ tags_index = results_str.index("---- Attack Analysis Tags ----")
43
+ findings_index = results_str.index("---- Detailed Findings ----")
44
+ body_index = results_str.index("---- Highlighted Body ----")
 
 
 
45
  except ValueError:
46
+ html = "<pre>" + "\n".join(results_str) + "</pre>"
47
+ return html, None
 
 
48
 
49
+ tags = results_str[tags_index + 1 : findings_index]
50
+ findings = results_str[findings_index + 1 : body_index]
51
+ highlighted_body = results_str[body_index + 1 :]
52
+
53
+ # HTML Report
54
  html = f"""
55
  <div style='font-family: Arial, sans-serif; padding: 20px; max-width: 800px; margin:auto;'>
56
  <h2 style="color:#2c3e50;">📧 Email Security Report</h2>
 
85
  </div>
86
  """
87
 
88
+ pdf_path = None
89
+ if export_pdf:
90
+ pdf_path = html_to_pdf(html)
91
+
92
  return html, pdf_path
93
 
94
  # Gradio Interface