Rishi Desai
commited on
Commit
·
212f6c9
1
Parent(s):
77096dd
fixing async issue
Browse files
demo.py
CHANGED
@@ -2,9 +2,10 @@ import gradio as gr
|
|
2 |
import os
|
3 |
import tempfile
|
4 |
import base64
|
5 |
-
|
|
|
6 |
|
7 |
-
def
|
8 |
# Create a temporary directory for intermediate files
|
9 |
with tempfile.TemporaryDirectory() as temp_dir:
|
10 |
# Save the uploaded image to a temporary file
|
@@ -17,25 +18,32 @@ def process_image_and_generate_video(image, prompt):
|
|
17 |
data_url = f"data:image/png;base64,{encoded_image}"
|
18 |
|
19 |
# Process the image and generate video
|
20 |
-
|
21 |
-
result, generated_image_path, video_path = process(data_url, prompt, temp_dir)
|
22 |
|
23 |
if result and video_path:
|
24 |
return video_path
|
25 |
else:
|
26 |
return None
|
27 |
|
|
|
|
|
|
|
28 |
# Create the Gradio interface
|
29 |
with gr.Blocks(title="Character Video Generation") as demo:
|
30 |
gr.Markdown("# Character Video Generation")
|
31 |
gr.Markdown("""
|
32 |
-
* Upload a high-quality image of a person
|
33 |
* Enter a prompt to generate a video
|
34 |
""")
|
35 |
|
36 |
with gr.Row():
|
37 |
with gr.Column():
|
38 |
-
input_image = gr.Image(
|
|
|
|
|
|
|
|
|
|
|
39 |
prompt = gr.Textbox(label="Enter your prompt")
|
40 |
generate_btn = gr.Button("Generate")
|
41 |
|
|
|
2 |
import os
|
3 |
import tempfile
|
4 |
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:
|
11 |
# Save the uploaded image to a temporary file
|
|
|
18 |
data_url = f"data:image/png;base64,{encoded_image}"
|
19 |
|
20 |
# Process the image and generate video
|
21 |
+
result, generated_image_path, video_path = await process_async(data_url, prompt, temp_dir)
|
|
|
22 |
|
23 |
if result and video_path:
|
24 |
return video_path
|
25 |
else:
|
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:
|
33 |
gr.Markdown("# Character Video Generation")
|
34 |
gr.Markdown("""
|
35 |
+
* Upload a high-quality image of a person (PNG, JPG, or JPEG only)
|
36 |
* Enter a prompt to generate a video
|
37 |
""")
|
38 |
|
39 |
with gr.Row():
|
40 |
with gr.Column():
|
41 |
+
input_image = gr.Image(
|
42 |
+
type="pil",
|
43 |
+
label="Upload Reference Image (PNG, JPG, or JPEG only)",
|
44 |
+
height=512,
|
45 |
+
width=512
|
46 |
+
)
|
47 |
prompt = gr.Textbox(label="Enter your prompt")
|
48 |
generate_btn = gr.Button("Generate")
|
49 |
|