File size: 766 Bytes
bef83c8
 
874fe5f
c645ae2
bef83c8
c645ae2
bef83c8
 
 
 
 
874fe5f
 
bef83c8
874fe5f
 
bef83c8
 
 
 
 
c645ae2
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)