File size: 1,174 Bytes
a432813
 
 
 
 
 
 
 
2c0cf70
 
 
 
62d5438
a432813
 
 
7d7e1ad
 
 
 
a432813
 
 
 
 
7d7e1ad
 
 
 
 
a432813
 
 
 
 
 
7d7e1ad
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
27
28
29
30
31
32
33
34
35
36
37
38
from fastapi import FastAPI, File, UploadFile, HTTPException
from fastapi.responses import JSONResponse
import shutil
import os
from models.feature_extractor import extract_features

app = FastAPI()

@app.get("/")
def root():
    return {"message": "Feature extraction API is running!"}

@app.post("/extractfacialfeatures")
async def extract_features_endpoint(file: UploadFile = File(...)):
    if not file:
        raise HTTPException(status_code=400, detail="No file provided")
    
    # Log file info
    print(f"Received file: {file.filename}, Content-Type: {file.content_type}")

    # Save the uploaded file temporarily
    os.makedirs("temp", exist_ok=True)
    file_location = f"temp/{file.filename}"
    with open(file_location, "wb") as buffer:
        shutil.copyfileobj(file.file, buffer)
    
    # Optionally log file size
    file_size = os.path.getsize(file_location)
    print(f"Saved file size: {file_size} bytes")

    try:
        features = extract_features(file_location)
        return JSONResponse(content=features)
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))
    finally:
        os.remove(file_location)