Leyo commited on
Commit
856c1fc
1 Parent(s): 6e59a34

catch image conversion errors

Browse files
Files changed (1) hide show
  1. 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
- if is_url(elem):
300
- try:
301
  response = requests.get(elem)
302
  if response.status_code == 200:
303
  elem_pil = Image.open(BytesIO(response.content))
304
- except Exception:
305
- print(f"Image is not loading")
306
- else:
307
- elem_pil = Image.open(elem)
308
- base64_img = pil_to_base64(elem_pil, resize=True)
309
- result_string_input += f"![]({base64_img})"
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