Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -2,13 +2,13 @@ import torch
|
|
| 2 |
import gradio as gr
|
| 3 |
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
| 4 |
from diffusers.utils import export_to_video
|
|
|
|
| 5 |
|
| 6 |
-
# Отключение CUDA (GPU)
|
| 7 |
-
#torch.device('cuda')
|
| 8 |
|
| 9 |
def generate_video(prompt):
|
| 10 |
# load pipeline
|
| 11 |
-
pipe = DiffusionPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b", torch_dtype=torch.float16,
|
|
|
|
| 12 |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
| 13 |
|
| 14 |
# optimize for GPU memory
|
|
@@ -18,9 +18,17 @@ def generate_video(prompt):
|
|
| 18 |
# generate
|
| 19 |
video_frames = pipe(prompt, num_inference_steps=25, num_frames=200).frames
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# convert to video
|
| 22 |
-
video_path = export_to_video(video_frames)
|
| 23 |
return video_path
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
| 4 |
from diffusers.utils import export_to_video
|
| 5 |
+
import os
|
| 6 |
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def generate_video(prompt):
|
| 9 |
# load pipeline
|
| 10 |
+
pipe = DiffusionPipeline.from_pretrained("damo-vilab/text-to-video-ms-1.7b", torch_dtype=torch.float16,
|
| 11 |
+
variant="fp16")
|
| 12 |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
| 13 |
|
| 14 |
# optimize for GPU memory
|
|
|
|
| 18 |
# generate
|
| 19 |
video_frames = pipe(prompt, num_inference_steps=25, num_frames=200).frames
|
| 20 |
|
| 21 |
+
# get absolute path to current working directory
|
| 22 |
+
current_directory = os.getcwd()
|
| 23 |
+
|
| 24 |
+
# create directory to store video
|
| 25 |
+
video_directory = os.path.join(current_directory, "generated_videos")
|
| 26 |
+
os.makedirs(video_directory, exist_ok=True)
|
| 27 |
+
|
| 28 |
# convert to video
|
| 29 |
+
video_path = export_to_video(video_frames, os.path.join(video_directory, "generated_video.mp4"))
|
| 30 |
return video_path
|
| 31 |
|
| 32 |
+
|
| 33 |
+
iface = gr.Interface(fn=generate_video, inputs="text", outputs="file")
|
| 34 |
+
iface.launch()
|