JahDaGanj commited on
Commit
1e98e33
·
verified ·
1 Parent(s): 62cd675

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -60
app.py DELETED
@@ -1,60 +0,0 @@
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("Failed to import `CogVideoXImageToVideoPipeline`. Please run `pip install diffusers`.")
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("Upload an image (JPG or PNG):", type=["jpg", "jpeg", "png"])
18
- prompt = st.text_input("Enter your prompt:", "A little girl is riding a bicycle at high speed. Focused, detailed, realistic.")
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())
27
- st.write("Uploaded image saved successfully.")
28
-
29
- # Load the image
30
- image = load_image(file_name)
31
-
32
- # Initialize pipeline
33
- device = "cuda" if torch.cuda.is_available() else "cpu"
34
- pipe = CogVideoXImageToVideoPipeline.from_pretrained(
35
- "THUDM/CogVideoX1.5-5B-I2V",
36
- torch_dtype=torch.bfloat16,
37
- cache_dir="./huggingface_cache",
38
- )
39
- pipe.enable_sequential_cpu_offload()
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
- # Attempt to generate the video
48
- video_frames = pipe(
49
- prompt=prompt,
50
- image=image,
51
- num_videos_per_prompt=1,
52
- num_inference_steps=50,
53
- num_frames=81,
54
- guidance_scale=6,
55
- generator=torch.Generator(device=device).manual_seed(42),
56
- ).frames[0]
57
- except Exception as e:
58
- # Handle errors gracefully
59
- st.error(f"An error occurred during video generation: {e}")
60
-