Spaces:
No application file
No application file
| #!/usr/bin/env python3 | |
| """ | |
| BACKUP of complex ui_function_wrapper that causes schema validation issues | |
| This is the original function from app_backup.py that triggers: | |
| TypeError: argument of type 'bool' is not iterable | |
| """ | |
| def ui_function_wrapper(vehicle_type, user_description): | |
| """ | |
| Main UI wrapper function that yields real-time updates to multiple Gradio components | |
| Returns tuples in the order: process_log, current_design_specs, progress_bar, | |
| final_status, simulation_video, best_design_specs, download_json, | |
| performance_summary, llm_rationale | |
| """ | |
| global designer | |
| # Reset designer for new task | |
| designer.reset_design_session() | |
| designer.vehicle_type = vehicle_type.lower() | |
| designer.user_task_description = user_description | |
| # Initial setup - yield initial states | |
| yield ( | |
| "π Initializing Agent2Robot system...\n", # process_log_output | |
| {}, # current_design_specs_output | |
| 0, # progress_bar_output | |
| "", # final_status_output | |
| None, # simulation_video_output | |
| {}, # best_design_specs_output | |
| None, # download_json_output | |
| "", # performance_summary_output | |
| "" # llm_rationale_output | |
| ) | |
| # Parse user criteria | |
| designer.log_process_step("π― Analyzing user task and success criteria...") | |
| criteria = designer.parse_user_task_for_criteria(user_description) | |
| designer.log_process_step(f"π Interpreted success criteria:") | |
| for criterion in criteria: | |
| designer.log_process_step(f" β’ {criterion}") | |
| # Update with criteria interpretation | |
| current_log = "\n".join(designer.process_log) | |
| yield ( | |
| current_log, # process_log_output | |
| {"interpreted_criteria": criteria}, # current_design_specs_output | |
| 0, # progress_bar_output | |
| "", # final_status_output | |
| None, # simulation_video_output | |
| {}, # best_design_specs_output | |
| None, # download_json_output | |
| "", # performance_summary_output | |
| "" # llm_rationale_output | |
| ) | |
| # Start design process | |
| designer.log_process_step(f"π Starting {vehicle_type} design process...") | |
| designer.log_process_step(f"π― Target: {user_description}") | |
| current_log = "\n".join(designer.process_log) | |
| yield ( | |
| current_log, # process_log_output | |
| {"status": "Design process starting..."}, # current_design_specs_output | |
| 0, # progress_bar_output | |
| "", # final_status_output | |
| None, # simulation_video_output | |
| {}, # best_design_specs_output | |
| None, # download_json_output | |
| "", # performance_summary_output | |
| "" # llm_rationale_output | |
| ) | |
| # Run iterations | |
| for iteration in range(1, MAX_ITERATIONS + 1): | |
| designer.log_process_step(f"\n=== Starting Iteration {iteration}/{MAX_ITERATIONS} ===") | |
| # Update progress at start of iteration | |
| current_log = "\n".join(designer.process_log) | |
| progress_value = (iteration - 0.5) / MAX_ITERATIONS * 100 # Convert to percentage | |
| yield ( | |
| current_log, # process_log_output | |
| {"current_iteration": iteration, "max_iterations": MAX_ITERATIONS, "status": "Running..."}, # current_design_specs_output | |
| progress_value, # progress_bar_output | |
| "", # final_status_output | |
| None, # simulation_video_output | |
| {}, # best_design_specs_output | |
| None, # download_json_output | |
| "", # performance_summary_output | |
| "" # llm_rationale_output | |
| ) | |
| # Run the iteration | |
| try: | |
| success = designer.run_single_iteration(iteration) | |
| # Get current design specs for display | |
| if designer.all_attempts: | |
| current_attempt = designer.all_attempts[-1] | |
| current_specs = current_attempt['vehicle_specs'] | |
| design_reasoning = current_attempt.get('design_reasoning', 'No reasoning provided') | |
| # Update with current iteration results | |
| current_log = "\n".join(designer.process_log) | |
| progress_value = iteration / MAX_ITERATIONS * 100 | |
| current_specs_display = { | |
| "iteration": iteration, | |
| "vehicle_specs": current_specs, | |
| "design_reasoning_preview": design_reasoning[:200] + "..." if len(design_reasoning) > 200 else design_reasoning, | |
| "status": "β SUCCESS" if success else "π Completed - Evaluating..." | |
| } | |
| yield ( | |
| current_log, # process_log_output | |
| current_specs_display, # current_design_specs_output | |
| progress_value, # progress_bar_output | |
| "", # final_status_output | |
| None, # simulation_video_output | |
| {}, # best_design_specs_output | |
| None, # download_json_output | |
| "", # performance_summary_output | |
| "" # llm_rationale_output | |
| ) | |
| if success: | |
| designer.log_process_step("π SUCCESS! Design meets all criteria!") | |
| break | |
| except Exception as e: | |
| designer.log_process_step(f"β Error in iteration {iteration}: {str(e)}") | |
| current_log = "\n".join(designer.process_log) | |
| progress_value = iteration / MAX_ITERATIONS * 100 | |
| yield ( | |
| current_log, # process_log_output | |
| {"error": f"Iteration {iteration} failed", "details": str(e)}, # current_design_specs_output | |
| progress_value, # progress_bar_output | |
| "", # final_status_output | |
| None, # simulation_video_output | |
| {}, # best_design_specs_output | |
| None, # download_json_output | |
| "", # performance_summary_output | |
| "" # llm_rationale_output | |
| ) | |
| # Generate final results | |
| designer.log_process_step("π Generating final results and visualizations...") | |
| current_log = "\n".join(designer.process_log) | |
| yield ( | |
| current_log, # process_log_output | |
| {"status": "Generating final results..."}, # current_design_specs_output | |
| 100, # progress_bar_output - complete | |
| "", # final_status_output | |
| None, # simulation_video_output | |
| {}, # best_design_specs_output | |
| None, # download_json_output | |
| "", # performance_summary_output | |
| "" # llm_rationale_output | |
| ) | |
| # Prepare final outputs | |
| if designer.overall_success: | |
| final_status = "## π SUCCESS!\n\nThe LLM agent successfully designed a vehicle that meets all criteria!" | |
| status_emoji = "β " | |
| else: | |
| final_status = "## β οΈ PROCESS COMPLETED\n\nThe agent completed all iterations. Showing best attempt found." | |
| status_emoji = "π" | |
| # Get best design specs | |
| best_specs = designer.best_attempt['vehicle_specs'] if designer.best_attempt else {} | |
| # Create visualization | |
| simulation_gif_path = None | |
| try: | |
| simulation_gif_path = designer.create_final_visualization() | |
| except Exception as e: | |
| designer.log_process_step(f"β οΈ Error creating visualization: {str(e)}") | |
| # Format performance summary | |
| if designer.best_attempt: | |
| eval_results = designer.best_attempt['evaluation_results'] | |
| performance_summary = f"""## π Performance Summary of Best Design | |
| **Iteration Found**: {designer.best_iteration}/{len(designer.all_attempts)} | |
| **Final Position**: {eval_results.get('final_robot_x_position', 0.0):.3f}m | |
| **Crossed Obstacle**: {'β Yes' if eval_results.get('robot_crossed_obstacle', False) else 'β No'} | |
| **Remained Stable**: {'β Yes' if eval_results.get('robot_remains_upright', False) else 'β No'} | |
| **Clean Pass**: {'β Yes' if eval_results.get('no_significant_collision_with_obstacle_during_pass', False) else 'β No'} | |
| **Overall Success**: {'β ACHIEVED' if eval_results.get('overall_success', False) else 'β NOT FULLY ACHIEVED'} | |
| **Target Distance**: 0.8m (obstacle clearance) | |
| **Achieved Distance**: {eval_results.get('final_robot_x_position', 0.0):.3f}m | |
| **Success Rate**: {100 if eval_results.get('overall_success', False) else 0}% | |
| {status_emoji} **Status**: {'Complete Success' if designer.overall_success else 'Best Effort'} | |
| """ | |
| else: | |
| performance_summary = "## β No successful attempts recorded\n\nThe system was unable to generate valid designs." | |
| # Get LLM rationale | |
| llm_rationale = designer.best_attempt['design_reasoning'] if designer.best_attempt else "No design reasoning available" | |
| # Create downloadable specs | |
| download_specs_path = None | |
| try: | |
| download_specs_path = designer.save_design_specs_json() | |
| except Exception as e: | |
| designer.log_process_step(f"β οΈ Error saving specs: {str(e)}") | |
| # Final log update | |
| designer.log_process_step(f"\nπ DESIGN PROCESS COMPLETED") | |
| designer.log_process_step(f"π Total iterations: {len(designer.all_attempts)}") | |
| designer.log_process_step(f"π Best iteration: {designer.best_iteration}") | |
| designer.log_process_step(f"β Overall success: {designer.overall_success}") | |
| final_log = "\n".join(designer.process_log) | |
| # Final yield with all results | |
| yield ( | |
| final_log, # process_log_output | |
| {"final_summary": f"Process completed. {len(designer.all_attempts)} iterations run."}, # current_design_specs_output | |
| 100, # progress_bar_output | |
| final_status, # final_status_output | |
| simulation_gif_path, # simulation_video_output | |
| best_specs, # best_design_specs_output | |
| download_specs_path, # download_json_output | |
| performance_summary, # performance_summary_output | |
| llm_rationale # llm_rationale_output | |
| ) |