Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from analyze_email_main import analyze
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
def analyze_email(file_obj):
|
| 5 |
if file_obj is None:
|
| 6 |
-
return "<p style='color:red;'>Please upload a .eml file to analyze.</p>"
|
| 7 |
|
| 8 |
results = analyze(file_obj.name)
|
| 9 |
|
|
@@ -32,7 +35,8 @@ def analyze_email(file_obj):
|
|
| 32 |
findings_index = results.index("---- Detailed Findings ----")
|
| 33 |
body_index = results.index("---- Highlighted Body ----")
|
| 34 |
except ValueError:
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
tags = results[tags_index + 1 : findings_index]
|
| 38 |
findings = results[findings_index + 1 : body_index]
|
|
@@ -53,7 +57,7 @@ def analyze_email(file_obj):
|
|
| 53 |
|
| 54 |
<p><b>Attack Type:</b> {attack_type}</p>
|
| 55 |
<p><b>Final Verdict:</b> <span style="background:{verdict_color}; color:white; padding:4px 10px; border-radius:6px;">
|
| 56 |
-
{verdict.replace(
|
| 57 |
</span></p>
|
| 58 |
|
| 59 |
<h3>π Attack Analysis Tags</h3>
|
|
@@ -74,16 +78,29 @@ def analyze_email(file_obj):
|
|
| 74 |
</div>
|
| 75 |
"""
|
| 76 |
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
# Gradio Interface
|
| 80 |
demo = gr.Interface(
|
| 81 |
fn=analyze_email,
|
| 82 |
-
inputs=
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
title="π§ Email Security Analyzer",
|
| 85 |
description="Upload an .eml file to detect phishing, spam, or malicious emails. "
|
| 86 |
-
"
|
| 87 |
)
|
| 88 |
|
| 89 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from analyze_email_main import analyze
|
| 3 |
+
import pdfkit
|
| 4 |
+
import tempfile
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
+
def analyze_email(file_obj, export_pdf=False):
|
| 8 |
if file_obj is None:
|
| 9 |
+
return "<p style='color:red;'>Please upload a .eml file to analyze.</p>", None
|
| 10 |
|
| 11 |
results = analyze(file_obj.name)
|
| 12 |
|
|
|
|
| 35 |
findings_index = results.index("---- Detailed Findings ----")
|
| 36 |
body_index = results.index("---- Highlighted Body ----")
|
| 37 |
except ValueError:
|
| 38 |
+
html = "<pre>" + "\n".join(results) + "</pre>"
|
| 39 |
+
return html, None
|
| 40 |
|
| 41 |
tags = results[tags_index + 1 : findings_index]
|
| 42 |
findings = results[findings_index + 1 : body_index]
|
|
|
|
| 57 |
|
| 58 |
<p><b>Attack Type:</b> {attack_type}</p>
|
| 59 |
<p><b>Final Verdict:</b> <span style="background:{verdict_color}; color:white; padding:4px 10px; border-radius:6px;">
|
| 60 |
+
{verdict.replace('Final Verdict:', '').strip()}
|
| 61 |
</span></p>
|
| 62 |
|
| 63 |
<h3>π Attack Analysis Tags</h3>
|
|
|
|
| 78 |
</div>
|
| 79 |
"""
|
| 80 |
|
| 81 |
+
pdf_path = None
|
| 82 |
+
if export_pdf:
|
| 83 |
+
# Generate temporary PDF file
|
| 84 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_pdf:
|
| 85 |
+
pdf_path = tmp_pdf.name
|
| 86 |
+
pdfkit.from_string(html, pdf_path)
|
| 87 |
+
|
| 88 |
+
return html, pdf_path
|
| 89 |
|
| 90 |
# Gradio Interface
|
| 91 |
demo = gr.Interface(
|
| 92 |
fn=analyze_email,
|
| 93 |
+
inputs=[
|
| 94 |
+
gr.File(label="Upload .eml File", type="file"),
|
| 95 |
+
gr.Checkbox(label="Export PDF Report")
|
| 96 |
+
],
|
| 97 |
+
outputs=[
|
| 98 |
+
gr.HTML(label="Analysis Report"),
|
| 99 |
+
gr.File(label="Download PDF Report")
|
| 100 |
+
],
|
| 101 |
title="π§ Email Security Analyzer",
|
| 102 |
description="Upload an .eml file to detect phishing, spam, or malicious emails. "
|
| 103 |
+
"Check 'Export PDF Report' to download a professional PDF report."
|
| 104 |
)
|
| 105 |
|
| 106 |
if __name__ == "__main__":
|