Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,16 +4,23 @@ from diffusers import CogVideoXImageToVideoPipeline
|
|
| 4 |
from diffusers.utils import export_to_video, load_image
|
| 5 |
import torch
|
| 6 |
|
|
|
|
| 7 |
st.write("App started.")
|
| 8 |
|
| 9 |
# Streamlit interface
|
| 10 |
st.title("Image to Video with Hugging Face")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
uploaded_file = st.file_uploader("Upload an image (JPG or PNG):", type=["jpg", "jpeg", "png"])
|
| 12 |
prompt = st.text_input("Enter your prompt:", "A little girl is riding a bicycle at high speed. Focused, detailed, realistic.")
|
| 13 |
|
| 14 |
if uploaded_file and prompt:
|
| 15 |
try:
|
| 16 |
-
#
|
| 17 |
st.write(f"Uploaded file: {uploaded_file.name}")
|
| 18 |
st.write(f"Prompt: {prompt}")
|
| 19 |
|
|
@@ -28,18 +35,28 @@ if uploaded_file and prompt:
|
|
| 28 |
image = load_image("uploaded_image.jpg")
|
| 29 |
st.write("Image loaded successfully.")
|
| 30 |
|
| 31 |
-
# Initialize pipeline
|
| 32 |
st.write("Initializing the pipeline...")
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
pipe.enable_sequential_cpu_offload()
|
| 38 |
pipe.vae.enable_tiling()
|
| 39 |
pipe.vae.enable_slicing()
|
| 40 |
-
st.write("Pipeline initialized successfully.")
|
| 41 |
|
| 42 |
-
#
|
|
|
|
|
|
|
|
|
|
| 43 |
st.write("Generating video... This may take a while.")
|
| 44 |
video_frames = pipe(
|
| 45 |
prompt=prompt,
|
|
@@ -58,12 +75,14 @@ if uploaded_file and prompt:
|
|
| 58 |
export_to_video(video_frames, video_path, fps=8)
|
| 59 |
st.write("Video exported successfully.")
|
| 60 |
|
| 61 |
-
# Display video
|
| 62 |
st.video(video_path)
|
| 63 |
|
| 64 |
except Exception as e:
|
| 65 |
st.error(f"An error occurred: {e}")
|
| 66 |
st.write(f"Debug info: {e}")
|
| 67 |
else:
|
|
|
|
| 68 |
st.write("Please upload an image and provide a prompt to get started.")
|
| 69 |
|
|
|
|
|
|
| 4 |
from diffusers.utils import export_to_video, load_image
|
| 5 |
import torch
|
| 6 |
|
| 7 |
+
# Debug: App started
|
| 8 |
st.write("App started.")
|
| 9 |
|
| 10 |
# Streamlit interface
|
| 11 |
st.title("Image to Video with Hugging Face")
|
| 12 |
+
st.write("Upload an image and provide a prompt to generate a video.")
|
| 13 |
+
|
| 14 |
+
# Debug: Waiting for user inputs
|
| 15 |
+
st.write("Waiting for image upload and prompt input...")
|
| 16 |
+
|
| 17 |
+
# File uploader for the input image
|
| 18 |
uploaded_file = st.file_uploader("Upload an image (JPG or PNG):", type=["jpg", "jpeg", "png"])
|
| 19 |
prompt = st.text_input("Enter your prompt:", "A little girl is riding a bicycle at high speed. Focused, detailed, realistic.")
|
| 20 |
|
| 21 |
if uploaded_file and prompt:
|
| 22 |
try:
|
| 23 |
+
# Debug: File and prompt received
|
| 24 |
st.write(f"Uploaded file: {uploaded_file.name}")
|
| 25 |
st.write(f"Prompt: {prompt}")
|
| 26 |
|
|
|
|
| 35 |
image = load_image("uploaded_image.jpg")
|
| 36 |
st.write("Image loaded successfully.")
|
| 37 |
|
| 38 |
+
# Initialize the CogVideoX pipeline
|
| 39 |
st.write("Initializing the pipeline...")
|
| 40 |
+
try:
|
| 41 |
+
pipe = CogVideoXImageToVideoPipeline.from_pretrained(
|
| 42 |
+
"THUDM/CogVideoX1.5-5B-I2V",
|
| 43 |
+
torch_dtype=torch.bfloat16
|
| 44 |
+
)
|
| 45 |
+
st.write("Pipeline initialized successfully.")
|
| 46 |
+
except Exception as e:
|
| 47 |
+
st.error("Error during pipeline initialization.")
|
| 48 |
+
st.write(f"Debug info: {e}")
|
| 49 |
+
raise e
|
| 50 |
+
|
| 51 |
+
# Enable optimizations for large models
|
| 52 |
pipe.enable_sequential_cpu_offload()
|
| 53 |
pipe.vae.enable_tiling()
|
| 54 |
pipe.vae.enable_slicing()
|
|
|
|
| 55 |
|
| 56 |
+
# Debug: Ready to generate video
|
| 57 |
+
st.write("Pipeline setup complete. Ready to generate video.")
|
| 58 |
+
|
| 59 |
+
# Generate the video
|
| 60 |
st.write("Generating video... This may take a while.")
|
| 61 |
video_frames = pipe(
|
| 62 |
prompt=prompt,
|
|
|
|
| 75 |
export_to_video(video_frames, video_path, fps=8)
|
| 76 |
st.write("Video exported successfully.")
|
| 77 |
|
| 78 |
+
# Display video in Streamlit
|
| 79 |
st.video(video_path)
|
| 80 |
|
| 81 |
except Exception as e:
|
| 82 |
st.error(f"An error occurred: {e}")
|
| 83 |
st.write(f"Debug info: {e}")
|
| 84 |
else:
|
| 85 |
+
# Debug: Waiting for inputs
|
| 86 |
st.write("Please upload an image and provide a prompt to get started.")
|
| 87 |
|
| 88 |
+
|