Anurag Bhardwaj commited on
Commit
ed35423
Β·
verified Β·
1 Parent(s): 0a9083e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -24
app.py CHANGED
@@ -1,32 +1,66 @@
1
- import streamlit as st
2
  import subprocess
3
  import os
4
 
5
- # Title
6
- st.title("πŸŽ₯ WAN 2.1 - 14B AI Text-to-Video Generator")
7
-
8
- # Input fields
9
- prompt = st.text_area("Enter your text prompt:", "A cat in military dress wearing headphones, laughing and walking.")
10
- frame_num = st.slider("Number of frames:", min_value=30, max_value=120, value=60, step=10)
11
- resolution = st.selectbox("Select resolution:", ["832*480", "1280*720"])
12
- sample_steps = st.slider("Sampling steps:", min_value=10, max_value=50, value=20, step=5)
13
-
14
- # Button to generate video
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
- # Print logs for debugging
25
- st.text_area("πŸ“œ Logs", stdout.decode() + stderr.decode())
26
-
27
- # Check if video was created
28
  if os.path.exists("output.mp4"):
29
- st.video("output.mp4")
30
- st.success("βœ… Video generated successfully!")
31
  else:
32
- st.error("❌ Video generation failed! Check logs above.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()