Spaces:
Paused
Paused
modified: app.py
Browse files
app.py
CHANGED
@@ -16,7 +16,7 @@ import torch
|
|
16 |
from threading import Thread
|
17 |
from typing import List, Dict, Union
|
18 |
import urllib
|
19 |
-
|
20 |
import io
|
21 |
import datasets
|
22 |
|
@@ -227,12 +227,12 @@ def load_image_from_url(url):
|
|
227 |
with urllib.request.urlopen(url) as response:
|
228 |
image_data = response.read()
|
229 |
image_stream = io.BytesIO(image_data)
|
230 |
-
image = Image.open(image_stream)
|
231 |
return image
|
232 |
|
233 |
|
234 |
def img_to_bytes(image_path):
|
235 |
-
image = Image.open(image_path).convert(mode='RGB')
|
236 |
buffer = io.BytesIO()
|
237 |
image.save(buffer, format="JPEG")
|
238 |
img_bytes = buffer.getvalue()
|
@@ -270,7 +270,7 @@ def format_user_prompt_with_im_history_and_system_conditioning(
|
|
270 |
if turn_is_pure_media(turn):
|
271 |
media = turn[0][0]
|
272 |
resulting_messages[-1]["content"].append({"type": "image"})
|
273 |
-
resulting_images.append(Image.open(media))
|
274 |
else:
|
275 |
user_utterance, assistant_utterance = turn
|
276 |
resulting_messages[-1]["content"].append(
|
@@ -300,7 +300,7 @@ def format_user_prompt_with_im_history_and_system_conditioning(
|
|
300 |
+ [{"type": "text", "text": user_prompt["text"]}],
|
301 |
}
|
302 |
)
|
303 |
-
resulting_images.extend([Image.open(path) for path in user_prompt["files"]])
|
304 |
|
305 |
return resulting_messages, resulting_images
|
306 |
|
|
|
16 |
from threading import Thread
|
17 |
from typing import List, Dict, Union
|
18 |
import urllib
|
19 |
+
import PIL.Image
|
20 |
import io
|
21 |
import datasets
|
22 |
|
|
|
227 |
with urllib.request.urlopen(url) as response:
|
228 |
image_data = response.read()
|
229 |
image_stream = io.BytesIO(image_data)
|
230 |
+
image = PIL.Image.open(image_stream)
|
231 |
return image
|
232 |
|
233 |
|
234 |
def img_to_bytes(image_path):
|
235 |
+
image = PIL.Image.open(image_path).convert(mode='RGB')
|
236 |
buffer = io.BytesIO()
|
237 |
image.save(buffer, format="JPEG")
|
238 |
img_bytes = buffer.getvalue()
|
|
|
270 |
if turn_is_pure_media(turn):
|
271 |
media = turn[0][0]
|
272 |
resulting_messages[-1]["content"].append({"type": "image"})
|
273 |
+
resulting_images.append(PIL.Image.open(media))
|
274 |
else:
|
275 |
user_utterance, assistant_utterance = turn
|
276 |
resulting_messages[-1]["content"].append(
|
|
|
300 |
+ [{"type": "text", "text": user_prompt["text"]}],
|
301 |
}
|
302 |
)
|
303 |
+
resulting_images.extend([PIL.Image.open(path) for path in user_prompt["files"]])
|
304 |
|
305 |
return resulting_messages, resulting_images
|
306 |
|