kikopubisher commited on
Commit
96698ba
ยท
verified ยท
1 Parent(s): 045f3e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -12
app.py CHANGED
@@ -1,7 +1,7 @@
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,7 +18,8 @@ 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
- pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
 
22
  return pipe
23
 
24
  pipe = load_model()
@@ -30,26 +31,22 @@ uploaded_image = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "pn
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
  # ุชู‚ุฏูŠู… ุจุนุถ ุงู„ู…ุนู„ูˆู…ุงุช ุญูˆู„ ุงู„ู†ู…ูˆุฐุฌ
 
1
  import streamlit as st
2
  from PIL import Image
3
  import torch
4
+ from transformers import pipeline
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
+ # ุชุฃูƒุฏ ู…ู† ุงุณุชุฎุฏุงู… ุงู„ูƒู„ุงุณ ุงู„ุตุญูŠุญ ู…ู† ู…ูƒุชุจุฉ transformers ุฅุฐุง ูƒุงู† ู…ุชุงุญู‹ุง
22
+ pipe = pipeline("image-to-video", model=model_id, torch_dtype=torch.float16).to("cuda")
23
  return pipe
24
 
25
  pipe = load_model()
 
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
+ video_frames = pipe(image, num_frames=frame_count)
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
  # ุชู‚ุฏูŠู… ุจุนุถ ุงู„ู…ุนู„ูˆู…ุงุช ุญูˆู„ ุงู„ู†ู…ูˆุฐุฌ