Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import subprocess
|
3 |
+
import os
|
4 |
+
|
5 |
+
# Path to save the generated video
|
6 |
+
output_dir = './results'
|
7 |
+
|
8 |
+
# Ensure the output directory exists
|
9 |
+
os.makedirs(output_dir, exist_ok=True)
|
10 |
+
|
11 |
+
# Define the function to generate the video
|
12 |
+
def generate_video(prompt, video_size, video_length, infer_steps, seed, save_path):
|
13 |
+
# Command to run the HunyuanVideo script
|
14 |
+
command = [
|
15 |
+
"python3", "sample_video.py",
|
16 |
+
"--prompt", prompt,
|
17 |
+
"--video-size", video_size,
|
18 |
+
"--video-length", str(video_length),
|
19 |
+
"--infer-steps", str(infer_steps),
|
20 |
+
"--seed", str(seed),
|
21 |
+
"--save-path", save_path
|
22 |
+
]
|
23 |
+
|
24 |
+
# Run the video generation process
|
25 |
+
try:
|
26 |
+
subprocess.run(command, check=True)
|
27 |
+
# Return the path to the generated video file
|
28 |
+
generated_video_path = os.path.join(save_path, "generated_video.mp4")
|
29 |
+
return generated_video_path
|
30 |
+
except subprocess.CalledProcessError as e:
|
31 |
+
return f"Error generating video: {e}"
|
32 |
+
|
33 |
+
# Create the Gradio interface
|
34 |
+
def create_interface():
|
35 |
+
# Define input components
|
36 |
+
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter the prompt for the video.")
|
37 |
+
video_size_input = gr.Textbox(label="Video Size", value="720 1280")
|
38 |
+
video_length_input = gr.Slider(label="Video Length", minimum=1, maximum=200, value=129)
|
39 |
+
infer_steps_input = gr.Slider(label="Inference Steps", minimum=1, maximum=100, value=30)
|
40 |
+
seed_input = gr.Slider(label="Seed", minimum=0, maximum=1000, value=0)
|
41 |
+
save_path_input = gr.Textbox(label="Save Path", value=output_dir)
|
42 |
+
|
43 |
+
# Define output component
|
44 |
+
output_video = gr.Video(label="Generated Video")
|
45 |
+
|
46 |
+
# Create Gradio interface
|
47 |
+
interface = gr.Interface(
|
48 |
+
fn=generate_video,
|
49 |
+
inputs=[prompt_input, video_size_input, video_length_input, infer_steps_input, seed_input, save_path_input],
|
50 |
+
outputs=[output_video],
|
51 |
+
live=True
|
52 |
+
)
|
53 |
+
|
54 |
+
# Launch the interface
|
55 |
+
interface.launch()
|
56 |
+
|
57 |
+
if __name__ == "__main__":
|
58 |
+
create_interface()
|