Rishi Desai commited on
Commit
b8037c7
·
1 Parent(s): 212f6c9

more work on async

Browse files
Files changed (1) hide show
  1. demo.py +11 -2
demo.py CHANGED
@@ -5,6 +5,10 @@ import base64
5
  import asyncio
6
  from main import process_async
7
 
 
 
 
 
8
  async def process_image_and_generate_video_async(image, prompt):
9
  # Create a temporary directory for intermediate files
10
  with tempfile.TemporaryDirectory() as temp_dir:
@@ -26,7 +30,8 @@ async def process_image_and_generate_video_async(image, prompt):
26
  return None
27
 
28
  def process_image_and_generate_video(image, prompt):
29
- return asyncio.run(process_image_and_generate_video_async(image, prompt))
 
30
 
31
  # Create the Gradio interface
32
  with gr.Blocks(title="Character Video Generation") as demo:
@@ -57,4 +62,8 @@ with gr.Blocks(title="Character Video Generation") as demo:
57
  )
58
 
59
  if __name__ == "__main__":
60
- demo.launch(share=True)
 
 
 
 
 
5
  import asyncio
6
  from main import process_async
7
 
8
+ # Create a single event loop for the entire application
9
+ loop = asyncio.new_event_loop()
10
+ asyncio.set_event_loop(loop)
11
+
12
  async def process_image_and_generate_video_async(image, prompt):
13
  # Create a temporary directory for intermediate files
14
  with tempfile.TemporaryDirectory() as temp_dir:
 
30
  return None
31
 
32
  def process_image_and_generate_video(image, prompt):
33
+ # Use the existing event loop instead of creating a new one
34
+ return loop.run_until_complete(process_image_and_generate_video_async(image, prompt))
35
 
36
  # Create the Gradio interface
37
  with gr.Blocks(title="Character Video Generation") as demo:
 
62
  )
63
 
64
  if __name__ == "__main__":
65
+ try:
66
+ demo.launch(share=True)
67
+ finally:
68
+ # Clean up the event loop when the application exits
69
+ loop.close()