Spaces:
Running
Running
sab
commited on
Commit
β’
0d3ff24
1
Parent(s):
30a08a0
fix layout
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
if os.environ.get("SPACES_ZERO_GPU") is not None:
|
3 |
import spaces
|
4 |
else:
|
@@ -7,6 +8,7 @@ else:
|
|
7 |
def GPU(func):
|
8 |
def wrapper(*args, **kwargs):
|
9 |
return func(*args, **kwargs)
|
|
|
10 |
return wrapper
|
11 |
|
12 |
import torch
|
@@ -22,33 +24,53 @@ pipe = MochiPipeline.from_pretrained(cfg.MODEL_PRE_TRAINED_ID, variant="bf16", t
|
|
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 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
|
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.Textbox(lines=2, placeholder="Enter your text prompt here... π‘"),
|
41 |
gr.Slider(minimum=1, maximum=240, value=84, label="Number of frames ποΈ"),
|
42 |
-
gr.Slider(minimum=1, maximum=60, value=30, label="FPS (Frames per second) β±οΈ")
|
|
|
43 |
],
|
44 |
outputs=gr.Video(),
|
45 |
title=cfg.TITLE,
|
46 |
description=cfg.DESCRIPTION,
|
47 |
examples=cfg.EXAMPLES,
|
48 |
-
article=cfg.BUY_ME_A_COFFE
|
49 |
-
|
50 |
)
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
# Launch the application
|
53 |
if __name__ == "__main__":
|
54 |
interface.launch()
|
|
|
1 |
import os
|
2 |
+
|
3 |
if os.environ.get("SPACES_ZERO_GPU") is not None:
|
4 |
import spaces
|
5 |
else:
|
|
|
8 |
def GPU(func):
|
9 |
def wrapper(*args, **kwargs):
|
10 |
return func(*args, **kwargs)
|
11 |
+
|
12 |
return wrapper
|
13 |
|
14 |
import torch
|
|
|
24 |
pipe.enable_model_cpu_offload()
|
25 |
pipe.enable_vae_tiling()
|
26 |
|
27 |
+
|
28 |
@spaces.GPU(duration=600)
|
29 |
+
def generate_video(prompt, num_frames=84, fps=30, high_quality=False):
|
30 |
+
if high_quality:
|
31 |
+
print("High quality option selected. Requires 42GB VRAM.")
|
32 |
+
# Check if running on ZeroGPU
|
33 |
+
if os.environ.get("SPACES_ZERO_GPU") is not None:
|
34 |
+
raise RuntimeError("High quality option may fail on ZeroGPU environments.")
|
35 |
+
with torch.autocast("cuda", torch.bfloat16, cache_enabled=False):
|
36 |
+
frames = pipe(prompt, num_frames=num_frames).frames[0]
|
37 |
+
else:
|
38 |
+
print("Standard quality option selected.")
|
39 |
+
frames = pipe(prompt, num_frames=num_frames).frames[0]
|
40 |
|
41 |
+
# Export frames as video
|
42 |
video_path = "mochi.mp4"
|
43 |
export_to_video(frames, video_path, fps=fps)
|
44 |
return video_path
|
45 |
|
46 |
+
|
47 |
# Create the Gradio interface
|
48 |
interface = gr.Interface(
|
49 |
fn=generate_video,
|
50 |
inputs=[
|
51 |
gr.Textbox(lines=2, placeholder="Enter your text prompt here... π‘"),
|
52 |
gr.Slider(minimum=1, maximum=240, value=84, label="Number of frames ποΈ"),
|
53 |
+
gr.Slider(minimum=1, maximum=60, value=30, label="FPS (Frames per second) β±οΈ"),
|
54 |
+
gr.Checkbox(label="High Quality Output (requires 42GB VRAM, may fail on ZeroGPU)")
|
55 |
],
|
56 |
outputs=gr.Video(),
|
57 |
title=cfg.TITLE,
|
58 |
description=cfg.DESCRIPTION,
|
59 |
examples=cfg.EXAMPLES,
|
60 |
+
article=cfg.BUY_ME_A_COFFE,
|
61 |
+
layout="vertical" # Use vertical layout to center title and description
|
62 |
)
|
63 |
|
64 |
+
# Center the title and description using custom CSS
|
65 |
+
interface.css = """
|
66 |
+
.interface-title {
|
67 |
+
text-align: center;
|
68 |
+
}
|
69 |
+
.interface-description {
|
70 |
+
text-align: center;
|
71 |
+
}
|
72 |
+
"""
|
73 |
+
|
74 |
# Launch the application
|
75 |
if __name__ == "__main__":
|
76 |
interface.launch()
|
config.py
CHANGED
@@ -1,6 +1,3 @@
|
|
1 |
-
import os
|
2 |
-
import numpy as np
|
3 |
-
|
4 |
TITLE = "Mochi 1 - Video Generator π"
|
5 |
|
6 |
DESCRIPTION = """
|
@@ -19,21 +16,11 @@ BUY_ME_A_COFFE = """
|
|
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 |
-
|
34 |
-
["A
|
35 |
-
["A
|
36 |
-
["
|
37 |
-
["A
|
38 |
]
|
39 |
|
|
|
|
|
|
|
|
|
1 |
TITLE = "Mochi 1 - Video Generator π"
|
2 |
|
3 |
DESCRIPTION = """
|
|
|
16 |
|
17 |
MODEL_PRE_TRAINED_ID = "genmo/mochi-1-preview"
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
EXAMPLES = [
|
20 |
+
["A majestic dragon soaring over a fiery volcano during a lunar eclipse, casting long shadows on the ancient ruins below. The ground trembles as molten lava flows down the mountainside, and the air is thick with ash and smoke.", 70, 24],
|
21 |
+
["A bustling steampunk city with towering airships navigating the skies, clockwork robots performing various tasks, and intricate networks of pipes and gears running through every building. The streets are filled with people in Victorian attire, and the sky is a perpetual haze of smoke and steam.", 60, 30],
|
22 |
+
["A magical forest filled with luminescent creatures that glow softly in the dim light, ancient ruins covered in mystical runes, and a crystal-clear river flowing under the light of a full moon. The trees are tall and twisted, their branches intertwined to form a canopy that filters the moonlight.", 50, 25],
|
23 |
+
["An underwater city inhabited by mermaids, surrounded by vibrant coral reefs and schools of colorful fish. The buildings are constructed from seashells and coral, with bioluminescent plants lighting the streets. The water is clear and teeming with marine life, creating a serene and otherworldly atmosphere.", 65, 20],
|
24 |
+
["A futuristic space station orbiting a distant exoplanet, equipped with massive solar panels and docking bays filled with various starships. The observation decks offer breathtaking views of the galaxy, with nearby nebulas and distant stars twinkling in the vast expanse of space.", 75, 30]
|
25 |
]
|
26 |
|