CU2 / scripts /vision_api.py
Fred808's picture
Upload 12 files
ba74f1a verified
raw
history blame contribute delete
488 Bytes
import os
from fastapi import FastAPI, File, UploadFile, Form
from scripts.blip2_infer import describe_image
import shutil
app = FastAPI()
@app.post("/vision")
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}