prithivMLmods commited on
Commit
0348aed
·
verified ·
1 Parent(s): 29cda59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -153,7 +153,7 @@ model_d = AutoModelForCausalLM.from_pretrained(
153
  trust_remote_code=True
154
  ).eval()
155
 
156
- MODEL_ID_P = "strangervisionhf/paddle" #-> https://huggingface.co/PaddlePaddle/PaddleOCR-VL
157
  processor_p = AutoProcessor.from_pretrained(MODEL_ID_P, trust_remote_code=True)
158
  model_p = AutoModelForCausalLM.from_pretrained(
159
  MODEL_ID_P,
@@ -186,12 +186,21 @@ def generate_image(model_name: str, text: str, image: Image.Image,
186
 
187
  images = [image.convert("RGB")]
188
 
189
- messages = [
190
- {
191
- "role": "user",
192
- "content": [{"type": "image"}] + [{"type": "text", "text": text}]
193
- }
194
- ]
 
 
 
 
 
 
 
 
 
195
  prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
196
  inputs = processor(text=prompt, images=images, return_tensors="pt").to(device)
197
 
 
153
  trust_remote_code=True
154
  ).eval()
155
 
156
+ MODEL_ID_P = "strangervisionhf/paddle"
157
  processor_p = AutoProcessor.from_pretrained(MODEL_ID_P, trust_remote_code=True)
158
  model_p = AutoModelForCausalLM.from_pretrained(
159
  MODEL_ID_P,
 
186
 
187
  images = [image.convert("RGB")]
188
 
189
+ # --- ERROR FIX ---
190
+ # PaddleOCR's processor expects a different message format than the others.
191
+ # Its chat template expects the 'content' to be a simple string, not a list.
192
+ if model_name == "PaddleOCR":
193
+ messages = [
194
+ {"role": "user", "content": text}
195
+ ]
196
+ else:
197
+ messages = [
198
+ {
199
+ "role": "user",
200
+ "content": [{"type": "image"}] + [{"type": "text", "text": text}]
201
+ }
202
+ ]
203
+
204
  prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
205
  inputs = processor(text=prompt, images=images, return_tensors="pt").to(device)
206