| 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} | |