Download app.py from cicint/appcinta: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/cicint/appcinta/resolve/main/app.py
- Command line
-
hf download hf://spaces/cicint/appcinta/app.py
-
curl -L -o app.py https://huggingface.co/spaces/cicint/appcinta/resolve/main/app.py
1.62 kB
| import gradio as gr | |
| from diffusers import DiffusionPipeline | |
| from PIL import Image | |
| from moviepy.editor import ImageSequenceClip | |
| import torch | |
| MODEL_ID = "Wan-AI/Wan2.1-I2V-5B" # versi publik yang aman | |
| def load_model(): | |
| device = "cuda" if torch.cuda.is_available() else "cpu" | |
| try: | |
| pipe = DiffusionPipeline.from_pretrained( | |
| MODEL_ID, | |
| torch_dtype=torch.float16 if device == "cuda" else torch.float32, | |
| ).to(device) | |
| return pipe | |
| except Exception as e: | |
| raise gr.Error(f"Gagal memuat model {MODEL_ID}: {e}") | |
| pipe = load_model() | |
| def generate_video(image, prompt=""): | |
| if image is None: | |
| raise gr.Error("Silakan upload gambar terlebih dahulu.") | |
| result = pipe( | |
| image=image, | |
| prompt=prompt, | |
| num_frames=49, | |
| height=480, | |
| width=832, | |
| guidance_scale=6.0, | |
| ) | |
| frames = result.frames | |
| clip = ImageSequenceClip(frames, fps=24) | |
| clip.write_videofile("output.mp4", codec="libx264", audio=False, verbose=False, logger=None) | |
| return "output.mp4" | |
| with gr.Blocks(theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("## 🎬 Wan-AI Image → Video (Space Demo)") | |
| image = gr.Image(label="Upload Gambar", type="pil") | |
| prompt = gr.Textbox(label="Prompt (opsional)", placeholder="contoh: kamera bergerak perlahan ke depan") | |
| video = gr.Video(label="Hasil Video", autoplay=True) | |
| generate = gr.Button("🎞️ Generate Video") | |
| generate.click(fn=generate_video, inputs=[image, prompt], outputs=video) | |
| if __name__ == "__main__": | |
| demo.launch() | |