Spaces:
Sleeping
Sleeping
update code
Browse files
app.py
CHANGED
@@ -2,19 +2,37 @@ import torch
|
|
2 |
import gradio as gr
|
3 |
from diffusers import DiffusionPipeline
|
4 |
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def generate_video(prompt):
|
|
|
|
|
|
|
9 |
try:
|
10 |
# Generate video frames
|
11 |
images = pipe(prompt).images
|
12 |
|
13 |
# Save the generated images as a video
|
14 |
-
# Note: This is a simplified version - you might want to use proper video encoding
|
15 |
output_path = "generated_video.mp4"
|
16 |
|
17 |
-
# Convert images to video
|
18 |
import imageio
|
19 |
imageio.mimsave(output_path, images, fps=5)
|
20 |
|
@@ -32,4 +50,7 @@ demo = gr.Interface(
|
|
32 |
)
|
33 |
|
34 |
if __name__ == "__main__":
|
35 |
-
|
|
|
|
|
|
|
|
2 |
import gradio as gr
|
3 |
from diffusers import DiffusionPipeline
|
4 |
|
5 |
+
def load_video_model():
|
6 |
+
try:
|
7 |
+
# Ensure all necessary libraries are imported
|
8 |
+
import sentencepiece
|
9 |
+
|
10 |
+
# Load the model with specific error handling
|
11 |
+
pipe = DiffusionPipeline.from_pretrained("Lightricks/LTX-Video")
|
12 |
+
return pipe
|
13 |
+
except ImportError as e:
|
14 |
+
print(f"Dependency Error: {e}")
|
15 |
+
print("Please install required libraries: pip install sentencepiece diffusers transformers torch gradio imageio")
|
16 |
+
return None
|
17 |
+
except Exception as e:
|
18 |
+
print(f"Error loading model: {e}")
|
19 |
+
return None
|
20 |
+
|
21 |
+
# Load the model when the script starts
|
22 |
+
pipe = load_video_model()
|
23 |
|
24 |
def generate_video(prompt):
|
25 |
+
if pipe is None:
|
26 |
+
return "Error: Model could not be loaded. Check your dependencies."
|
27 |
+
|
28 |
try:
|
29 |
# Generate video frames
|
30 |
images = pipe(prompt).images
|
31 |
|
32 |
# Save the generated images as a video
|
|
|
33 |
output_path = "generated_video.mp4"
|
34 |
|
35 |
+
# Convert images to video
|
36 |
import imageio
|
37 |
imageio.mimsave(output_path, images, fps=5)
|
38 |
|
|
|
50 |
)
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
+
if pipe is not None:
|
54 |
+
demo.launch()
|
55 |
+
else:
|
56 |
+
print("Could not launch app due to model loading failure.")
|