sam133 commited on
Commit
e7593e4
Β·
1 Parent(s): 5770dd2

Minimal 9-output function for schema debug

Browse files
Files changed (2) hide show
  1. app.py +84 -39
  2. ui_function_backup.py +230 -0
app.py CHANGED
@@ -41,41 +41,38 @@ os.environ['PYTHONPATH'] = os.environ.get('PYTHONPATH', '') + ';.'
41
 
42
  import gradio as gr
43
 
44
- def simple_test_function(vehicle_type, user_description):
45
- """Ultra simple function with only basic string outputs"""
46
- if not user_description:
47
- user_description = "No description provided"
 
 
 
48
 
49
- # Only basic string outputs to avoid any schema issues
50
- result = f"""βœ… DESIGN COMPLETED!
51
-
52
- 🚁 Vehicle: {vehicle_type}
53
- πŸ“ Description: {user_description}
54
-
55
- 🎯 Design Parameters:
56
- β€’ Speed: 5.2 m/s
57
- β€’ Weight: 1.8 kg
58
- β€’ Dimensions: 10x8x6 cm
59
- β€’ Battery: 45 min
60
-
61
- βœ… Status: SUCCESS"""
62
-
63
- progress = "100% Complete"
64
-
65
- return result, progress
66
 
67
  def create_minimal_working_app():
68
- """Ultra minimal app with only basic components"""
69
 
70
- with gr.Blocks(title="πŸ€–πŸš Agent2Robot") as demo:
71
 
72
- gr.HTML("<h1>πŸ€–πŸš Agent2Robot - Ultra Stable Version</h1>")
73
 
74
  with gr.Row():
75
  with gr.Column():
76
  gr.Markdown("## Input")
77
 
78
- # Most basic components only
79
  vehicle_input = gr.Radio(
80
  choices=["Robot", "Drone"],
81
  label="Vehicle Type",
@@ -88,33 +85,81 @@ def create_minimal_working_app():
88
  value="Design a robot for obstacle navigation"
89
  )
90
 
91
- process_button = gr.Button("πŸš€ Process", variant="primary")
92
 
93
  with gr.Column():
94
- gr.Markdown("## Results")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
- # Only basic text outputs
97
- result_output = gr.Textbox(
98
- label="Design Results",
99
- lines=12,
100
  interactive=False
101
  )
102
 
103
- status_output = gr.Textbox(
104
- label="Status",
105
- lines=1,
106
  interactive=False
107
  )
108
 
109
- # Ultra simple button connection
110
- process_button.click(
111
- fn=simple_test_function,
112
  inputs=[vehicle_input, description_input],
113
- outputs=[result_output, status_output]
 
 
 
 
 
 
 
 
 
 
114
  )
115
 
116
  gr.Markdown("---")
117
- gr.Markdown("**Ultra Stable Version** - Avoids all schema validation issues")
118
 
119
  return demo
120
 
 
41
 
42
  import gradio as gr
43
 
44
+ def minimal_ui_function_wrapper(vehicle_type, user_description):
45
+ """
46
+ ULTRA MINIMAL wrapper function for debugging schema validation
47
+ Must yield exactly 9 outputs to match the complex function:
48
+ process_log, current_design_specs, progress_bar, final_status,
49
+ simulation_video, best_design_specs, download_json, performance_summary, llm_rationale
50
+ """
51
 
52
+ # Test with absolute minimal data types
53
+ yield (
54
+ "Minimal test: Process started.", # process_log_output (gr.Textbox)
55
+ {"status": "minimal_test"}, # current_design_specs_output (gr.JSON)
56
+ 1, # progress_bar_output (gr.Slider/Number)
57
+ "Minimal test: Test status.", # final_status_output (gr.Markdown/Textbox)
58
+ None, # simulation_video_output (gr.Image/Video)
59
+ {"result": "minimal_test_data"}, # best_design_specs_output (gr.JSON)
60
+ None, # download_json_output (gr.File)
61
+ "Minimal test: Performance test.", # performance_summary_output (gr.Markdown/Textbox)
62
+ "Minimal test: Rationale test." # llm_rationale_output (gr.Textbox)
63
+ )
 
 
 
 
 
64
 
65
  def create_minimal_working_app():
66
+ """Ultra minimal app for debugging schema validation"""
67
 
68
+ with gr.Blocks(title="πŸ€–πŸš Agent2Robot - Schema Debug") as demo:
69
 
