File size: 1,036 Bytes
ef5ce50
655ba26
ef5ce50
 
 
 
655ba26
 
ef5ce50
 
 
 
 
 
 
 
83e9d74
ef5ce50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from typing import Any, Dict, List

from transformers import AutoModel, AutoTokenizer, pipeline


class EndpointHandler:
    def __init__(self, path=""):

        # Load the pipeline for the model
        model = AutoModel.from_pretrained(
            "openbmb/MiniCPM-Llama3-V-2_5-int4",
            trust_remote_code=True,
        )
        tokenizer = AutoTokenizer.from_pretrained(
            "openbmb/MiniCPM-Llama3-V-2_5-int4", trust_remote_code=True
        )
        self.pipeline = pipeline(model=model, tokenizer=tokenizer)

    def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:
        # Get the image and question from the request
        image = data.get("image")
        question = data.get("question")

        # Perform the VQA
        return self.pipeline(image, question)


# if __name__ == "__main__":
#     handler = EndpointHandler()
#     data = {
#         "image": "https://pwm.im-cdn.it/image/1524723057/xxl.jpg",
#         "question": "Describe the image:",
#     }
#     print(handler(data))