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

Class MiniCPMV2_5

chat.py:163–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161 return answer
162
163class MiniCPMV2_5:
164 def __init__(self, model_path) -> None:
165 self.model = AutoModel.from_pretrained(model_path, trust_remote_code=True).to(dtype=torch.float16)
166 self.tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
167 self.model.eval().cuda()
168
169 def chat(self, input):
170 try:
171 image = Image.open(io.BytesIO(base64.b64decode(input['image']))).convert('RGB')
172 except Exception as e:
173 return "Image decode error"
174
175 msgs = json.loads(input['question'])
176
177 answer = self.model.chat(
178 image=image,
179 msgs=msgs,
180 tokenizer=self.tokenizer,
181 sampling=True,
182 temperature=0.7
183 )
184 return answer
185
186class MiniCPMV2_6:
187 def __init__(self, model_path, multi_gpus=False) -> None:

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected