Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -341,22 +341,25 @@ def bot(history, temperature, top_p, max_output_tokens):
|
|
341 |
image_list.append(load_image(f))
|
342 |
else:
|
343 |
raise ValueError("Invalid image file")
|
344 |
-
|
345 |
-
image_tensor = [
|
346 |
-
our_chatbot.image_processor.preprocess(f, return_tensors="pt")["pixel_values"][
|
347 |
-
0
|
348 |
-
]
|
349 |
-
.half()
|
350 |
-
.to(our_chatbot.model.device)
|
351 |
-
for f in image_list
|
352 |
-
]
|
353 |
|
354 |
-
|
355 |
-
|
356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
|
358 |
-
|
359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
360 |
our_chatbot.conversation.append_message(our_chatbot.conversation.roles[0], inp)
|
361 |
# image = None
|
362 |
our_chatbot.conversation.append_message(our_chatbot.conversation.roles[1], None)
|
@@ -386,7 +389,7 @@ def bot(history, temperature, top_p, max_output_tokens):
|
|
386 |
generate_kwargs = dict(
|
387 |
inputs=input_ids,
|
388 |
streamer=streamer,
|
389 |
-
images=image_tensor,
|
390 |
do_sample=True,
|
391 |
temperature=temperature,
|
392 |
top_p=top_p,
|
|
|
341 |
image_list.append(load_image(f))
|
342 |
else:
|
343 |
raise ValueError("Invalid image file")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
344 |
|
345 |
+
if num_new_images > 0:
|
346 |
+
image_tensor = [
|
347 |
+
our_chatbot.image_processor.preprocess(f, return_tensors="pt")["pixel_values"][
|
348 |
+
0
|
349 |
+
]
|
350 |
+
.half()
|
351 |
+
.to(our_chatbot.model.device)
|
352 |
+
for f in image_list
|
353 |
+
]
|
354 |
|
355 |
+
|
356 |
+
image_tensor = torch.stack(image_tensor)
|
357 |
+
image_token = DEFAULT_IMAGE_TOKEN * num_new_images
|
358 |
+
|
359 |
+
inp = text
|
360 |
+
inp = image_token + "\n" + inp
|
361 |
+
else:
|
362 |
+
inp = text
|
363 |
our_chatbot.conversation.append_message(our_chatbot.conversation.roles[0], inp)
|
364 |
# image = None
|
365 |
our_chatbot.conversation.append_message(our_chatbot.conversation.roles[1], None)
|
|
|
389 |
generate_kwargs = dict(
|
390 |
inputs=input_ids,
|
391 |
streamer=streamer,
|
392 |
+
images=image_tensor if num_new_images > 0 else None,
|
393 |
do_sample=True,
|
394 |
temperature=temperature,
|
395 |
top_p=top_p,
|