nalin0503 commited on
Commit
c811f4d
·
1 Parent(s): 73d6948

Update app.py to freeze on running once

Browse files
Files changed (1) hide show
  1. app.py +22 -79
app.py CHANGED
@@ -157,22 +157,6 @@ def main():
157
  padding-left: 1rem;
158
  margin-left: 1rem;
159
  }
160
- /* Processing overlay */
161
- .processing-overlay {
162
- position: fixed;
163
- top: 0;
164
- left: 0;
165
- right: 0;
166
- bottom: 0;
167
- background-color: rgba(0, 0, 0, 0.7);
168
- z-index: 1000;
169
- display: flex;
170
- flex-direction: column;
171
- justify-content: center;
172
- align-items: center;
173
- color: white;
174
- font-size: 1.5rem;
175
- }
176
  </style>
177
  """,
178
  unsafe_allow_html=True
@@ -231,24 +215,13 @@ def main():
231
 
232
  # Add a restart button to clear the session state and start over
233
  if st.button("Start New Morphing Project", key="restart"):
234
- restart() # Use the restart function
235
-
236
  except Exception as e:
237
  st.error(f"Error preparing video for download: {e}")
238
 
239
  # Early return to not show the input forms again when we have a result
240
  return
241
 
242
- # Show processing indicator if currently processing
243
- if st.session_state.processing:
244
- progress_container = st.container()
245
- with progress_container:
246
- st.info("Processing your morphing request. Please wait...")
247
- progress_bar = st.progress(0)
248
- status_text = st.empty()
249
- status_text.text("Initializing pipeline. Please do not close this page.")
250
- st.warning("⚠️ Please wait for the current process to complete. Do not press the run button again.")
251
-
252
  # ---------------- SECTION 1: IMAGE & PROMPT INPUTS ----------------
253
  st.subheader("1. Upload Source Images & Prompts")
254
  st.markdown("**Note:** Your uploaded images must be of similar topology and same size to achieve the best results.")
@@ -380,7 +353,6 @@ def main():
380
 
381
  # Create a container for the run button and its status messages
382
  run_container = st.container()
383
-
384
  with run_container:
385
  # Button text changes based on processing state
386
  button_text = "Processing... Please Wait" if st.session_state.processing else "Run Morphing Pipeline"
@@ -393,11 +365,6 @@ def main():
393
  # Set the processing state to True to prevent multiple runs
394
  st.session_state.processing = True
395
 
396
- # Create progress indicators
397
- progress_bar = st.progress(0)
398
- status_text = st.empty()
399
- status_text.text("Initializing pipeline. This may take a few minutes...")
400
-
401
  # Instead of using /tmp, create a folder in the repo for temporary processing.
402
  temp_dir = create_temp_folder()
403
  st.session_state.temp_dir = temp_dir
@@ -448,57 +415,33 @@ def main():
448
  # Add film recursion parameter
449
  cmd.extend(["--film_num_recursions", str(film_recursions)])
450
 
451
- # If SLAB execution is enabled, prepend the srun command prefix.
452
- # if using_slab:
453
- # slab_prefix = [
454
- # "srun", "-p", "rtx3090_slab", "-w", "slabgpu05", "--gres=gpu:1",
455
- # "--job-name=test", "--kill-on-bad-exit=1"
456
- # ]
457
- # cmd = slab_prefix + cmd
458
 
459
- # Update progress status for preparing phase
460
- progress_bar.progress(10)
461
- status_text.text("Preparing images and configuration...")
 
 
462
 
463
- # Run the morphing process
464
- try:
465
- subprocess.run(cmd, check=True)
466
-
467
- # Update progress
468
- progress_bar.progress(90)
469
- status_text.text("Processing complete! Preparing results...")
470
-
471
- # Check for output video
472
- video_found = False
473
- possible_outputs = [f for f in os.listdir(film_output_dir) if f.endswith(".mp4")]
474
  if possible_outputs:
475
- final_video_path = os.path.join(film_output_dir, possible_outputs[0])
476
  video_found = True
477
-
478
- if not video_found:
479
- possible_outputs = [f for f in os.listdir(output_dir) if f.endswith(".mp4")]
480
- if possible_outputs:
481
- final_video_path = os.path.join(output_dir, possible_outputs[0])
482
- video_found = True
483
-
484
- if video_found:
485
- st.session_state.final_video_path = final_video_path
486
- st.session_state.process_complete = True
487
-
488
- # Set progress to 100%
489
- progress_bar.progress(100)
490
-
491
- st.rerun()
492
- else:
493
- status_text.warning("No output video was generated. Check logs for details.")
494
- st.session_state.processing = False
495
- st.session_state.process_complete = False
496
-
497
- except subprocess.CalledProcessError as e:
498
- st.error(f"Error running morphing pipeline: {e}")
499
  st.session_state.processing = False
500
  st.session_state.process_complete = False
501
-
 
 
 
 
502
  except Exception as e:
503
  st.error(f"An error occurred during processing: {e}")
504
  st.session_state.processing = False
 
157
  padding-left: 1rem;
158
  margin-left: 1rem;
159
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  </style>
161
  """,
