Spaces:
Sleeping
Sleeping
Download app.py from kabeerahmad/Feature_Extraction: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/kabeerahmad/Feature_Extraction/resolve/main/app.py
- Command line
-
hf download hf://spaces/kabeerahmad/Feature_Extraction/app.py
-
curl -L -o app.py https://huggingface.co/spaces/kabeerahmad/Feature_Extraction/resolve/main/app.py
1.17 kB
| 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() | |
| def root(): | |
| return {"message": "Feature extraction API is running!"} | |
| 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) | |