Spaces:
Sleeping
Sleeping
Download api.py from PRUTHVIn/vqa_project: direct link, hf CLI and curl.
- Browser
- Download file 594 Bytes
-
https://huggingface.co/spaces/PRUTHVIn/vqa_project/resolve/main/api.py
- Command line
-
hf download hf://spaces/PRUTHVIn/vqa_project/api.py
-
curl -L -o api.py https://huggingface.co/spaces/PRUTHVIn/vqa_project/resolve/main/api.py
594 Bytes
| from fastapi import FastAPI, File, UploadFile, Form | |
| from inference import predict | |
| import shutil | |
| import os | |
| app = FastAPI() | |
| UPLOAD_DIR = "temp" | |
| os.makedirs(UPLOAD_DIR, exist_ok=True) | |
| async def predict_api(file: UploadFile = File(...), question: str = Form(...)): | |
| try: | |
| file_path = os.path.join(UPLOAD_DIR, file.filename) | |
| with open(file_path, "wb") as buffer: | |
| shutil.copyfileobj(file.file, buffer) | |
| answer = predict(file_path, question) | |
| return {"answer": answer} | |
| except Exception as e: | |
| return {"error": str(e)} |