Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import torch
|
4 |
-
from
|
5 |
import numpy as np
|
6 |
import io
|
7 |
|
@@ -18,8 +18,7 @@ st.write("Upload an image to generate a video. You can also adjust settings for
|
|
18 |
@st.cache_resource
|
19 |
def load_model():
|
20 |
model_id = "stabilityai/stable-video-diffusion-img2vid-xt"
|
21 |
-
|
22 |
-
pipe = pipeline("image-to-video", model=model_id, torch_dtype=torch.float16).to("cuda")
|
23 |
return pipe
|
24 |
|
25 |
pipe = load_model()
|
@@ -31,22 +30,26 @@ uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "pn
|
|
31 |
frame_count = st.slider("Number of frames", min_value=10, max_value=50, value=25, step=5)
|
32 |
|
33 |
if uploaded_image is not None:
|
34 |
-
image = Image.open(uploaded_image)
|
35 |
st.image(image, caption='Uploaded Image', use_column_width=True)
|
36 |
|
37 |
if st.button('Generate Video'):
|
38 |
# ุชุญููู ุงูุตูุฑุฉ ุฅูู ููุฏูู
|
39 |
with st.spinner("Generating video..."):
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
42 |
st.success("Video generated successfully!")
|
43 |
|
44 |
# ุนุฑุถ ุงูููุฏูู
|
45 |
-
st.video(video_frames[0], format="video/mp4")
|
46 |
-
|
47 |
-
# ุชูุฒูู ุงูููุฏูู
|
48 |
video_bytes = io.BytesIO()
|
49 |
video_frames[0].save(video_bytes, format="mp4")
|
|
|
|
|
|
|
50 |
st.download_button(label="Download Video", data=video_bytes.getvalue(), file_name="generated_video.mp4", mime="video/mp4")
|
51 |
|
52 |
# ุชูุฏูู
ุจุนุถ ุงูู
ุนููู
ุงุช ุญูู ุงููู
ูุฐุฌ
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
import torch
|
4 |
+
from diffusers import DiffusionPipeline
|
5 |
import numpy as np
|
6 |
import io
|
7 |
|
|
|
18 |
@st.cache_resource
|
19 |
def load_model():
|
20 |
model_id = "stabilityai/stable-video-diffusion-img2vid-xt"
|
21 |
+
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
|
|
|
22 |
return pipe
|
23 |
|
24 |
pipe = load_model()
|
|
|
30 |
frame_count = st.slider("Number of frames", min_value=10, max_value=50, value=25, step=5)
|
31 |
|
32 |
if uploaded_image is not None:
|
33 |
+
image = Image.open(uploaded_image).convert("RGB")
|
34 |
st.image(image, caption='Uploaded Image', use_column_width=True)
|
35 |
|
36 |
if st.button('Generate Video'):
|
37 |
# ุชุญููู ุงูุตูุฑุฉ ุฅูู ููุฏูู
|
38 |
with st.spinner("Generating video..."):
|
39 |
+
# ุชุญููู ุงูุตูุฑุฉ ุฅูู tensor
|
40 |
+
image_tensor = torch.tensor(np.array(image)).float().unsqueeze(0).permute(0, 3, 1, 2).to("cuda") / 255.0
|
41 |
+
|
42 |
+
# ุชูููุฏ ุงูููุฏูู
|
43 |
+
video_frames = pipe(image_tensor, num_frames=frame_count).images
|
44 |
+
|
45 |
st.success("Video generated successfully!")
|
46 |
|
47 |
# ุนุฑุถ ุงูููุฏูู
|
|
|
|
|
|
|
48 |
video_bytes = io.BytesIO()
|
49 |
video_frames[0].save(video_bytes, format="mp4")
|
50 |
+
st.video(video_bytes, format="video/mp4")
|
51 |
+
|
52 |
+
# ุชูุฒูู ุงูููุฏูู
|
53 |
st.download_button(label="Download Video", data=video_bytes.getvalue(), file_name="generated_video.mp4", mime="video/mp4")
|
54 |
|
55 |
# ุชูุฏูู
ุจุนุถ ุงูู
ุนููู
ุงุช ุญูู ุงููู
ูุฐุฌ
|