70
+ gr.HTML("<h1>πŸ€–πŸš Agent2Robot - Schema Validation Debug</h1>")
71
 
72
  with gr.Row():
73
  with gr.Column():
74
  gr.Markdown("## Input")
75
 
 
76
  vehicle_input = gr.Radio(
77
  choices=["Robot", "Drone"],
78
  label="Vehicle Type",
 
85
  value="Design a robot for obstacle navigation"
86
  )
87
 
88
+ debug_button = gr.Button("πŸ” Debug Schema", variant="primary")
89
 
90
  with gr.Column():
91
+ gr.Markdown("## Debug Outputs (9 components)")
92
+
93
+ # Exactly matching the complex function's 9 outputs
94
+ process_log_output = gr.Textbox(
95
+ label="1. Process Log",
96
+ lines=3,
97
+ interactive=False
98
+ )
99
+
100
+ current_design_specs_output = gr.JSON(
101
+ label="2. Current Design Specs",
102
+ value={}
103
+ )
104
+
105
+ progress_bar_output = gr.Number(
106
+ label="3. Progress Bar",
107
+ value=0,
108
+ interactive=False
109
+ )
110
+
111
+ final_status_output = gr.Textbox(
112
+ label="4. Final Status",
113
+ lines=2,
114
+ interactive=False
115
+ )
116
+
117
+ simulation_video_output = gr.Image(
118
+ label="5. Simulation Video",
119
+ interactive=False
120
+ )
121
+
122
+ best_design_specs_output = gr.JSON(
123
+ label="6. Best Design Specs",
124
+ value={}
125
+ )
126
+
127
+ download_json_output = gr.File(
128
+ label="7. Download JSON",
129
+ interactive=False
130
+ )
131
 
132
+ performance_summary_output = gr.Textbox(
133
+ label="8. Performance Summary",
134
+ lines=2,
 
135
  interactive=False
136
  )
137
 
138
+ llm_rationale_output = gr.Textbox(
139
+ label="9. LLM Rationale",
140
+ lines=2,
141
  interactive=False
142
  )
143
 
144
+ # Connect with 9 outputs (matching complex function)
145
+ debug_button.click(
146
+ fn=minimal_ui_function_wrapper,
147
  inputs=[vehicle_input, description_input],
148
+ outputs=[
149
+ process_log_output,
150
+ current_design_specs_output,
151
+ progress_bar_output,
152
+ final_status_output,
153
+ simulation_video_output,
154
+ best_design_specs_output,
155
+ download_json_output,
156
+ performance_summary_output,
157
+ llm_rationale_output
158
+ ]
159
  )
160
 
161
  gr.Markdown("---")
162
+ gr.Markdown("**Schema Debug Version** - Testing 9-output function for schema validation issues")
163
 
164
  return demo
165
 
