| 161 | return answer |
| 162 | |
| 163 | class 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 | |
| 186 | class MiniCPMV2_6: |
| 187 | def __init__(self, model_path, multi_gpus=False) -> None: |