Spaces:
Running
Running
nalin0503
commited on
Commit
Β·
d40dbb3
1
Parent(s):
4643ddf
bug fixes
Browse files
app.py
CHANGED
|
@@ -239,19 +239,12 @@ def main():
|
|
| 239 |
with col_left:
|
| 240 |
st.markdown("##### Keyframe Generator Parameters")
|
| 241 |
num_frames = st.number_input("Number of keyframes (2β50)", min_value=2, max_value=50, value=16)
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
)
|
| 249 |
-
else:
|
| 250 |
-
lcm_default = preset_lcm if preset_lcm is not None else False
|
| 251 |
-
enable_lcm_lora = st.checkbox(
|
| 252 |
-
"Enable LCM-LoRA (accelerated inference, slight decrease in quality)",
|
| 253 |
-
value=lcm_default
|
| 254 |
-
)
|
| 255 |
use_adain = st.checkbox("Use AdaIN", value=True)
|
| 256 |
use_reschedule = st.checkbox("Use reschedule sampling", value=True)
|
| 257 |
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)
|
|
@@ -275,24 +268,42 @@ def main():
|
|
| 275 |
st.error("Please upload both images before running the morphing pipeline.")
|
| 276 |
return
|
| 277 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
with tempfile.TemporaryDirectory() as temp_dir:
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
|
| 284 |
output_dir = os.path.join(temp_dir, "morph_results")
|
| 285 |
film_output_dir = os.path.join(temp_dir, "film_output")
|
| 286 |
os.makedirs(output_dir, exist_ok=True)
|
| 287 |
os.makedirs(film_output_dir, exist_ok=True)
|
| 288 |
|
| 289 |
-
#
|
| 290 |
duration_ms = int(keyframe_duration * 1000)
|
| 291 |
|
| 292 |
-
# Build the CLI command
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
cmd = [
|
| 294 |
sys.executable, "run_morphing.py",
|
| 295 |
-
"--model_path",
|
| 296 |
"--image_path_0", imgA_path,
|
| 297 |
"--image_path_1", imgB_path,
|
| 298 |
"--prompt_0", prompt_A,
|
|
@@ -301,7 +312,7 @@ def main():
|
|
| 301 |
"--film_output_folder", film_output_dir,
|
| 302 |
"--num_frames", str(num_frames),
|
| 303 |
"--duration", str(duration_ms)
|
| 304 |
-
] + (["--save_inter"] if use_film else [])
|
| 305 |
if enable_lcm_lora:
|
| 306 |
cmd.append("--use_lcm")
|
| 307 |
if use_adain:
|
|
@@ -314,13 +325,13 @@ def main():
|
|
| 314 |
cmd.extend(["--film_num_recursions", str(film_recursions)])
|
| 315 |
|
| 316 |
st.info("Initializing pipeline. Please wait...")
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
return
|
| 323 |
|
|
|
|
| 324 |
possible_outputs = [f for f in os.listdir(film_output_dir) if f.endswith(".mp4")]
|
| 325 |
if not possible_outputs:
|
| 326 |
possible_outputs = [f for f in os.listdir(output_dir) if f.endswith(".mp4")]
|
|
@@ -332,13 +343,16 @@ def main():
|
|
| 332 |
)
|
| 333 |
st.success("Morphing complete! π")
|
| 334 |
st.video(final_video_path)
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
|
|
|
|
|
|
|
|
|
| 342 |
else:
|
| 343 |
st.warning("No .mp4 output found. Check logs for details.")
|
| 344 |
|
|
|
|
| 239 |
with col_left:
|
| 240 |
st.markdown("##### Keyframe Generator Parameters")
|
| 241 |
num_frames = st.number_input("Number of keyframes (2β50)", min_value=2, max_value=50, value=16)
|
| 242 |
+
# Removed disabling for SD V2-1 so that LCM-LoRA can be enabled for it as well.
|
| 243 |
+
lcm_default = preset_lcm if preset_lcm is not None else False
|
| 244 |
+
enable_lcm_lora = st.checkbox(
|
| 245 |
+
"Enable LCM-LoRA (accelerated inference, slight decrease in quality)",
|
| 246 |
+
value=lcm_default
|
| 247 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
use_adain = st.checkbox("Use AdaIN", value=True)
|
| 249 |
use_reschedule = st.checkbox("Use reschedule sampling", value=True)
|
| 250 |
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 |
st.error("Please upload both images before running the morphing pipeline.")
|
| 269 |
return
|
| 270 |
|
| 271 |
+
# Check that the pipeline script exists
|
| 272 |
+
if not os.path.exists("run_morphing.py"):
|
| 273 |
+
st.error("Pipeline script 'run_morphing.py' not found in the current directory.")
|
| 274 |
+
return
|
| 275 |
+
|
| 276 |
with tempfile.TemporaryDirectory() as temp_dir:
|
| 277 |
+
try:
|
| 278 |
+
imgA_path = os.path.join(temp_dir, "imageA.png")
|
| 279 |
+
imgB_path = os.path.join(temp_dir, "imageB.png")
|
| 280 |
+
save_uploaded_file(uploaded_image_A, imgA_path)
|
| 281 |
+
save_uploaded_file(uploaded_image_B, imgB_path)
|
| 282 |
+
except Exception as e:
|
| 283 |
+
st.error(f"Error saving uploaded images: {e}")
|
| 284 |
+
return
|
| 285 |
|
| 286 |
output_dir = os.path.join(temp_dir, "morph_results")
|
| 287 |
film_output_dir = os.path.join(temp_dir, "film_output")
|
| 288 |
os.makedirs(output_dir, exist_ok=True)
|
| 289 |
os.makedirs(film_output_dir, exist_ok=True)
|
| 290 |
|
| 291 |
+
# Convert seconds to milliseconds
|
| 292 |
duration_ms = int(keyframe_duration * 1000)
|
| 293 |
|
| 294 |
+
# Build the CLI command
|
| 295 |
+
# Here you can add a mapping if you want to convert display names to actual model identifiers.
|
| 296 |
+
# For this example, we assume model_option is already a valid model identifier,
|
| 297 |
+
# or use a conditional similar to before.
|
| 298 |
+
actual_model_path = (
|
| 299 |
+
"lykon/dreamshaper-7" if model_option == "Dreamshaper-7 (fine-tuned SD V1-5)"
|
| 300 |
+
else "sd-legacy/stable-diffusion-v1-5" if model_option == "Base Stable Diffusion V1-5"
|
| 301 |
+
else "stabilityai/stable-diffusion-2-1-base"
|
| 302 |
+
)
|
| 303 |
+
|
| 304 |
cmd = [
|
| 305 |
sys.executable, "run_morphing.py",
|
| 306 |
+
"--model_path", actual_model_path,
|
| 307 |
"--image_path_0", imgA_path,
|
| 308 |
"--image_path_1", imgB_path,
|
| 309 |
"--prompt_0", prompt_A,
|
|
|
|
| 312 |
"--film_output_folder", film_output_dir,
|
| 313 |
"--num_frames", str(num_frames),
|
| 314 |
"--duration", str(duration_ms)
|
| 315 |
+
] + (["--save_inter"] if use_film else [])
|
| 316 |
if enable_lcm_lora:
|
| 317 |
cmd.append("--use_lcm")
|
| 318 |
if use_adain:
|
|
|
|
| 325 |
cmd.extend(["--film_num_recursions", str(film_recursions)])
|
| 326 |
|
| 327 |
st.info("Initializing pipeline. Please wait...")
|
| 328 |
+
try:
|
| 329 |
+
subprocess.run(cmd, check=True)
|
| 330 |
+
except subprocess.CalledProcessError as e:
|
| 331 |
+
st.error(f"Error running pipeline: {e}")
|
| 332 |
+
return
|
|
|
|
| 333 |
|
| 334 |
+
# Check for output file in FILM folder first; if not, then in output_dir
|
| 335 |
possible_outputs = [f for f in os.listdir(film_output_dir) if f.endswith(".mp4")]
|
| 336 |
if not possible_outputs:
|
| 337 |
possible_outputs = [f for f in os.listdir(output_dir) if f.endswith(".mp4")]
|
|
|
|
| 343 |
)
|
| 344 |
st.success("Morphing complete! π")
|
| 345 |
st.video(final_video_path)
|
| 346 |
+
try:
|
| 347 |
+
with open(final_video_path, "rb") as f:
|
| 348 |
+
st.download_button(
|
| 349 |
+
"Download Result Video",
|
| 350 |
+
data=f.read(),
|
| 351 |
+
file_name="morph_result.mp4",
|
| 352 |
+
mime="video/mp4"
|
| 353 |
+
)
|
| 354 |
+
except Exception as e:
|
| 355 |
+
st.error(f"Error reading output video: {e}")
|
| 356 |
else:
|
| 357 |
st.warning("No .mp4 output found. Check logs for details.")
|
| 358 |
|