Browse Source

make vlm generate on text and not on image

tags/v0.3.7rc0
haixuanTao 1 year ago
parent
commit
215331e574
1 changed files with 15 additions and 13 deletions
  1. +15
    -13
      node-hub/dora-internvl/dora_internvl/main.py

+ 15
- 13
node-hub/dora-internvl/dora_internvl/main.py View File

@@ -121,6 +121,7 @@ def main():
node = Node()

question = "<image>\nPlease describe the image shortly."
frame = None
pa.array([]) # initialize pyarrow array

for event in node:
@@ -157,21 +158,22 @@ def main():
else:
raise RuntimeError(f"Unsupported image encoding: {encoding}")

# set the max number of tiles in `max_num`
pixel_values = load_image(frame, max_num=12).to(torch.bfloat16).cuda()
generation_config = dict(max_new_tokens=1024, do_sample=True)
response = model.chat(
tokenizer, pixel_values, question, generation_config
)

node.send_output(
"text",
pa.array([response]),
metadata,
)

elif event_id == "text":
question = "<image>\n" + event["value"][0].as_py()
if frame is not None:
# set the max number of tiles in `max_num`
pixel_values = (
load_image(frame, max_num=12).to(torch.bfloat16).cuda()
)
generation_config = dict(max_new_tokens=1024, do_sample=True)
response = model.chat(
tokenizer, pixel_values, question, generation_config
)
node.send_output(
"text",
pa.array([response]),
metadata,
)

elif event_type == "ERROR":
raise RuntimeError(event["error"])


Loading…
Cancel
Save