RanM commited on
Commit
5c6cd7b
·
verified ·
1 Parent(s): c6bcba8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -5
app.py CHANGED
@@ -7,7 +7,7 @@ import gradio as gr
7
  from concurrent.futures import ProcessPoolExecutor
8
  import multiprocessing
9
 
10
- # Load the model once outside of the function
11
  print("Loading the model...")
12
  model = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo")
13
  print("Model loaded successfully.")
@@ -66,15 +66,12 @@ async def queue_api_calls(sentence_mapping, character_dict, selected_style):
66
  def process_prompt(sentence_mapping, character_dict, selected_style):
67
  print(f"process_prompt called with sentence_mapping: {sentence_mapping}, character_dict: {character_dict}, selected_style: {selected_style}")
68
  try:
69
- # See if there is a loop already running. If there is, reuse it.
70
  loop = asyncio.get_running_loop()
71
  except RuntimeError:
72
- # Create new event loop if one is not running
73
  loop = asyncio.new_event_loop()
74
  asyncio.set_event_loop(loop)
75
  print("Event loop created.")
76
 
77
- # This sends the prompts to function that sets up the async calls. Once all the calls to the API complete, it returns a list of the gr.Textbox with value= set.
78
  cmpt_return = loop.run_until_complete(queue_api_calls(sentence_mapping, character_dict, selected_style))
79
  print(f"process_prompt completed with return value: {cmpt_return}")
80
  return cmpt_return
@@ -92,5 +89,5 @@ gradio_interface = gr.Interface(
92
 
93
  if __name__ == "__main__":
94
  print("Launching Gradio interface...")
95
- gradio_interface.launch()
96
  print("Gradio interface launched.")
 
7
  from concurrent.futures import ProcessPoolExecutor
8
  import multiprocessing
9
 
10
+ # Load the model once outside of the function and share across processes
11
  print("Loading the model...")
12
  model = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo")
13
  print("Model loaded successfully.")
 
66
  def process_prompt(sentence_mapping, character_dict, selected_style):
67
  print(f"process_prompt called with sentence_mapping: {sentence_mapping}, character_dict: {character_dict}, selected_style: {selected_style}")
68
  try:
 
69
  loop = asyncio.get_running_loop()
70
  except RuntimeError:
 
71
  loop = asyncio.new_event_loop()
72
  asyncio.set_event_loop(loop)
73
  print("Event loop created.")
74
 
 
75
  cmpt_return = loop.run_until_complete(queue_api_calls(sentence_mapping, character_dict, selected_style))
76
  print(f"process_prompt completed with return value: {cmpt_return}")
77
  return cmpt_return
 
89
 
90
  if __name__ == "__main__":
91
  print("Launching Gradio interface...")
92
+ gradio_interface.launch(server_name="0.0.0.0", server_port=7860, debug=True)
93
  print("Gradio interface launched.")