Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,32 @@
|
|
| 1 |
-
import
|
| 2 |
-
from
|
| 3 |
-
from
|
| 4 |
-
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
pipe =
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
# Generate video using RCNA MINI
|
| 22 |
-
output = pipe(
|
| 23 |
-
prompt=prompt,
|
| 24 |
-
negative_prompt="bad quality, worse quality, low resolution",
|
| 25 |
-
num_frames=16,
|
| 26 |
-
guidance_scale=2.0,
|
| 27 |
-
num_inference_steps=6,
|
| 28 |
-
generator=torch.Generator("cpu").manual_seed(0),
|
| 29 |
-
)
|
| 30 |
-
frames = output.frames[0]
|
| 31 |
-
export_to_gif(frames, "animatelcm.gif")
|
| 32 |
-
|
| 33 |
-
# Return the generated video
|
| 34 |
-
return "animatelcm.gif"
|
| 35 |
-
|
| 36 |
-
# Create a Gradio interface
|
| 37 |
-
interface = gr.Interface(
|
| 38 |
fn=generate_video,
|
| 39 |
-
inputs="text",
|
| 40 |
-
outputs="
|
| 41 |
-
title="
|
| 42 |
-
description="
|
| 43 |
)
|
| 44 |
|
| 45 |
-
# Launch the Gradio
|
| 46 |
-
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import snapshot_download
|
| 2 |
+
from modelscope.pipelines import pipeline
|
| 3 |
+
from modelscope.outputs import OutputKeys
|
| 4 |
+
import pathlib
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
+
# Download the model weights and prepare the model directory
|
| 8 |
+
model_dir = pathlib.Path('weights')
|
| 9 |
+
snapshot_download('damo-vilab/modelscope-damo-text-to-video-synthesis',
|
| 10 |
+
repo_type='model', local_dir=model_dir)
|
| 11 |
|
| 12 |
+
# Initialize the text-to-video synthesis pipeline
|
| 13 |
+
pipe = pipeline('text-to-video-synthesis', model_dir.as_posix())
|
| 14 |
|
| 15 |
+
# Define a function that takes a text prompt and generates a video
|
| 16 |
+
def generate_video(text_prompt):
|
| 17 |
+
test_text = {'text': text_prompt}
|
| 18 |
+
output_video_path = pipe(test_text)[OutputKeys.OUTPUT_VIDEO]
|
| 19 |
+
return output_video_path
|
| 20 |
|
| 21 |
+
# Set up Gradio interface
|
| 22 |
+
demo = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
fn=generate_video,
|
| 24 |
+
inputs=gr.Textbox(label="Enter a text prompt", placeholder="Describe the scene..."),
|
| 25 |
+
outputs=gr.Video(label="Generated Video"),
|
| 26 |
+
title="Text-to-Video Generator",
|
| 27 |
+
description="Enter a text description, and the model will generate a video based on your input.",
|
| 28 |
)
|
| 29 |
|
| 30 |
+
# Launch the Gradio interface
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
demo.launch()
|