Update app.py
Browse files
app.py
CHANGED
|
@@ -2,32 +2,45 @@ import gradio as gr
|
|
| 2 |
import torch
|
| 3 |
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
| 4 |
from diffusers.utils import export_to_video
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
# Optimize for GPU memory
|
| 15 |
-
|
| 16 |
-
pipe.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def generate_video(prompt):
|
| 19 |
try:
|
|
|
|
| 20 |
# Generate video frames
|
| 21 |
video_frames = pipe(
|
| 22 |
prompt,
|
| 23 |
-
num_inference_steps=
|
| 24 |
-
num_frames=
|
| 25 |
).frames
|
| 26 |
-
|
| 27 |
# Export frames to video file
|
| 28 |
video_path = export_to_video(video_frames, output_video_path="output_video.mp4")
|
|
|
|
| 29 |
return video_path
|
| 30 |
except Exception as e:
|
|
|
|
| 31 |
return f"Error generating video: {str(e)}"
|
| 32 |
|
| 33 |
# Create Gradio interface
|
|
@@ -43,4 +56,6 @@ interface = gr.Interface(
|
|
| 43 |
)
|
| 44 |
|
| 45 |
# Launch the app
|
| 46 |
-
|
|
|
|
|
|
|
|
|
| 2 |
import torch
|
| 3 |
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
| 4 |
from diffusers.utils import export_to_video
|
| 5 |
+
import logging
|
| 6 |
|
| 7 |
+
# Set up logging
|
| 8 |
+
logging.basicConfig(level=logging.INFO)
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
# Initialize the diffusion pipeline
|
| 13 |
+
logger.info("Loading diffusion pipeline...")
|
| 14 |
+
pipe = DiffusionPipeline.from_pretrained(
|
| 15 |
+
"heboya8/text2video-test-2",
|
| 16 |
+
torch_dtype=torch.float16,
|
| 17 |
+
trust_remote_code=True,
|
| 18 |
+
)
|
| 19 |
|
| 20 |
+
# Optimize for GPU memory
|
| 21 |
+
logger.info("Enabling CPU offload and VAE slicing...")
|
| 22 |
+
pipe.enable_model_cpu_offload()
|
| 23 |
+
pipe.enable_vae_slicing()
|
| 24 |
+
except Exception as e:
|
| 25 |
+
logger.error(f"Failed to initialize pipeline: {str(e)}")
|
| 26 |
+
raise
|
| 27 |
|
| 28 |
def generate_video(prompt):
|
| 29 |
try:
|
| 30 |
+
logger.info(f"Generating video for prompt: {prompt}")
|
| 31 |
# Generate video frames
|
| 32 |
video_frames = pipe(
|
| 33 |
prompt,
|
| 34 |
+
num_inference_steps=50, # Increased for better quality
|
| 35 |
+
num_frames=16, # Increased for longer video
|
| 36 |
).frames
|
| 37 |
+
|
| 38 |
# Export frames to video file
|
| 39 |
video_path = export_to_video(video_frames, output_video_path="output_video.mp4")
|
| 40 |
+
logger.info(f"Video generated at: {video_path}")
|
| 41 |
return video_path
|
| 42 |
except Exception as e:
|
| 43 |
+
logger.error(f"Error generating video: {str(e)}")
|
| 44 |
return f"Error generating video: {str(e)}"
|
| 45 |
|
| 46 |
# Create Gradio interface
|
|
|
|
| 56 |
)
|
| 57 |
|
| 58 |
# Launch the app
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
logger.info("Launching Gradio interface...")
|
| 61 |
+
interface.launch(server_name="0.0.0.0", server_port=7860)
|