Spaces:
Running
Running
catch image conversion errors
Browse files- app_dialogue.py +8 -8
app_dialogue.py
CHANGED
@@ -296,17 +296,17 @@ def prompt_list_to_tgi_input(prompt_list: List[str]) -> str:
|
|
296 |
result_string_input = ""
|
297 |
for elem in prompt_list:
|
298 |
if is_image(elem):
|
299 |
-
|
300 |
-
|
301 |
response = requests.get(elem)
|
302 |
if response.status_code == 200:
|
303 |
elem_pil = Image.open(BytesIO(response.content))
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
else:
|
311 |
result_string_input += elem
|
312 |
return result_string_input
|
|
|
296 |
result_string_input = ""
|
297 |
for elem in prompt_list:
|
298 |
if is_image(elem):
|
299 |
+
try:
|
300 |
+
if is_url(elem):
|
301 |
response = requests.get(elem)
|
302 |
if response.status_code == 200:
|
303 |
elem_pil = Image.open(BytesIO(response.content))
|
304 |
+
else:
|
305 |
+
elem_pil = Image.open(elem)
|
306 |
+
base64_img = pil_to_base64(elem_pil, resize=True)
|
307 |
+
result_string_input += f"![]({base64_img})"
|
308 |
+
except Exception as e:
|
309 |
+
print(f"Image can't be loaded because of exception {e}")
|
310 |
else:
|
311 |
result_string_input += elem
|
312 |
return result_string_input
|