Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -13,42 +13,50 @@ pipe = AnimateDiffPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
|
13 |
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
14 |
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
15 |
|
16 |
-
#
|
17 |
def estimate_time(num_frames):
|
18 |
-
|
19 |
-
|
|
|
|
|
20 |
|
21 |
-
|
|
|
|
|
|
|
22 |
def generate_video(image, prompt, num_frames, email):
|
23 |
status = "Generating..."
|
24 |
progress = 0
|
25 |
|
26 |
image = image.convert("RGB").resize((512, 512))
|
27 |
-
|
28 |
-
#
|
29 |
for i in range(3):
|
30 |
time.sleep(0.8)
|
31 |
progress += 30
|
32 |
|
|
|
33 |
result = pipe(prompt=prompt, image=image, num_frames=num_frames, guidance_scale=7.5)
|
34 |
frames = result.frames
|
35 |
|
|
|
36 |
video_path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
|
37 |
imageio.mimsave(video_path, frames, fps=8)
|
38 |
|
|
|
39 |
final_message = f"β
Done! Generated {num_frames} frames."
|
40 |
if email:
|
41 |
-
final_message += f" Notification would be sent to: {email} (simulated)"
|
42 |
-
|
43 |
-
return video_path, final_message, gr.update(
|
44 |
|
45 |
-
#
|
46 |
with gr.Blocks() as demo:
|
47 |
gr.Markdown("# π Image + Prompt to Video Generator")
|
48 |
-
|
49 |
with gr.Row():
|
50 |
-
image_input = gr.Image(type="pil", label="Upload Image")
|
51 |
-
prompt_input = gr.Textbox(label="Describe Motion (Prompt)")
|
52 |
|
53 |
with gr.Row():
|
54 |
num_frames_slider = gr.Slider(8, 32, value=16, step=8, label="ποΈ Number of Frames")
|
@@ -56,7 +64,7 @@ with gr.Blocks() as demo:
|
|
56 |
|
57 |
email_input = gr.Textbox(label="π§ Optional Email (Notify when done)")
|
58 |
generate_btn = gr.Button("π¬ Generate Video")
|
59 |
-
|
60 |
with gr.Row():
|
61 |
status_output = gr.Textbox(label="π Status", interactive=False)
|
62 |
progress_bar = gr.Slider(0, 100, value=0, label="π Progress", interactive=False)
|
@@ -70,7 +78,11 @@ with gr.Blocks() as demo:
|
|
70 |
generate_btn.click(
|
71 |
fn=generate_video,
|
72 |
inputs=[image_input, prompt_input, num_frames_slider, email_input],
|
73 |
-
outputs=[video_output, status_output,
|
74 |
)
|
75 |
|
|
|
|
|
|
|
|
|
76 |
demo.launch()
|
|
|
13 |
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
14 |
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
15 |
|
16 |
+
# Estimate time based on device
|
17 |
def estimate_time(num_frames):
|
18 |
+
if torch.cuda.is_available():
|
19 |
+
time_per_frame = 2.5 # GPU
|
20 |
+
else:
|
21 |
+
time_per_frame = 12.0 # CPU
|
22 |
|
23 |
+
est_seconds = int(num_frames * time_per_frame)
|
24 |
+
return f"Estimated time: ~{est_seconds} seconds ({'GPU' if torch.cuda.is_available() else 'CPU'})"
|
25 |
+
|
26 |
+
# Video generation function with simulated progress
|
27 |
def generate_video(image, prompt, num_frames, email):
|
28 |
status = "Generating..."
|
29 |
progress = 0
|
30 |
|
31 |
image = image.convert("RGB").resize((512, 512))
|
32 |
+
|
33 |
+
# Simulated progress before real generation
|
34 |
for i in range(3):
|
35 |
time.sleep(0.8)
|
36 |
progress += 30
|
37 |
|
38 |
+
# Generate animation frames
|
39 |
result = pipe(prompt=prompt, image=image, num_frames=num_frames, guidance_scale=7.5)
|
40 |
frames = result.frames
|
41 |
|
42 |
+
# Save video
|
43 |
video_path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
|
44 |
imageio.mimsave(video_path, frames, fps=8)
|
45 |
|
46 |
+
# Build message
|
47 |
final_message = f"β
Done! Generated {num_frames} frames."
|
48 |
if email:
|
49 |
+
final_message += f"\nπ§ Notification would be sent to: {email} (simulated)"
|
50 |
+
|
51 |
+
return video_path, final_message, gr.update(value=100), gr.update(visible=True, value=video_path)
|
52 |
|
53 |
+
# UI layout
|
54 |
with gr.Blocks() as demo:
|
55 |
gr.Markdown("# π Image + Prompt to Video Generator")
|
56 |
+
|
57 |
with gr.Row():
|
58 |
+
image_input = gr.Image(type="pil", label="πΌοΈ Upload Image")
|
59 |
+
prompt_input = gr.Textbox(label="βοΈ Describe Motion (Prompt)")
|
60 |
|
61 |
with gr.Row():
|
62 |
num_frames_slider = gr.Slider(8, 32, value=16, step=8, label="ποΈ Number of Frames")
|
|
|
64 |
|
65 |
email_input = gr.Textbox(label="π§ Optional Email (Notify when done)")
|
66 |
generate_btn = gr.Button("π¬ Generate Video")
|
67 |
+
|
68 |
with gr.Row():
|
69 |
status_output = gr.Textbox(label="π Status", interactive=False)
|
70 |
progress_bar = gr.Slider(0, 100, value=0, label="π Progress", interactive=False)
|
|
|
78 |
generate_btn.click(
|
79 |
fn=generate_video,
|
80 |
inputs=[image_input, prompt_input, num_frames_slider, email_input],
|
81 |
+
outputs=[video_output, status_output, progress_bar, download_button]
|
82 |
)
|
83 |
|
84 |
+
# Optional warning if on CPU
|
85 |
+
if not torch.cuda.is_available():
|
86 |
+
gr.Markdown("β οΈ **Warning: Running on CPU. Generation will be slow!**")
|
87 |
+
|
88 |
demo.launch()
|