Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -109,6 +109,10 @@ def vqa(image, question, max_new_tokens=256):
|
|
| 109 |
model, processor, image_paths=[path], question=question.strip(),
|
| 110 |
device=DEVICE, dtype=DTYPE, max_new_tokens=int(max_new_tokens),
|
| 111 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
return text.strip()
|
| 113 |
|
| 114 |
|
|
@@ -197,7 +201,15 @@ def embodied_plan(image, task, num_frames=3, num_steps=50, height=144, width=256
|
|
| 197 |
pil.save(frame_f.name)
|
| 198 |
prior_steps.append((text, frame_f.name))
|
| 199 |
gallery.append((pil, f"Step {k + 1}"))
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
yield gallery, "\n\n".join(plan_md_lines)
|
| 202 |
|
| 203 |
|
|
|
|
| 109 |
model, processor, image_paths=[path], question=question.strip(),
|
| 110 |
device=DEVICE, dtype=DTYPE, max_new_tokens=int(max_new_tokens),
|
| 111 |
)
|
| 112 |
+
# The model wraps answers in <answer>...</answer>; strip the tags for display.
|
| 113 |
+
text = text.strip()
|
| 114 |
+
for tag in ("<answer>", "</answer>"):
|
| 115 |
+
text = text.replace(tag, "")
|
| 116 |
return text.strip()
|
| 117 |
|
| 118 |
|
|
|
|
| 201 |
pil.save(frame_f.name)
|
| 202 |
prior_steps.append((text, frame_f.name))
|
| 203 |
gallery.append((pil, f"Step {k + 1}"))
|
| 204 |
+
# Tidy the emitted text: drop any wrapper tags and a leading "Step N:"
|
| 205 |
+
# the model may already produce (we add our own numbered heading).
|
| 206 |
+
disp = text.strip()
|
| 207 |
+
for tag in ("<answer>", "</answer>"):
|
| 208 |
+
disp = disp.replace(tag, "")
|
| 209 |
+
disp = disp.strip()
|
| 210 |
+
if disp.lower().startswith(f"step {k + 1}:"):
|
| 211 |
+
disp = disp[len(f"step {k + 1}:"):].strip()
|
| 212 |
+
plan_md_lines.append(f"**Step {k + 1}:** {disp or '(imagined goal frame only)'}")
|
| 213 |
yield gallery, "\n\n".join(plan_md_lines)
|
| 214 |
|
| 215 |
|