AngeT10 commited on
Commit
83f8db0
1 Parent(s): ae37ed8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -46
app.py CHANGED
@@ -1,58 +1,52 @@
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()
 
1
  import gradio as gr
2
+ import torch
3
+ from torchvision import transforms
4
+ from PIL import Image
5
+ import numpy as np
6
  import subprocess
 
7
 
8
+ # Carica il modello HunyuanVideo
9
+ model = torch.hub.load('tencent/HunyuanVideo', 'HunyuanVideo', pretrained=True)
10
 
11
+ # Definisci la funzione per generare video
12
+ def generate_video(prompt, video_size=(720, 1280), video_length=129, infer_steps=50):
13
+ # Prepara il prompt per il modello
14
+ prompt = prompt.strip()
15
+
16
+ # Genera il video utilizzando il modello
17
  command = [
18
  "python3", "sample_video.py",
19
+ "--video-size", str(video_size[0]), str(video_size[1]),
 
20
  "--video-length", str(video_length),
21
  "--infer-steps", str(infer_steps),
22
+ "--prompt", prompt,
23
+ "--flow-reverse",
24
+ "--use-cpu-offload",
25
+ "--save-path", "./results"
26
  ]
27
 
28
+ # Esegue il comando
29
+ subprocess.run(command)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
+ # Carica il video generato
32
+ video_path = "./results/generated_video.mp4"
33
+
34
+ # Ritorna il video generato
35
+ return video_path
36
+
37
+ # Crea l'interfaccia Gradio
38
+ iface = gr.Interface(
39
+ fn=generate_video,
40
+ inputs=[
41
+ gr.Textbox(label="Inserisci il prompt", placeholder="Un gatto cammina sull'erba, stile realistico."),
42
+ gr.Dropdown(label="Dimensione del video", choices=[(720, 1280), (544, 960)], value=(720, 1280)),
43
+ gr.Slider(label="Lunghezza del video (frame)", minimum=1, maximum=300, value=129),
44
+ gr.Slider(label="Passi di inferenza", minimum=1, maximum=100, value=50)
45
+ ],
46
+ outputs=gr.Video(label="Video generato"),
47
+ title="Generazione di video con HunyuanVideo",
48
+ description="Genera video utilizzando il modello HunyuanVideo fornendo un prompt di testo."
49
+ )
50
 
51
+ # Avvia l'applicazione Gradio
52
+ iface.launch()