MCPcopy Create free account
hub / github.com/OpenBMB/MiniCPM-V / MiniCPMV

Class MiniCPMV

chat.py:139–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137 return encoded_string
138
139class MiniCPMV:
140 def __init__(self, model_path) -> None:
141 self.model = AutoModel.from_pretrained(model_path, trust_remote_code=True).to(dtype=torch.bfloat16)
142 self.tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
143 self.model.eval().cuda()
144
145 def chat(self, input):
146 try:
147 image = Image.open(io.BytesIO(base64.b64decode(input['image']))).convert('RGB')
148 except Exception as e:
149 return "Image decode error"
150
151 msgs = json.loads(input['question'])
152
153 answer, context, _ = self.model.chat(
154 image=image,
155 msgs=msgs,
156 context=None,
157 tokenizer=self.tokenizer,
158 sampling=True,
159 temperature=0.7
160 )
161 return answer
162
163class MiniCPMV2_5:
164 def __init__(self, model_path) -> None:

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected