Spaces:
Runtime error
Runtime error
sab
commited on
Commit
·
3facca5
1
Parent(s):
2f86a37
first commit
Browse files- app.py +48 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
if os.environ.get("SPACES_ZERO_GPU") is not None:
|
| 3 |
+
import spaces
|
| 4 |
+
else:
|
| 5 |
+
class spaces:
|
| 6 |
+
@staticmethod
|
| 7 |
+
def GPU(func):
|
| 8 |
+
def wrapper(*args, **kwargs):
|
| 9 |
+
return func(*args, **kwargs)
|
| 10 |
+
return wrapper
|
| 11 |
+
|
| 12 |
+
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=80)
|
| 26 |
+
def generate_video(prompt):
|
| 27 |
+
# Generare i frame del video
|
| 28 |
+
frames = pipe(prompt, num_frames=84).frames[0]
|
| 29 |
+
|
| 30 |
+
# Esportare i frame come video
|
| 31 |
+
video_path = "mochi.mp4"
|
| 32 |
+
export_to_video(frames, video_path, fps=30)
|
| 33 |
+
|
| 34 |
+
return video_path
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
# Creare l'interfaccia Gradio
|
| 38 |
+
interface = gr.Interface(
|
| 39 |
+
fn=generate_video,
|
| 40 |
+
inputs="text",
|
| 41 |
+
outputs="video",
|
| 42 |
+
title="Mochi Video Generator",
|
| 43 |
+
description="Genera un video basato su un prompt di testo utilizzando MochiPipeline."
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# Avviare l'applicazione
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
interface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
accelerate
|
| 2 |
+
torch
|
| 3 |
+
gradio
|
| 4 |
+
transformers
|
| 5 |
+
git+https://github.com/huggingface/diffusers
|