Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, File
|
| 2 |
+
import requests
|
| 3 |
+
import tempfile
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
# Point this to your analyzer Space API
|
| 8 |
+
ANALYZER_SPACE_API = "https://princemaxp-cysecguardians.hf.space/run/predict"
|
| 9 |
+
|
| 10 |
+
@app.post("/analyze")
|
| 11 |
+
async def analyze_email(file: UploadFile = File(...)):
|
| 12 |
+
# Save uploaded file temporarily
|
| 13 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".eml") as tmp:
|
| 14 |
+
content = await file.read()
|
| 15 |
+
tmp.write(content)
|
| 16 |
+
tmp_path = tmp.name
|
| 17 |
+
|
| 18 |
+
# Call analyzer space API
|
| 19 |
+
with open(tmp_path, "rb") as f:
|
| 20 |
+
response = requests.post(
|
| 21 |
+
ANALYZER_SPACE_API,
|
| 22 |
+
files={"data": f}
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
if response.status_code == 200:
|
| 26 |
+
return response.json()
|
| 27 |
+
else:
|
| 28 |
+
return {"error": "Analyzer Space not reachable", "status": response.status_code}
|