Download scripts/vision_api.py from Fred808/CU1: direct link, hf CLI and curl.
- Browser
- Download file 488 Bytes
-
https://huggingface.co/spaces/Fred808/CU1/resolve/main/scripts/vision_api.py
- Command line
-
hf download hf://spaces/Fred808/CU1/scripts/vision_api.py
-
curl -L -o vision_api.py https://huggingface.co/spaces/Fred808/CU1/resolve/main/scripts/vision_api.py
488 Bytes
| import os | |
| from fastapi import FastAPI, File, UploadFile, Form | |
| from scripts.blip2_infer import describe_image | |
| import shutil | |
| app = FastAPI() | |
| async def process_vision(image: UploadFile = File(...), prompt: str = Form("Describe this image.")): | |
| temp_path = "frame.jpg" | |
| with open(temp_path, "wb") as f: | |
| shutil.copyfileobj(image.file, f) | |
| desc = describe_image(temp_path, prompt) | |
| os.remove(temp_path) | |
| return {"description": desc} | |