princemaxp commited on
Commit
a252c82
·
verified ·
1 Parent(s): 5472827

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -16
app.py CHANGED
@@ -1,29 +1,41 @@
1
  import gradio as gr
2
- from analyze_email_main import analyze_email # Import main analysis function
 
3
 
4
- def analyze_eml_file(file):
5
  try:
6
- with open(file.name, "rb") as f:
7
- raw_email = f.read()
8
- results = analyze_email(raw_email)
 
9
 
10
- # Format results for display
11
- if isinstance(results, list):
12
- output = "\n".join([f"{r['category']}: {r['description']}" for r in results])
 
 
 
 
 
 
 
 
 
 
 
13
  else:
14
- output = str(results)
15
 
16
- return output
17
  except Exception as e:
18
  return f"❌ Error analyzing email: {e}"
19
 
20
- demo = gr.Interface(
21
- fn=analyze_eml_file,
22
- inputs=gr.File(file_types=[".eml"], label="Upload an Email (.eml)"),
23
  outputs="text",
24
- title="📧 Email Guardians - Free Email Analyzer",
25
- description="Upload a .eml file to analyze headers, body, and URLs for phishing, spam, spoofing, and malicious content."
26
  )
27
 
28
  if __name__ == "__main__":
29
- demo.launch()
 
1
  import gradio as gr
2
+ import tempfile
3
+ from analyze_email_main import analyze_email
4
 
5
+ def analyze_uploaded_email(file_obj):
6
  try:
7
+ # Write uploaded file to a temporary .eml file
8
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".eml") as tmp:
9
+ tmp.write(file_obj.read())
10
+ tmp_path = tmp.name
11
 
12
+ results = analyze_email(tmp_path)
13
+
14
+ if isinstance(results, dict):
15
+ # Format dict output nicely
16
+ output = []
17
+ for section, findings in results.items():
18
+ output.append(f"--- {section.upper()} ---")
19
+ if findings:
20
+ output.extend(findings)
21
+ else:
22
+ output.append("No issues found")
23
+ return "\n".join(output)
24
+ elif isinstance(results, list):
25
+ return "\n".join(results)
26
  else:
27
+ return str(results)
28
 
 
29
  except Exception as e:
30
  return f"❌ Error analyzing email: {e}"
31
 
32
+ iface = gr.Interface(
33
+ fn=analyze_uploaded_email,
34
+ inputs=gr.File(type="file", label="Upload .eml file"),
35
  outputs="text",
36
+ title="Email Analysis Tool",
37
+ description="Upload a .eml file to analyze headers, body, and URLs."
38
  )
39
 
40
  if __name__ == "__main__":
41
+ iface.launch()