Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI, UploadFile, File | |
| import requests | |
| import base64 | |
| import uvicorn | |
| app = FastAPI() | |
| ANALYZER_SPACE_API = "https://princemaxp-cysecguardians.hf.space/run/predict" | |
| async def analyze_email(file: UploadFile = File(...)): | |
| file_bytes = await file.read() | |
| b64_file = base64.b64encode(file_bytes).decode("utf-8") | |
| payload = {"data": [b64_file]} | |
| response = requests.post(ANALYZER_SPACE_API, json=payload) | |
| if response.status_code == 200: | |
| return response.json() | |
| else: | |
| return {"error": "Analyzer Space not reachable", "status": response.status_code} | |
| # π Trick to make Hugging Face accept FastAPI in Gradio mode | |
| if __name__ == "__main__": | |
| uvicorn.run(app, host="0.0.0.0", port=7860) | |