Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -206,14 +206,14 @@ def main():
|
|
| 206 |
preset_option = st.selectbox(
|
| 207 |
"Select a preset for quality and inference time",
|
| 208 |
options=[
|
| 209 |
-
"Maximum quality,
|
| 210 |
"Medium quality, medium inference time βοΈ",
|
| 211 |
-
"Low quality,
|
| 212 |
"Creative morph π¨",
|
| 213 |
"Custom βοΈ"
|
| 214 |
],
|
| 215 |
index=0,
|
| 216 |
-
label_visibility="collapsed"
|
| 217 |
)
|
| 218 |
|
| 219 |
# Determine preset defaults based on selection
|
|
@@ -234,6 +234,7 @@ def main():
|
|
| 234 |
preset_film = True
|
| 235 |
preset_lcm = True
|
| 236 |
else:
|
|
|
|
| 237 |
preset_model = None
|
| 238 |
preset_film = None
|
| 239 |
preset_lcm = None
|
|
@@ -264,7 +265,6 @@ def main():
|
|
| 264 |
)
|
| 265 |
use_adain = st.checkbox("Use AdaIN", value=True, help="Adaptive Instance Normalization for improved generation")
|
| 266 |
use_reschedule = st.checkbox("Use reschedule sampling", value=True, help="Better sampling strategy")
|
| 267 |
-
keyframe_duration = st.number_input("Keyframe Duration (seconds, only if not using FILM)", min_value=0.01, max_value=5.0, value=0.1, step=0.01)
|
| 268 |
|
| 269 |
# Right Column: Inter-frame Interpolator Parameters (FILM)
|
| 270 |
with col_right:
|
|
@@ -272,9 +272,12 @@ def main():
|
|
| 272 |
st.markdown("##### Inter-frame Interpolator Parameters")
|
| 273 |
default_use_film = preset_film if preset_film is not None else True
|
| 274 |
use_film = st.checkbox("Use FILM interpolation", value=default_use_film, help="Frame Interpolation for Large Motion - creates smooth transitions")
|
| 275 |
-
film_fps = st.number_input("FILM FPS (1β120)", min_value=1, max_value=120, value=30, help="Output video frames per second")
|
| 276 |
film_recursions = st.number_input("FILM recursion passes (1β6)", min_value=1, max_value=6, value=3,
|
| 277 |
help="Higher values create more intermediate frames (smoother but slower)")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 279 |
|
| 280 |
st.markdown("<hr>", unsafe_allow_html=True)
|
|
@@ -283,7 +286,7 @@ def main():
|
|
| 283 |
st.subheader("3. Generate Morphing Video")
|
| 284 |
st.markdown("Once satisfied with your inputs, click below to start the process.")
|
| 285 |
|
| 286 |
-
#
|
| 287 |
# using_slab = st.checkbox("Using SLAB GPU Cluster?", value=False, help="If enabled, the pipeline command will be prefixed with SLAB cluster execution parameters.")
|
| 288 |
|
| 289 |
if st.button("Run Morphing Pipeline", key="run_pipeline"):
|
|
@@ -307,8 +310,6 @@ def main():
|
|
| 307 |
os.makedirs(output_dir, exist_ok=True)
|
| 308 |
os.makedirs(film_output_dir, exist_ok=True)
|
| 309 |
|
| 310 |
-
duration_ms = int(keyframe_duration * 1000)
|
| 311 |
-
|
| 312 |
actual_model_path = (
|
| 313 |
"lykon/dreamshaper-7" if model_option == "Dreamshaper-7 (fine-tuned SD V1-5)"
|
| 314 |
else "stabilityai/stable-diffusion-2-1-base" if model_option == "Base Stable Diffusion V2-1"
|
|
@@ -326,7 +327,7 @@ def main():
|
|
| 326 |
"--output_path", output_dir,
|
| 327 |
"--film_output_folder", film_output_dir,
|
| 328 |
"--num_frames", str(num_frames),
|
| 329 |
-
"--
|
| 330 |
]
|
| 331 |
|
| 332 |
if enable_lcm_lora:
|
|
@@ -338,9 +339,10 @@ def main():
|
|
| 338 |
if use_film:
|
| 339 |
cmd.append("--use_film")
|
| 340 |
|
| 341 |
-
|
| 342 |
cmd.extend(["--film_num_recursions", str(film_recursions)])
|
| 343 |
|
|
|
|
| 344 |
# if using_slab:
|
| 345 |
# slab_prefix = [
|
| 346 |
# "srun", "-p", "rtx3090_slab", "-w", "slabgpu05", "--gres=gpu:1",
|
|
@@ -351,22 +353,25 @@ def main():
|
|
| 351 |
st.info("Initializing pipeline. This may take a few minutes...")
|
| 352 |
progress_bar = st.progress(0)
|
| 353 |
status_text = st.empty()
|
| 354 |
-
|
|
|
|
| 355 |
for i in range(1, 11):
|
| 356 |
status_text.text(f"Step {i}/10: {'Preparing images' if i <= 2 else 'Generating keyframes' if i <= 6 else 'Interpolating frames' if i <= 9 else 'Finalizing video'}")
|
| 357 |
progress_bar.progress(i * 10)
|
| 358 |
|
| 359 |
-
if i == 3:
|
| 360 |
try:
|
| 361 |
subprocess.run(cmd, check=True)
|
| 362 |
except subprocess.CalledProcessError as e:
|
| 363 |
st.error(f"Error running morphing pipeline: {e}")
|
| 364 |
return
|
| 365 |
break
|
| 366 |
-
|
|
|
|
| 367 |
progress_bar.progress(100)
|
| 368 |
status_text.text("Processing complete!")
|
| 369 |
|
|
|
|
| 370 |
video_found = False
|
| 371 |
possible_outputs = [f for f in os.listdir(film_output_dir) if f.endswith(".mp4")]
|
| 372 |
if possible_outputs:
|
|
@@ -381,7 +386,7 @@ def main():
|
|
| 381 |
|
| 382 |
if video_found:
|
| 383 |
st.success("Morphing complete! π")
|
| 384 |
-
st.video(final_video_path)
|
| 385 |
try:
|
| 386 |
with open(final_video_path, "rb") as f:
|
| 387 |
video_bytes = f.read()
|
|
|
|
| 206 |
preset_option = st.selectbox(
|
| 207 |
"Select a preset for quality and inference time",
|
| 208 |
options=[
|
| 209 |
+
"Maximum quality, longest inference time π",
|
| 210 |
"Medium quality, medium inference time βοΈ",
|
| 211 |
+
"Low quality, shortest inference time β‘",
|
| 212 |
"Creative morph π¨",
|
| 213 |
"Custom βοΈ"
|
| 214 |
],
|
| 215 |
index=0,
|
| 216 |
+
label_visibility="collapsed" # Hide the label in the UI but keep it for accessibility
|
| 217 |
)
|
| 218 |
|
| 219 |
# Determine preset defaults based on selection
|
|
|
|
| 234 |
preset_film = True
|
| 235 |
preset_lcm = True
|
| 236 |
else:
|
| 237 |
+
# "Custom"
|
| 238 |
preset_model = None
|
| 239 |
preset_film = None
|
| 240 |
preset_lcm = None
|
|
|
|
| 265 |
)
|
| 266 |
use_adain = st.checkbox("Use AdaIN", value=True, help="Adaptive Instance Normalization for improved generation")
|
| 267 |
use_reschedule = st.checkbox("Use reschedule sampling", value=True, help="Better sampling strategy")
|
|
|
|
| 268 |
|
| 269 |
# Right Column: Inter-frame Interpolator Parameters (FILM)
|
| 270 |
with col_right:
|
|
|
|
| 272 |
st.markdown("##### Inter-frame Interpolator Parameters")
|
| 273 |
default_use_film = preset_film if preset_film is not None else True
|
| 274 |
use_film = st.checkbox("Use FILM interpolation", value=default_use_film, help="Frame Interpolation for Large Motion - creates smooth transitions")
|
|
|
|
| 275 |
film_recursions = st.number_input("FILM recursion passes (1β6)", min_value=1, max_value=6, value=3,
|
| 276 |
help="Higher values create more intermediate frames (smoother but slower)")
|
| 277 |
+
# Set default FPS based on whether FILM is enabled
|
| 278 |
+
default_fps = 30 if use_film else 4
|
| 279 |
+
output_fps = st.number_input("Output FPS (1β120)", min_value=1, max_value=120, value=default_fps,
|
| 280 |
+
help="Output video frames per second")
|
| 281 |
st.markdown("</div>", unsafe_allow_html=True)
|
| 282 |
|
| 283 |
st.markdown("<hr>", unsafe_allow_html=True)
|
|
|
|
| 286 |
st.subheader("3. Generate Morphing Video")
|
| 287 |
st.markdown("Once satisfied with your inputs, click below to start the process.")
|
| 288 |
|
| 289 |
+
# New checkbox for SLAB execution toggle
|
| 290 |
# using_slab = st.checkbox("Using SLAB GPU Cluster?", value=False, help="If enabled, the pipeline command will be prefixed with SLAB cluster execution parameters.")
|
| 291 |
|
| 292 |
if st.button("Run Morphing Pipeline", key="run_pipeline"):
|
|
|
|
| 310 |
os.makedirs(output_dir, exist_ok=True)
|
| 311 |
os.makedirs(film_output_dir, exist_ok=True)
|
| 312 |
|
|
|
|
|
|
|
| 313 |
actual_model_path = (
|
| 314 |
"lykon/dreamshaper-7" if model_option == "Dreamshaper-7 (fine-tuned SD V1-5)"
|
| 315 |
else "stabilityai/stable-diffusion-2-1-base" if model_option == "Base Stable Diffusion V2-1"
|
|
|
|
| 327 |
"--output_path", output_dir,
|
| 328 |
"--film_output_folder", film_output_dir,
|
| 329 |
"--num_frames", str(num_frames),
|
| 330 |
+
"--fps", str(output_fps)
|
| 331 |
]
|
| 332 |
|
| 333 |
if enable_lcm_lora:
|
|
|
|
| 339 |
if use_film:
|
| 340 |
cmd.append("--use_film")
|
| 341 |
|
| 342 |
+
# Add film recursion parameter
|
| 343 |
cmd.extend(["--film_num_recursions", str(film_recursions)])
|
| 344 |
|
| 345 |
+
# If SLAB execution is enabled, prepend the srun command prefix.
|
| 346 |
# if using_slab:
|
| 347 |
# slab_prefix = [
|
| 348 |
# "srun", "-p", "rtx3090_slab", "-w", "slabgpu05", "--gres=gpu:1",
|
|
|
|
| 353 |
st.info("Initializing pipeline. This may take a few minutes...")
|
| 354 |
progress_bar = st.progress(0)
|
| 355 |
status_text = st.empty()
|
| 356 |
+
|
| 357 |
+
# Update progress status
|
| 358 |
for i in range(1, 11):
|
| 359 |
status_text.text(f"Step {i}/10: {'Preparing images' if i <= 2 else 'Generating keyframes' if i <= 6 else 'Interpolating frames' if i <= 9 else 'Finalizing video'}")
|
| 360 |
progress_bar.progress(i * 10)
|
| 361 |
|
| 362 |
+
if i == 3: # Start processing!
|
| 363 |
try:
|
| 364 |
subprocess.run(cmd, check=True)
|
| 365 |
except subprocess.CalledProcessError as e:
|
| 366 |
st.error(f"Error running morphing pipeline: {e}")
|
| 367 |
return
|
| 368 |
break
|
| 369 |
+
|
| 370 |
+
# Set to 100% when done
|
| 371 |
progress_bar.progress(100)
|
| 372 |
status_text.text("Processing complete!")
|
| 373 |
|
| 374 |
+
# Check for output video
|
| 375 |
video_found = False
|
| 376 |
possible_outputs = [f for f in os.listdir(film_output_dir) if f.endswith(".mp4")]
|
| 377 |
if possible_outputs:
|
|
|
|
| 386 |
|
| 387 |
if video_found:
|
| 388 |
st.success("Morphing complete! π")
|
| 389 |
+
# st.video(final_video_path) # Comment to remove video preview, buggy
|
| 390 |
try:
|
| 391 |
with open(final_video_path, "rb") as f:
|
| 392 |
video_bytes = f.read()
|