Leyo commited on
Commit
42e4a55
1 Parent(s): 055c2f1

better handle exceptions

Browse files
Files changed (1) hide show
  1. app_dialogue.py +8 -3
app_dialogue.py CHANGED
@@ -803,8 +803,11 @@ with gr.Blocks(title="AI Meme Generator", theme=gr.themes.Base(), css=css) as de
803
  text_at_the_top,
804
  generation_args,
805
  ):
806
- time.sleep(random.uniform(0, 1))
807
- text = client.generate(prompt=query, **generation_args).generated_text
 
 
 
808
  if image is not None and text != "":
809
  meme_image = make_meme_image(
810
  image=image,
@@ -814,6 +817,8 @@ with gr.Blocks(title="AI Meme Generator", theme=gr.themes.Base(), css=css) as de
814
  text_at_the_top=text_at_the_top,
815
  )
816
  return meme_image
 
 
817
 
818
  def model_inference(
819
  model_selector,
@@ -904,7 +909,7 @@ with gr.Blocks(title="AI Meme Generator", theme=gr.themes.Base(), css=css) as de
904
  ]
905
 
906
  for future in concurrent.futures.as_completed(futures):
907
- meme_image = future.result()
908
  if meme_image:
909
  all_meme_images.append(meme_image)
910
  return user_prompt_str, all_meme_images, chat_history
 
803
  text_at_the_top,
804
  generation_args,
805
  ):
806
+ try:
807
+ text = client.generate(prompt=query, **generation_args).generated_text
808
+ except Exception as e:
809
+ logger.error(f"Error {e} while generating meme text")
810
+ text = ""
811
  if image is not None and text != "":
812
  meme_image = make_meme_image(
813
  image=image,
 
817
  text_at_the_top=text_at_the_top,
818
  )
819
  return meme_image
820
+ else:
821
+ return None
822
 
823
  def model_inference(
824
  model_selector,
 
909
  ]
910
 
911
  for future in concurrent.futures.as_completed(futures):
912
+ meme_image = future.result(timeout=45)
913
  if meme_image:
914
  all_meme_images.append(meme_image)
915
  return user_prompt_str, all_meme_images, chat_history