Spaces:
Sleeping
Sleeping
| 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" | |
| 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} | |