Spaces:
Runtime error
Runtime error
kikopubisher
commited on
Commit
โข
7d89612
1
Parent(s):
5b062dc
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import DiffusionPipeline
|
4 |
+
from PIL import Image
|
5 |
+
import numpy as np
|
6 |
+
import io
|
7 |
+
|
8 |
+
# ุชุญู
ูู ุงููู
ูุฐุฌ
|
9 |
+
model_id = "stabilityai/stable-video-diffusion-img2vid"
|
10 |
+
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
|
11 |
+
|
12 |
+
def generate_video(image):
|
13 |
+
# ุชุญููู ุงูุตูุฑุฉ ุฅูู ุชูุณูุฑ
|
14 |
+
image_tensor = torch.tensor(np.array(image)).float().unsqueeze(0).permute(0, 3, 1, 2).to("cuda") / 255.0
|
15 |
+
|
16 |
+
# ุชูููุฏ ุงูููุฏูู
|
17 |
+
video_frames = pipe(image_tensor, num_frames=25).images # ุงูุชุฑุถูุง 25 ุฅุทุงุฑ ูุนุฏุฏ ุงูุชุฑุงุถู
|
18 |
+
|
19 |
+
# ุญูุธ ุงูููุฏูู ุงููุงุชุฌ ุฅูู ู
ูู
|
20 |
+
video_bytes = io.BytesIO()
|
21 |
+
video_frames[0].save(video_bytes, format="mp4") # ุงุญูุธ ุงูุฅุทุงุฑ ุงูุฃูู ูููุฏูู ููุฅุดุงุฑุฉ
|
22 |
+
|
23 |
+
return video_bytes.getvalue()
|
24 |
+
|
25 |
+
# ุฅุนุฏุงุฏ ูุงุฌูุฉ Gradio
|
26 |
+
interface = gr.Interface(
|
27 |
+
fn=generate_video,
|
28 |
+
inputs=gr.Image(type="pil", label="Upload an Image"),
|
29 |
+
outputs=gr.File(label="Download Video"),
|
30 |
+
title="Stable Video Diffusion - Image to Video",
|
31 |
+
description="Upload an image to generate a video using the Stable Video Diffusion model.",
|
32 |
+
)
|
33 |
+
|
34 |
+
# ุชุดุบูู ุงููุงุฌูุฉ
|
35 |
+
if __name__ == "__main__":
|
36 |
+
interface.launch()
|