nalin0503 commited on
Commit
d40dbb3
Β·
1 Parent(s): 4643ddf
Files changed (1) hide show
  1. app.py +48 -34
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
- if model_option == "Base Stable Diffusion V2-1 (No LCM-LoRA support)":
243
- enable_lcm_lora = st.checkbox(
244
- "Enable LCM-LoRA (accelerated inference, slight decrease in quality)",
245
- value=False,
246
- disabled=True,
247
- help="LCM-LoRA is not available for the selected model card."
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
- imgA_path = os.path.join(temp_dir, "imageA.png")
280
- imgB_path = os.path.join(temp_dir, "imageB.png")
281
- save_uploaded_file(uploaded_image_A, imgA_path)
282
- save_uploaded_file(uploaded_image_B, imgB_path)
 
 
 
 
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
- # convert seconds to miliseconds...
290
  duration_ms = int(keyframe_duration * 1000)
291
 
292
- # Build the CLI command. Note: numeric parameters are converted to strings for CLI compatibility.
 
 
 
 
 
 
 
 
 
293
  cmd = [
294
  sys.executable, "run_morphing.py",
295
- "--model_path", model_option if model_option != "Dreamshaper-7 (fine-tuned SD V1-5)" else "lykon/dreamshaper-7",
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 []) # to ensure we have intermediate folder for FILM
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
- with st.spinner("Generating morph..."):
318
- try:
319
- subprocess.run(cmd, check=True)
320
- except subprocess.CalledProcessError as e:
321
- st.error(f"Error running pipeline: {e}")
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
- with open(final_video_path, "rb") as f:
336
- st.download_button(
337
- "Download Result Video",
338
- data=f.read(),
339
- file_name="morph_result.mp4",
340
- mime="video/mp4"
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