Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from diffusers import DiffusionPipeline
|
3 |
+
|
4 |
+
# Загрузка модели
|
5 |
+
model_id = "ali-vilab/text-to-video-ms-1.7b"
|
6 |
+
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, variant="fp16")
|
7 |
+
pipe = pipe.to("cuda")
|
8 |
+
|
9 |
+
def generate_video(prompt: str, num_inference_steps: int = 50, guidance_scale: float = 7.5):
|
10 |
+
"""
|
11 |
+
Генерирует видео по текстовому описанию.
|
12 |
+
|
13 |
+
Args:
|
14 |
+
prompt (str): Текстовое описание видео.
|
15 |
+
num_inference_steps (int, optional): Количество шагов вывода. По умолчанию 50.
|
16 |
+
guidance_scale (float, optional): Масштаб направляющей. По умолчанию 7.5.
|
17 |
+
|
18 |
+
Returns:
|
19 |
+
str: Путь к сгенерированному видео.
|
20 |
+
"""
|
21 |
+
|
22 |
+
video_frames = pipe(prompt, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale).frames
|
23 |
+
video_path = f"generated_video_{prompt[:10]}.mp4"
|
24 |
+
video_frames[0].save(video_path, save_all=True, append_images=video_frames[1:])
|
25 |
+
return video_path
|
26 |
+
|
27 |
+
with gr.Blocks() as demo:
|
28 |
+
with gr.Row():
|
29 |
+
with gr.Column():
|
30 |
+
text_input = gr.Textbox(label="Введите текстовое описание видео:")
|
31 |
+
num_inference_steps_slider = gr.Slider(minimum=10, maximum=100, value=50, step=10, label="Количество шагов вывода:")
|
32 |
+
guidance_scale_slider = gr.Slider(minimum=1, maximum=15, value=7.5, step=0.5, label="Масштаб направляющей:")
|
33 |
+
generate_button = gr.Button("Сгенерировать видео")
|
34 |
+
with gr.Column():
|
35 |
+
video_output = gr.Video(label="Сгенерированное видео:")
|
36 |
+
|
37 |
+
generate_button.click(fn=generate_video, inputs=[text_input, num_inference_steps_slider, guidance_scale_slider], outputs=video_output)
|
38 |
+
|
39 |
+
demo.launch()
|