ui_function_backup.py ADDED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ BACKUP of complex ui_function_wrapper that causes schema validation issues
4
+ This is the original function from app_backup.py that triggers:
5
+ TypeError: argument of type 'bool' is not iterable
6
+ """
7
+
8
+ def ui_function_wrapper(vehicle_type, user_description):
9
+ """
10
+ Main UI wrapper function that yields real-time updates to multiple Gradio components
11
+ Returns tuples in the order: process_log, current_design_specs, progress_bar,
12
+ final_status, simulation_video, best_design_specs, download_json,
13
+ performance_summary, llm_rationale
14
+ """
15
+ global designer
16
+
17
+ # Reset designer for new task
18
+ designer.reset_design_session()
19
+ designer.vehicle_type = vehicle_type.lower()
20
+ designer.user_task_description = user_description
21
+
22
+ # Initial setup - yield initial states
23
+ yield (
24
+ "πŸš€ Initializing Agent2Robot system...\n", # process_log_output
25
+ {}, # current_design_specs_output
26
+ 0, # progress_bar_output
27
+ "", # final_status_output
28
+ None, # simulation_video_output
29
+ {}, # best_design_specs_output
30
+ None, # download_json_output
31
+ "", # performance_summary_output
32
+ "" # llm_rationale_output
33
+ )
34
+
35
+ # Parse user criteria
36
+ designer.log_process_step("🎯 Analyzing user task and success criteria...")
37
+ criteria = designer.parse_user_task_for_criteria(user_description)
38
+
39
+ designer.log_process_step(f"πŸ“‹ Interpreted success criteria:")
40
+ for criterion in criteria:
41
+ designer.log_process_step(f" β€’ {criterion}")
42
+
43
+ # Update with criteria interpretation
44
+ current_log = "\n".join(designer.process_log)
45
+ yield (
46
+ current_log, # process_log_output
47
+ {"interpreted_criteria": criteria}, # current_design_specs_output
48
+ 0, # progress_bar_output
49
+ "", # final_status_output
50
+ None, # simulation_video_output
51
+ {}, # best_design_specs_output
52
+ None, # download_json_output
53
+ "", # performance_summary_output
54
+ "" # llm_rationale_output
55
+ )
56
+
57
+ # Start design process
58
+ designer.log_process_step(f"πŸš€ Starting {vehicle_type} design process...")
59
+ designer.log_process_step(f"🎯 Target: {user_description}")
60
+
61
+ current_log = "\n".join(designer.process_log)
62
+ yield (
63
+ current_log, # process_log_output
64
+ {"status": "Design process starting..."}, # current_design_specs_output
65
+ 0, # progress_bar_output
66
+ "", # final_status_output
67
+ None, # simulation_video_output
68
+ {}, # best_design_specs_output
69
+ None, # download_json_output
70
+ "", # performance_summary_output
71
+ "" # llm_rationale_output
72
+ )
73
+
74
+ # Run iterations
75
+ for iteration in range(1, MAX_ITERATIONS + 1):
76
+ designer.log_process_step(f"\n=== Starting Iteration {iteration}/{MAX_ITERATIONS} ===")
77
+
78
+ # Update progress at start of iteration
79
+ current_log = "\n".join(designer.process_log)
80
+ progress_value = (iteration - 0.5) / MAX_ITERATIONS * 100 # Convert to percentage
81
+ yield (
82
+ current_log, # process_log_output
83
+ {"current_iteration": iteration, "max_iterations": MAX_ITERATIONS, "status": "Running..."}, # current_design_specs_output
84
+ progress_value, # progress_bar_output
85
+ "", # final_status_output
86
+ None, # simulation_video_output
87
+ {}, # best_design_specs_output
88
+ None, # download_json_output
89
+ "", # performance_summary_output
90
+ "" # llm_rationale_output
91
+ )
92
+
93
+ # Run the iteration
94
+ try:
95
+ success = designer.run_single_iteration(iteration)
96
+
97
+ # Get current design specs for display
98
+ if designer.all_attempts:
99
+ current_attempt = designer.all_attempts[-1]
100
+ current_specs = current_attempt['vehicle_specs']
101
+ design_reasoning = current_attempt.get('design_reasoning', 'No reasoning provided')
102
+
103
+ # Update with current iteration results
104
+ current_log = "\n".join(designer.process_log)
105
+ progress_value = iteration / MAX_ITERATIONS * 100
106
+
107
+ current_specs_display = {
108
+ "iteration": iteration,
109
+ "vehicle_specs": current_specs,
110
+ "design_reasoning_preview": design_reasoning[:200] + "..." if len(design_reasoning) > 200 else design_reasoning,
111
+ "status": "βœ… SUCCESS" if success else "πŸ”„ Completed - Evaluating..."
112
+ }
113
+
114
+ yield (
115
+ current_log, # process_log_output
116
+ current_specs_display, # current_design_specs_output
117
+ progress_value, # progress_bar_output
118
+ "", # final_status_output
119
+ None, # simulation_video_output
120
+ {}, # best_design_specs_output
121
+ None, # download_json_output
122
+ "", # performance_summary_output
123
+ "" # llm_rationale_output
124
+ )
125
+
126
+ if success:
127
+ designer.log_process_step("πŸŽ‰ SUCCESS! Design meets all criteria!")
128
+ break
129
+
130
+ except Exception as e:
131
+ designer.log_process_step(f"❌ Error in iteration {iteration}: {str(e)}")
132
+ current_log = "\n".join(designer.process_log)
133
+ progress_value = iteration / MAX_ITERATIONS * 100
134
+ yield (
135
+ current_log, # process_log_output
136
+ {"error": f"Iteration {iteration} failed", "details": str(e)}, # current_design_specs_output
137
+ progress_value, # progress_bar_output
138
+ "", # final_status_output
139
+ None, # simulation_video_output
140
+ {}, # best_design_specs_output
141
+ None, # download_json_output
142
+ "", # performance_summary_output
143
+ "" # llm_rationale_output
144
+ )
145
+
146
+ # Generate final results
147
+ designer.log_process_step("πŸ“Š Generating final results and visualizations...")
148
+ current_log = "\n".join(designer.process_log)
149
+ yield (
150
+ current_log, # process_log_output
151
+ {"status": "Generating final results..."}, # current_design_specs_output
152
+ 100, # progress_bar_output - complete
153
+ "", # final_status_output
154
+ None, # simulation_video_output
155
+ {}, # best_design_specs_output
156
+ None, # download_json_output
157
+ "", # performance_summary_output
158
+ "" # llm_rationale_output
159
+ )
160
+
161
+ # Prepare final outputs
162
+ if designer.overall_success:
163
+ final_status = "## πŸŽ‰ SUCCESS!\n\nThe LLM agent successfully designed a vehicle that meets all criteria!"
164
+ status_emoji = "βœ…"
165
+ else:
166
+ final_status = "## ⚠️ PROCESS COMPLETED\n\nThe agent completed all iterations. Showing best attempt found."
167
+ status_emoji = "πŸ”„"
168
+
169
+ # Get best design specs
170
+ best_specs = designer.best_attempt['vehicle_specs'] if designer.best_attempt else {}
171
+
172
+ # Create visualization
173
+ simulation_gif_path = None
174
+ try:
175
+ simulation_gif_path = designer.create_final_visualization()
176
+ except Exception as e:
177
+ designer.log_process_step(f"⚠️ Error creating visualization: {str(e)}")
178
+
179
+ # Format performance summary
180
+ if designer.best_attempt:
181
+ eval_results = designer.best_attempt['evaluation_results']
182
+ performance_summary = f"""## πŸ“Š Performance Summary of Best Design
183
+
184
+ **Iteration Found**: {designer.best_iteration}/{len(designer.all_attempts)}
185
+ **Final Position**: {eval_results.get('final_robot_x_position', 0.0):.3f}m
186
+ **Crossed Obstacle**: {'βœ… Yes' if eval_results.get('robot_crossed_obstacle', False) else '❌ No'}
187
+ **Remained Stable**: {'βœ… Yes' if eval_results.get('robot_remains_upright', False) else '❌ No'}
188
+ **Clean Pass**: {'βœ… Yes' if eval_results.get('no_significant_collision_with_obstacle_during_pass', False) else '❌ No'}
189
+
190
+ **Overall Success**: {'βœ… ACHIEVED' if eval_results.get('overall_success', False) else '❌ NOT FULLY ACHIEVED'}
191
+
192
+ **Target Distance**: 0.8m (obstacle clearance)
193
+ **Achieved Distance**: {eval_results.get('final_robot_x_position', 0.0):.3f}m
194
+ **Success Rate**: {100 if eval_results.get('overall_success', False) else 0}%
195
+
196
+ {status_emoji} **Status**: {'Complete Success' if designer.overall_success else 'Best Effort'}
197
+ """
198
+ else:
199
+ performance_summary = "## ❌ No successful attempts recorded\n\nThe system was unable to generate valid designs."
200
+
201
+ # Get LLM rationale
202
+ llm_rationale = designer.best_attempt['design_reasoning'] if designer.best_attempt else "No design reasoning available"
203
+
204
+ # Create downloadable specs
205
+ download_specs_path = None
206
+ try:
207
+ download_specs_path = designer.save_design_specs_json()
208
+ except Exception as e:
209
+ designer.log_process_step(f"⚠️ Error saving specs: {str(e)}")
210
+
211
+ # Final log update
212
+ designer.log_process_step(f"\n🏁 DESIGN PROCESS COMPLETED")
213
+ designer.log_process_step(f"πŸ“Š Total iterations: {len(designer.all_attempts)}")
214
+ designer.log_process_step(f"πŸ† Best iteration: {designer.best_iteration}")
215
+ designer.log_process_step(f"βœ… Overall success: {designer.overall_success}")
216
+
217
+ final_log = "\n".join(designer.process_log)
218
+
219
+ # Final yield with all results
220
+ yield (
221
+ final_log, # process_log_output
222
+ {"final_summary": f"Process completed. {len(designer.all_attempts)} iterations run."}, # current_design_specs_output
223
+ 100, # progress_bar_output
224
+ final_status, # final_status_output
225
+ simulation_gif_path, # simulation_video_output
226
+ best_specs, # best_design_specs_output
227
+ download_specs_path, # download_json_output
228
+ performance_summary, # performance_summary_output
229
+ llm_rationale # llm_rationale_output
230
+ )