sab commited on
Commit
549018e
β€’
1 Parent(s): b436fb9

config file

Browse files
Files changed (2) hide show
  1. app.py +24 -20
  2. config.py +39 -0
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
- # Caricare il modello pre-addestrato
18
- pipe = MochiPipeline.from_pretrained("genmo/mochi-1-preview", variant="bf16", torch_dtype=torch.bfloat16)
19
 
20
- # Abilitare le ottimizzazioni per il risparmio di memoria
21
  pipe.enable_model_cpu_offload()
22
  pipe.enable_vae_tiling()
23
 
 
 
 
 
 
24
 
25
- @spaces.GPU(duration=200)
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=30)
35
-
36
  return video_path
37
 
38
-
39
- # Creare l'interfaccia Gradio
40
  interface = gr.Interface(
41
  fn=generate_video,
42
- inputs="text",
43
- outputs="video",
44
- title="Mochi Video Generator",
45
- description="Genera un video basato su un prompt di testo utilizzando MochiPipeline."
 
 
 
 
 
 
 
46
  )
47
 
48
- # Avviare l'applicazione
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
+