Spaces:
Running
Running
Anurag Bhardwaj
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,66 @@
|
|
1 |
-
import
|
2 |
import subprocess
|
3 |
import os
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
if st.button("Generate Video"):
|
16 |
-
st.info("Generating video... This may take a few minutes.")
|
17 |
-
|
18 |
-
# Run WAN 2.1 - 14B Model
|
19 |
-
command = f"python generate.py --task t2v-14B --size {resolution} --frame_num {frame_num} --sample_steps {sample_steps} --ckpt_dir ./Wan2.1-T2V-14B --offload_model True --prompt \"{prompt}\""
|
20 |
|
|
|
21 |
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
22 |
stdout, stderr = process.communicate()
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
# Check if video was created
|
28 |
if os.path.exists("output.mp4"):
|
29 |
-
|
30 |
-
|
31 |
else:
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
import subprocess
|
3 |
import os
|
4 |
|
5 |
+
def generate_video(prompt, frame_num, resolution, sample_steps):
|
6 |
+
# Inform user that generation has started
|
7 |
+
status = "Generating video... This may take a few minutes."
|
8 |
+
|
9 |
+
# Build command with proper quoting for the prompt
|
10 |
+
command = (
|
11 |
+
f"python generate.py --task t2v-14B --size {resolution} "
|
12 |
+
f"--frame_num {frame_num} --sample_steps {sample_steps} "
|
13 |
+
f"--ckpt_dir ./Wan2.1-T2V-14B --offload_model True --prompt \"{prompt}\""
|
14 |
+
)
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# Run the command and capture stdout and stderr
|
17 |
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
18 |
stdout, stderr = process.communicate()
|
19 |
+
logs = stdout.decode() + stderr.decode()
|
20 |
+
|
21 |
+
# Check if video file exists
|
|
|
|
|
22 |
if os.path.exists("output.mp4"):
|
23 |
+
video_file = "output.mp4"
|
24 |
+
status = "β
Video generated successfully!"
|
25 |
else:
|
26 |
+
video_file = None
|
27 |
+
status = "β Video generation failed! Check logs above."
|
28 |
+
|
29 |
+
return video_file, logs, status
|
30 |
+
|
31 |
+
with gr.Blocks() as demo:
|
32 |
+
gr.Markdown("# π₯ WAN 2.1 - 14B AI Text-to-Video Generator")
|
33 |
+
|
34 |
+
with gr.Row():
|
35 |
+
prompt_input = gr.Textbox(
|
36 |
+
label="Enter your text prompt:",
|
37 |
+
value="A cat in military dress wearing headphones, laughing and walking.",
|
38 |
+
lines=4
|
39 |
+
)
|
40 |
+
|
41 |
+
with gr.Row():
|
42 |
+
frame_slider = gr.Slider(30, 120, step=10, value=60, label="Number of frames:")
|
43 |
+
|
44 |
+
with gr.Row():
|
45 |
+
resolution_choice = gr.Radio(
|
46 |
+
choices=["832*480", "1280*720"],
|
47 |
+
label="Select resolution:",
|
48 |
+
value="832*480"
|
49 |
+
)
|
50 |
+
|
51 |
+
with gr.Row():
|
52 |
+
steps_slider = gr.Slider(10, 50, step=5, value=20, label="Sampling steps:")
|
53 |
+
|
54 |
+
generate_button = gr.Button("Generate Video")
|
55 |
+
|
56 |
+
video_output = gr.Video(label="Generated Video")
|
57 |
+
logs_output = gr.Textbox(label="π Logs", lines=10)
|
58 |
+
status_output = gr.Textbox(label="Status")
|
59 |
+
|
60 |
+
generate_button.click(
|
61 |
+
generate_video,
|
62 |
+
inputs=[prompt_input, frame_slider, resolution_choice, steps_slider],
|
63 |
+
outputs=[video_output, logs_output, status_output]
|
64 |
+
)
|
65 |
+
|
66 |
+
demo.launch()
|