162
  unsafe_allow_html=True
 
215
 
216
  # Add a restart button to clear the session state and start over
217
  if st.button("Start New Morphing Project", key="restart"):
218
+ restart()
 
219
  except Exception as e:
220
  st.error(f"Error preparing video for download: {e}")
221
 
222
  # Early return to not show the input forms again when we have a result
223
  return
224
 
 
 
 
 
 
 
 
 
 
 
225
  # ---------------- SECTION 1: IMAGE & PROMPT INPUTS ----------------
226
  st.subheader("1. Upload Source Images & Prompts")
227
  st.markdown("**Note:** Your uploaded images must be of similar topology and same size to achieve the best results.")
 
353
 
354
  # Create a container for the run button and its status messages
355
  run_container = st.container()
 
356
  with run_container:
357
  # Button text changes based on processing state
358
  button_text = "Processing... Please Wait" if st.session_state.processing else "Run Morphing Pipeline"
 
365
  # Set the processing state to True to prevent multiple runs
366
  st.session_state.processing = True
367
 
 
 
 
 
 
368
  # Instead of using /tmp, create a folder in the repo for temporary processing.
369
  temp_dir = create_temp_folder()
370
  st.session_state.temp_dir = temp_dir
 
415
  # Add film recursion parameter
416
  cmd.extend(["--film_num_recursions", str(film_recursions)])
417
 
418
+ subprocess.run(cmd, check=True)
 
 
 
 
 
 
419
 
420
+ possible_outputs = [f for f in os.listdir(film_output_dir) if f.endswith(".mp4")]
421
+ video_found = False
422
+ if possible_outputs:
423
+ final_video_path = os.path.join(film_output_dir, possible_outputs[0])
424
+ video_found = True
425
 
426
+ if not video_found:
427
+ possible_outputs = [f for f in os.listdir(output_dir) if f.endswith(".mp4")]
 
 
 
 
 
 
 
 
 
428
  if possible_outputs:
429
+ final_video_path = os.path.join(output_dir, possible_outputs[0])
430
  video_found = True
431
+
432
+ if video_found:
433
+ st.session_state.final_video_path = final_video_path
434
+ st.session_state.process_complete = True
435
+ st.rerun()
436
+ else:
437
+ st.error("No output video was generated. Check logs for details.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
438
  st.session_state.processing = False
439
  st.session_state.process_complete = False
440
+
441
+ except subprocess.CalledProcessError as e:
442
+ st.error(f"Error running morphing pipeline: {e}")
443
+ st.session_state.processing = False
444
+ st.session_state.process_complete = False
445
  except Exception as e:
446
  st.error(f"An error occurred during processing: {e}")
447
  st.session_state.processing = False