Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,18 @@
|
|
| 1 |
from fastapi import FastAPI, UploadFile, File
|
| 2 |
import requests
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
app = FastAPI()
|
| 6 |
|
| 7 |
-
# Point this to your analyzer Space API
|
| 8 |
ANALYZER_SPACE_API = "https://princemaxp-cysecguardians.hf.space/run/predict"
|
| 9 |
|
| 10 |
@app.post("/analyze")
|
| 11 |
async def analyze_email(file: UploadFile = File(...)):
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
content = await file.read()
|
| 15 |
-
tmp.write(content)
|
| 16 |
-
tmp_path = tmp.name
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
response = requests.post(
|
| 21 |
-
ANALYZER_SPACE_API,
|
| 22 |
-
files={"data": f}
|
| 23 |
-
)
|
| 24 |
|
| 25 |
if response.status_code == 200:
|
| 26 |
return response.json()
|
|
|
|
| 1 |
from fastapi import FastAPI, UploadFile, File
|
| 2 |
import requests
|
| 3 |
+
import base64
|
| 4 |
|
| 5 |
+
app = FastAPI() # 👈 this is what Hugging Face looks for
|
| 6 |
|
|
|
|
| 7 |
ANALYZER_SPACE_API = "https://princemaxp-cysecguardians.hf.space/run/predict"
|
| 8 |
|
| 9 |
@app.post("/analyze")
|
| 10 |
async def analyze_email(file: UploadFile = File(...)):
|
| 11 |
+
file_bytes = await file.read()
|
| 12 |
+
b64_file = base64.b64encode(file_bytes).decode("utf-8")
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
payload = {"data": [b64_file]}
|
| 15 |
+
response = requests.post(ANALYZER_SPACE_API, json=payload)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
if response.status_code == 200:
|
| 18 |
return response.json()
|