Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -193,13 +193,19 @@ def generate_image(model_name: str, text: str, image: Image.Image,
|
|
| 193 |
|
| 194 |
images = [image.convert("RGB")]
|
| 195 |
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
inputs = processor(text=prompt, images=images, return_tensors="pt").to(device)
|
| 204 |
|
| 205 |
streamer = TextIteratorStreamer(processor, skip_prompt=True, skip_special_tokens=True)
|
|
|
|
| 193 |
|
| 194 |
images = [image.convert("RGB")]
|
| 195 |
|
| 196 |
+
# Create the prompt based on the specific model's requirements
|
| 197 |
+
if model_name == "PaddleOCR":
|
| 198 |
+
# PaddleOCR's template expects a single string with an image placeholder
|
| 199 |
+
messages = [
|
| 200 |
+
{"role": "user", "content": f"<image>\n{text}"}
|
| 201 |
+
]
|
| 202 |
+
else:
|
| 203 |
+
# Standard format for Nanonets and Dots.OCR
|
| 204 |
+
messages = [
|
| 205 |
+
{"role": "user", "content": [{"type": "image"}] + [{"type": "text", "text": text}]}
|
| 206 |
+
]
|
| 207 |
+
|
| 208 |
+
prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 209 |
inputs = processor(text=prompt, images=images, return_tensors="pt").to(device)
|
| 210 |
|
| 211 |
streamer = TextIteratorStreamer(processor, skip_prompt=True, skip_special_tokens=True)
|