Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,41 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
-
def
|
| 5 |
try:
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
else:
|
| 14 |
-
|
| 15 |
|
| 16 |
-
return output
|
| 17 |
except Exception as e:
|
| 18 |
return f"❌ Error analyzing email: {e}"
|
| 19 |
|
| 20 |
-
|
| 21 |
-
fn=
|
| 22 |
-
inputs=gr.File(
|
| 23 |
outputs="text",
|
| 24 |
-
title="
|
| 25 |
-
description="Upload a .eml file to analyze headers, body, and URLs
|
| 26 |
)
|
| 27 |
|
| 28 |
if __name__ == "__main__":
|
| 29 |
-
|
|
|
|
| 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()
|