Leyo commited on
Commit
f487d9c
1 Parent(s): d1f0943

update multiprocessing handling + concurency count

Browse files
Files changed (1) hide show
  1. app_dialogue.py +12 -17
app_dialogue.py CHANGED
@@ -634,24 +634,19 @@ def model_inference(
634
  query = prompt_list_to_tgi_input(formated_prompt_list)
635
  all_meme_images = []
636
  with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
637
- futures = [
638
- executor.submit(
639
  generate_meme,
640
- client,
641
- query,
642
- image,
643
- font_meme_text,
644
- all_caps_meme_text,
645
- text_at_the_top,
646
- generation_args,
647
  )
648
- for i in range(4)
649
- ]
650
-
651
- for future in concurrent.futures.as_completed(futures):
652
- meme_image = future.result(timeout=45)
653
- if meme_image:
654
- all_meme_images.append(meme_image)
655
  return user_prompt_str, all_meme_images, chat_history
656
 
657
 
@@ -941,5 +936,5 @@ with gr.Blocks(title="AI Meme Generator", theme=gr.themes.Base(), css=css) as de
941
  # outputs=[template_gallery],
942
  queue=False,
943
  )
944
- demo.queue(concurrency_count=4, max_size=40, api_open=False)
945
  demo.launch(max_threads=400)
 
634
  query = prompt_list_to_tgi_input(formated_prompt_list)
635
  all_meme_images = []
636
  with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
637
+ all_meme_images = list(
638
+ executor.map(
639
  generate_meme,
640
+ [client for _ in range(4)],
641
+ [query for _ in range(4)],
642
+ [image for _ in range(4)],
643
+ [font_meme_text for _ in range(4)],
644
+ [all_caps_meme_text for _ in range(4)],
645
+ [text_at_the_top for _ in range(4)],
646
+ [generation_args for _ in range(4)],
647
  )
648
+ )
649
+ all_meme_images = [meme for meme in all_meme_images if meme is not None]
 
 
 
 
 
650
  return user_prompt_str, all_meme_images, chat_history
651
 
652
 
 
936
  # outputs=[template_gallery],
937
  queue=False,
938
  )
939
+ demo.queue(concurrency_count=8, max_size=40, api_open=False)
940
  demo.launch(max_threads=400)