Process a single scene using CodeGenerator and VideoRenderer. Args: i (int): Scene index scene_outline (str): Overall scene outline scene_implementation (str): Implementation plan for this scene topic (str): The topic of the video
(self, i: int, scene_outline: str, scene_implementation: str, topic: str, description: str, max_retries: int, file_prefix: str, session_id: str, scene_trace_id: str)
| 333 | await asyncio.gather(*tasks) |
| 334 | |
| 335 | async def process_scene(self, i: int, scene_outline: str, scene_implementation: str, topic: str, description: str, max_retries: int, file_prefix: str, session_id: str, scene_trace_id: str): # added scene_trace_id |
| 336 | """ |
| 337 | Process a single scene using CodeGenerator and VideoRenderer. |
| 338 | |
| 339 | Args: |
| 340 | i (int): Scene index |
| 341 | scene_outline (str): Overall scene outline |
| 342 | scene_implementation (str): Implementation plan for this scene |
| 343 | topic (str): The topic of the video |
| 344 | description (str): Description of the video content |
| 345 | max_retries (int): Maximum number of code fix attempts |
| 346 | file_prefix (str): Prefix for file naming |
| 347 | session_id (str): Session identifier for tracking |
| 348 | scene_trace_id (str): Trace identifier for this scene |
| 349 | """ |
| 350 | curr_scene = i + 1 |
| 351 | curr_version = 0 |
| 352 | # scene_trace_id = str(uuid.uuid4()) # Remove uuid generation |
| 353 | rag_queries_cache = {} # Initialize RAG queries cache |
| 354 | |
| 355 | # Create necessary directories |
| 356 | code_dir = os.path.join(self.output_dir, file_prefix, f"scene{curr_scene}", "code") |
| 357 | os.makedirs(code_dir, exist_ok=True) |
| 358 | media_dir = os.path.join(self.output_dir, file_prefix, "media") # Define media_dir here |
| 359 | |
| 360 | async with self.scene_semaphore: |
| 361 | # Step 3A: Generate initial manim code |
| 362 | code, log = self.code_generator.generate_manim_code( |
| 363 | topic=topic, |
| 364 | description=description, |
| 365 | scene_outline=scene_outline, |
| 366 | scene_implementation=scene_implementation, |
| 367 | scene_number=curr_scene, |
| 368 | additional_context=[_prompt_manim_cheatsheet, _code_font_size, _code_limit, _code_disable], |
| 369 | scene_trace_id=scene_trace_id, # Use passed scene_trace_id |
| 370 | session_id=session_id, |
| 371 | rag_queries_cache=rag_queries_cache # Pass the cache |
| 372 | ) |
| 373 | |
| 374 | # Save initial code and log (file operations can be offloaded if needed) |
| 375 | with open(os.path.join(code_dir, f"{file_prefix}_scene{curr_scene}_v{curr_version}_init_log.txt"), "w") as f: |
| 376 | f.write(log) |
| 377 | with open(os.path.join(code_dir, f"{file_prefix}_scene{curr_scene}_v{curr_version}.py"), "w") as f: |
| 378 | f.write(code) |
| 379 | print(f"Code saved to {code_dir}/{file_prefix}_scene{curr_scene}_v{curr_version}.py") |
| 380 | |
| 381 | # Step 3B: Compile and fix code if needed |
| 382 | error_message = None |
| 383 | while True: # Retry loop controlled by break statements |
| 384 | code, error_message = await self.video_renderer.render_scene( |
| 385 | code=code, |
| 386 | file_prefix=file_prefix, |
| 387 | curr_scene=curr_scene, |
| 388 | curr_version=curr_version, |
| 389 | code_dir=code_dir, |
| 390 | media_dir=media_dir, |
| 391 | max_retries=max_retries, # Pass max_retries here if needed in render_scene |
| 392 | use_visual_fix_code=self.use_visual_fix_code, |
no test coverage detected