Spaces:
Running
Running
sab
commited on
Commit
β’
549018e
1
Parent(s):
b436fb9
config file
Browse files
app.py
CHANGED
@@ -13,38 +13,42 @@ import torch
|
|
13 |
from diffusers import MochiPipeline
|
14 |
from diffusers.utils import export_to_video
|
15 |
import gradio as gr
|
|
|
16 |
|
17 |
-
#
|
18 |
-
pipe = MochiPipeline.from_pretrained(
|
19 |
|
20 |
-
#
|
21 |
pipe.enable_model_cpu_offload()
|
22 |
pipe.enable_vae_tiling()
|
23 |
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
def generate_video(prompt):
|
27 |
-
# Generare i frame del video
|
28 |
-
print("Generare i frame del video...")
|
29 |
-
#frames = pipe(prompt, num_frames=84).frames[0]
|
30 |
-
frames = pipe(prompt, num_frames=24).frames[0]
|
31 |
-
|
32 |
-
# Esportare i frame come video
|
33 |
video_path = "mochi.mp4"
|
34 |
-
export_to_video(frames, video_path, fps=
|
35 |
-
|
36 |
return video_path
|
37 |
|
38 |
-
|
39 |
-
# Creare l'interfaccia Gradio
|
40 |
interface = gr.Interface(
|
41 |
fn=generate_video,
|
42 |
-
inputs=
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
)
|
47 |
|
48 |
-
#
|
49 |
if __name__ == "__main__":
|
50 |
interface.launch()
|
|
|
13 |
from diffusers import MochiPipeline
|
14 |
from diffusers.utils import export_to_video
|
15 |
import gradio as gr
|
16 |
+
import config as cfg
|
17 |
|
18 |
+
# Load the pre-trained model
|
19 |
+
pipe = MochiPipeline.from_pretrained(cfg.MODEL_PRE_TRAINED_ID, variant="bf16", torch_dtype=torch.bfloat16)
|
20 |
|
21 |
+
# Enable memory-saving optimizations
|
22 |
pipe.enable_model_cpu_offload()
|
23 |
pipe.enable_vae_tiling()
|
24 |
|
25 |
+
@spaces.GPU(duration=600)
|
26 |
+
def generate_video(prompt, num_frames=84, fps=30):
|
27 |
+
# Generate video frames
|
28 |
+
print("Generating video frames...")
|
29 |
+
frames = pipe(prompt, num_frames=num_frames).frames[0]
|
30 |
|
31 |
+
# Export frames as video
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
video_path = "mochi.mp4"
|
33 |
+
export_to_video(frames, video_path, fps=fps)
|
|
|
34 |
return video_path
|
35 |
|
36 |
+
# Create the Gradio interface
|
|
|
37 |
interface = gr.Interface(
|
38 |
fn=generate_video,
|
39 |
+
inputs=[
|
40 |
+
gr.inputs.Textbox(lines=2, placeholder="Enter your text prompt here... π‘"),
|
41 |
+
gr.inputs.Slider(minimum=1, maximum=240, default=84, label="Number of frames ποΈ"),
|
42 |
+
gr.inputs.Slider(minimum=1, maximum=60, default=30, label="FPS (Frames per second) β±οΈ")
|
43 |
+
],
|
44 |
+
outputs=gr.outputs.Video(),
|
45 |
+
title=cfg.TITLE,
|
46 |
+
description=cfg.DESCRIPTION,
|
47 |
+
examples=cfg.EXAMPLES,
|
48 |
+
article=cfg.BUY_ME_A_COFFEE
|
49 |
+
|
50 |
)
|
51 |
|
52 |
+
# Launch the application
|
53 |
if __name__ == "__main__":
|
54 |
interface.launch()
|
config.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
TITLE = "Mochi 1 - Video Generator π"
|
5 |
+
|
6 |
+
DESCRIPTION = """
|
7 |
+
β¨ Generate a video based on a text prompt using the MochiPipeline. π₯
|
8 |
+
Enter a text prompt and customize the number of frames and the frame rate (fps) for the generated video. π οΈ
|
9 |
+
"""
|
10 |
+
|
11 |
+
BUY_ME_A_COFFE= """
|
12 |
+
<a href="https://buymeacoffee.com/thesab" target="_blank">
|
13 |
+
<button style="background-color: #FFDD00; border: none; color: black; padding: 10px 20px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; border-radius: 10px;">
|
14 |
+
β Buy Me a Coffee
|
15 |
+
</button>
|
16 |
+
</a>
|
17 |
+
"""
|
18 |
+
|
19 |
+
|
20 |
+
MODEL_PRE_TRAINED_ID = "genmo/mochi-1-preview"
|
21 |
+
|
22 |
+
MAX_SEED = np.iinfo(np.int32).max
|
23 |
+
MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "1024"))
|
24 |
+
DEFAULT_SEED = 42
|
25 |
+
DEFAULT_RANDOMIZE_SEED = False
|
26 |
+
DEFAULT_WIDTH = 1024
|
27 |
+
DEFAULT_HEIGHT = 1024
|
28 |
+
DEFAULT_GUIDANCE_SCALE = 4.5
|
29 |
+
DEFAULT_NUM_INFERENCE_STEPS = 40
|
30 |
+
DEFAULT_LORA_SCALE = 4.5
|
31 |
+
|
32 |
+
EXAMPLES = [
|
33 |
+
["A beautiful sunrise over the mountains π", 100, 24],
|
34 |
+
["A futuristic city with flying cars πβ¨", 120, 30],
|
35 |
+
["A serene beach with waves crashing π", 80, 25],
|
36 |
+
["A bustling market in a medieval town π°", 90, 20],
|
37 |
+
["A spaceship traveling through space π", 110, 30]
|
38 |
+
]
|
39 |
+
|