Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,35 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import torch
|
| 4 |
from diffusers.utils import load_image
|
| 5 |
|
|
|
|
| 6 |
try:
|
| 7 |
from diffusers import CogVideoXImageToVideoPipeline
|
| 8 |
pipeline_available = True
|
| 9 |
except ImportError:
|
| 10 |
pipeline_available = False
|
| 11 |
-
st.error(
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
st.title("Image to Video with Hugging Face")
|
| 14 |
st.write("Upload an image and provide a prompt to generate a video.")
|
| 15 |
|
| 16 |
if pipeline_available:
|
| 17 |
-
uploaded_file = st.file_uploader(
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
if uploaded_file and prompt:
|
| 21 |
try:
|
| 22 |
# Save uploaded file
|
| 23 |
-
import uuid
|
| 24 |
file_name = f"{uuid.uuid4()}_uploaded_image.jpg"
|
| 25 |
with open(file_name, "wb") as f:
|
| 26 |
f.write(uploaded_file.read())
|
|
@@ -40,21 +49,25 @@ if pipeline_available:
|
|
| 40 |
pipe.vae.enable_tiling()
|
| 41 |
pipe.vae.enable_slicing()
|
| 42 |
|
| 43 |
-
|
| 44 |
# Generate video
|
| 45 |
with st.spinner("Generating video... This may take a while."):
|
| 46 |
try:
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
| 60 |
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import uuid
|
| 3 |
import streamlit as st
|
| 4 |
import torch
|
| 5 |
from diffusers.utils import load_image
|
| 6 |
|
| 7 |
+
# Versuch, die Pipeline zu importieren
|
| 8 |
try:
|
| 9 |
from diffusers import CogVideoXImageToVideoPipeline
|
| 10 |
pipeline_available = True
|
| 11 |
except ImportError:
|
| 12 |
pipeline_available = False
|
| 13 |
+
st.error(
|
| 14 |
+
"Failed to import `CogVideoXImageToVideoPipeline`. "
|
| 15 |
+
"Please run `pip install diffusers`."
|
| 16 |
+
)
|
| 17 |
|
| 18 |
st.title("Image to Video with Hugging Face")
|
| 19 |
st.write("Upload an image and provide a prompt to generate a video.")
|
| 20 |
|
| 21 |
if pipeline_available:
|
| 22 |
+
uploaded_file = st.file_uploader(
|
| 23 |
+
"Upload an image (JPG or PNG):", type=["jpg", "jpeg", "png"]
|
| 24 |
+
)
|
| 25 |
+
prompt = st.text_input(
|
| 26 |
+
"Enter your prompt:",
|
| 27 |
+
"A little girl is riding a bicycle at high speed. Focused, detailed, realistic."
|
| 28 |
+
)
|
| 29 |
|
| 30 |
if uploaded_file and prompt:
|
| 31 |
try:
|
| 32 |
# Save uploaded file
|
|
|
|
| 33 |
file_name = f"{uuid.uuid4()}_uploaded_image.jpg"
|
| 34 |
with open(file_name, "wb") as f:
|
| 35 |
f.write(uploaded_file.read())
|
|
|
|
| 49 |
pipe.vae.enable_tiling()
|
| 50 |
pipe.vae.enable_slicing()
|
| 51 |
|
|
|
|
| 52 |
# Generate video
|
| 53 |
with st.spinner("Generating video... This may take a while."):
|
| 54 |
try:
|
| 55 |
+
# Attempt to generate the video
|
| 56 |
+
video_frames = pipe(
|
| 57 |
+
prompt=prompt,
|
| 58 |
+
image=image,
|
| 59 |
+
num_videos_per_prompt=1,
|
| 60 |
+
num_inference_steps=50,
|
| 61 |
+
num_frames=81,
|
| 62 |
+
guidance_scale=6,
|
| 63 |
+
generator=torch.Generator(device=device).manual_seed(42),
|
| 64 |
+
).frames[0]
|
| 65 |
+
|
| 66 |
+
st.video(video_frames)
|
| 67 |
+
st.success("Video generated successfully!")
|
| 68 |
+
|
| 69 |
+
except Exception as e:
|
| 70 |
+
st.error(f"An error occurred during video generation: {e}")
|
| 71 |
|
| 72 |
+
except Exception as e:
|
| 73 |
+
st.error(f"An error occurred while processing the uploaded file: {e}")
|