princemaxp's picture
Rename main.py to app.py
c645ae2 verified
raw
history blame contribute delete
766 Bytes
from fastapi import FastAPI, UploadFile, File
import requests
import base64
import uvicorn
app = FastAPI()
ANALYZER_SPACE_API = "https://princemaxp-cysecguardians.hf.space/run/predict"
@app.post("/analyze")
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)