Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
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"
|
| 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 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 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 |
|