Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,6 +39,10 @@ from PIL import Image
|
|
| 39 |
from io import BytesIO
|
| 40 |
from transformers import TextStreamer, TextIteratorStreamer
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
import gradio as gr
|
| 43 |
import gradio_client
|
| 44 |
import subprocess
|
|
@@ -226,25 +230,9 @@ def bot(history):
|
|
| 226 |
assert len(images_this_term) > 0, "must have an image"
|
| 227 |
# image_files = (args.image_file).split(',')
|
| 228 |
# image = [load_image(f) for f in images_this_term if f]
|
| 229 |
-
|
| 230 |
-
for f in images_this_term:
|
| 231 |
-
if is_valid_video_filename(f):
|
| 232 |
-
image_list += sample_frames(f, our_chatbot.num_frames)
|
| 233 |
-
elif is_valid_image_filename(f):
|
| 234 |
-
image_list.append(load_image(f))
|
| 235 |
-
else:
|
| 236 |
-
raise ValueError("Invalid image file")
|
| 237 |
-
|
| 238 |
-
image_tensor = [
|
| 239 |
-
our_chatbot.image_processor.preprocess(f, return_tensors="pt")["pixel_values"][
|
| 240 |
-
0
|
| 241 |
-
]
|
| 242 |
-
.half()
|
| 243 |
-
.to(our_chatbot.model.device)
|
| 244 |
-
for f in image_list
|
| 245 |
-
]
|
| 246 |
all_image_hash = []
|
| 247 |
-
for image_path in
|
| 248 |
with open(image_path, "rb") as image_file:
|
| 249 |
image_data = image_file.read()
|
| 250 |
image_hash = hashlib.md5(image_data).hexdigest()
|
|
@@ -261,6 +249,25 @@ def bot(history):
|
|
| 261 |
if not os.path.isfile(filename):
|
| 262 |
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
| 263 |
image.save(filename)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
image_tensor = torch.stack(image_tensor)
|
| 266 |
image_token = DEFAULT_IMAGE_TOKEN * num_new_images
|
|
|
|
| 39 |
from io import BytesIO
|
| 40 |
from transformers import TextStreamer, TextIteratorStreamer
|
| 41 |
|
| 42 |
+
import hashlib
|
| 43 |
+
import PIL
|
| 44 |
+
import base64
|
| 45 |
+
|
| 46 |
import gradio as gr
|
| 47 |
import gradio_client
|
| 48 |
import subprocess
|
|
|
|
| 230 |
assert len(images_this_term) > 0, "must have an image"
|
| 231 |
# image_files = (args.image_file).split(',')
|
| 232 |
# image = [load_image(f) for f in images_this_term if f]
|
| 233 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
all_image_hash = []
|
| 235 |
+
for image_path in images_this_term:
|
| 236 |
with open(image_path, "rb") as image_file:
|
| 237 |
image_data = image_file.read()
|
| 238 |
image_hash = hashlib.md5(image_data).hexdigest()
|
|
|
|
| 249 |
if not os.path.isfile(filename):
|
| 250 |
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
| 251 |
image.save(filename)
|
| 252 |
+
|
| 253 |
+
image_list = []
|
| 254 |
+
for f in images_this_term:
|
| 255 |
+
if is_valid_video_filename(f):
|
| 256 |
+
image_list += sample_frames(f, our_chatbot.num_frames)
|
| 257 |
+
elif is_valid_image_filename(f):
|
| 258 |
+
image_list.append(load_image(f))
|
| 259 |
+
else:
|
| 260 |
+
raise ValueError("Invalid image file")
|
| 261 |
+
|
| 262 |
+
image_tensor = [
|
| 263 |
+
our_chatbot.image_processor.preprocess(f, return_tensors="pt")["pixel_values"][
|
| 264 |
+
0
|
| 265 |
+
]
|
| 266 |
+
.half()
|
| 267 |
+
.to(our_chatbot.model.device)
|
| 268 |
+
for f in image_list
|
| 269 |
+
]
|
| 270 |
+
|
| 271 |
|
| 272 |
image_tensor = torch.stack(image_tensor)
|
| 273 |
image_token = DEFAULT_IMAGE_TOKEN * num_new_images
|