princemaxp's picture
Create app.py
bef83c8 verified
raw
history blame
834 Bytes
from fastapi import FastAPI, UploadFile, File
import requests
import tempfile
app = FastAPI()
# Point this to your analyzer Space API
ANALYZER_SPACE_API = "https://princemaxp-cysecguardians.hf.space/run/predict"
@app.post("/analyze")
async def analyze_email(file: UploadFile = File(...)):
# Save uploaded file temporarily
with tempfile.NamedTemporaryFile(delete=False, suffix=".eml") as tmp:
content = await file.read()
tmp.write(content)
tmp_path = tmp.name
# Call analyzer space API
with open(tmp_path, "rb") as f:
response = requests.post(
ANALYZER_SPACE_API,
files={"data": f}
)
if response.status_code == 200:
return response.json()
else:
return {"error": "Analyzer Space not reachable", "status": response.status_code}