euler314 commited on
Commit
0a24f79
·
verified ·
1 Parent(s): cce8261

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -12
app.py CHANGED
@@ -738,6 +738,10 @@ def generate_manim_video(python_code, format_type, quality_preset, animation_spe
738
  full_output = []
739
  output_file_path = None
740
  mp4_output_path = None # Track MP4 output for GIF fallback
 
 
 
 
741
  total_frames = None
742
  current_frame = 0
743
 
@@ -749,29 +753,46 @@ def generate_manim_video(python_code, format_type, quality_preset, animation_spe
749
  full_output.append(line)
750
  log_placeholder.code("".join(full_output[-10:]))
751
 
752
- # Try to extract total frames information
753
- if "Render animations with total frames:" in line:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
754
  try:
755
  total_frames = int(line.split("Render animations with total frames:")[1].strip().split()[0])
756
  logger.info(f"Total frames to render: {total_frames}")
757
- except:
758
- pass
759
 
760
- # Update progress bar based on frame information or percentage
761
- if "Rendering frame" in line and total_frames:
762
  try:
763
  # Extract current frame number
764
  frame_match = re.search(r"Rendering frame (\d+)", line)
765
  if frame_match:
766
  current_frame = int(frame_match.group(1))
767
  # Calculate progress as current frame / total frames
768
- progress = min(0.99, current_frame / total_frames)
769
- progress_bar.progress(progress)
770
  # Update status with frame information
771
- status_placeholder.info(f"Rendering {scene_class}: Frame {current_frame}/{total_frames} ({int(progress*100)}%)")
772
- except:
773
- pass
774
- elif "%" in line:
775
  try:
776
  # Fallback to percentage if available
777
  percent = float(line.split("%")[0].strip().split()[-1])
@@ -816,6 +837,8 @@ def generate_manim_video(python_code, format_type, quality_preset, animation_spe
816
  # IMPORTANT: Wait a moment for file system to catch up
817
  time.sleep(3)
818
 
 
 
819
  # Special handling for GIF format - if Manim failed to generate a GIF but we have an MP4
820
  if format_type == "gif" and (not output_file_path or not os.path.exists(output_file_path)) and mp4_output_path and os.path.exists(mp4_output_path):
821
  status_placeholder.info("GIF generation via Manim failed. Trying FFmpeg conversion...")
 
738
  full_output = []
739
  output_file_path = None
740
  mp4_output_path = None # Track MP4 output for GIF fallback
741
+
742
+ # Animation tracking variables
743
+ total_animations = None
744
+ current_animation = 0
745
  total_frames = None
746
  current_frame = 0
747
 
 
753
  full_output.append(line)
754
  log_placeholder.code("".join(full_output[-10:]))
755
 
756
+ # Try to detect total animations
757
+ if "Rendering animation number" in line or "Processing animation" in line:
758
+ try:
759
+ # Extract current animation number
760
+ anim_match = re.search(r"(?:Rendering animation number|Processing animation) (\d+) (?:out of|/) (\d+)", line)
761
+ if anim_match:
762
+ current_animation = int(anim_match.group(1))
763
+ total_animations = int(anim_match.group(2))
764
+ logger.info(f"Animation progress: {current_animation}/{total_animations}")
765
+
766
+ # Calculate progress based on animations
767
+ animation_progress = current_animation / total_animations
768
+ progress_bar.progress(animation_progress)
769
+ status_placeholder.info(f"Rendering {scene_class}: Animation {current_animation}/{total_animations} ({int(animation_progress*100)}%)")
770
+ except Exception as e:
771
+ logger.error(f"Error parsing animation progress: {str(e)}")
772
+
773
+ # Try to extract total frames information as fallback
774
+ elif "Render animations with total frames:" in line and not total_animations:
775
  try:
776
  total_frames = int(line.split("Render animations with total frames:")[1].strip().split()[0])
777
  logger.info(f"Total frames to render: {total_frames}")
778
+ except Exception as e:
779
+ logger.error(f"Error parsing total frames: {str(e)}")
780
 
781
+ # Update progress bar based on frame information if animation count not available
782
+ elif "Rendering frame" in line and total_frames and not total_animations:
783
  try:
784
  # Extract current frame number
785
  frame_match = re.search(r"Rendering frame (\d+)", line)
786
  if frame_match:
787
  current_frame = int(frame_match.group(1))
788
  # Calculate progress as current frame / total frames
789
+ frame_progress = min(0.99, current_frame / total_frames)
790
+ progress_bar.progress(frame_progress)
791
  # Update status with frame information
792
+ status_placeholder.info(f"Rendering {scene_class}: Frame {current_frame}/{total_frames} ({int(frame_progress*100)}%)")
793
+ except Exception as e:
794
+ logger.error(f"Error parsing frame progress: {str(e)}")
795
+ elif "%" in line and not total_animations and not total_frames:
796
  try:
797
  # Fallback to percentage if available
798
  percent = float(line.split("%")[0].strip().split()[-1])
 
837
  # IMPORTANT: Wait a moment for file system to catch up
838
  time.sleep(3)
839
 
840
+ # Rest of the function remains the same
841
+
842
  # Special handling for GIF format - if Manim failed to generate a GIF but we have an MP4
843
  if format_type == "gif" and (not output_file_path or not os.path.exists(output_file_path)) and mp4_output_path and os.path.exists(mp4_output_path):
844
  status_placeholder.info("GIF generation via Manim failed. Trying FFmpeg conversion...")