File size: 486 Bytes
f7934f7
 
 
 
 
 
f3be2c5
f7934f7
 
 
 
 
 
 
 
 
48367a0
73fd97f
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import asyncio
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from gradio_client import Client

app = FastAPI()
client = Client("vikhyatk/moondream2")


def get_caption(image: str, question: str):
    result = client.predict(image, question, api_name="/answer_question")
    return result.strip()


@app.post("/caption")
async def captioning(image: str, question):
    return JSONResponse({"caption": await asyncio.to_thread(get_caption, image, question)})

# yo