princemaxp commited on
Commit
874fe5f
·
verified ·
1 Parent(s): 24003d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -14
app.py CHANGED
@@ -1,26 +1,18 @@
1
  from fastapi import FastAPI, UploadFile, File
2
  import requests
3
- import tempfile
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
- # Save uploaded file temporarily
13
- with tempfile.NamedTemporaryFile(delete=False, suffix=".eml") as tmp:
14
- content = await file.read()
15
- tmp.write(content)
16
- tmp_path = tmp.name
17
 
18
- # Call analyzer space API
19
- with open(tmp_path, "rb") as f:
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()