sam133 commited on
Commit
44cdfaa
Β·
1 Parent(s): 0fe9c4b

Initial Agent2Robot app

Browse files
Files changed (3) hide show
  1. app.py +148 -92
  2. requirements.txt +13 -4
  3. test_components.py +140 -0
app.py CHANGED
@@ -13,6 +13,7 @@ try:
13
  import certifi
14
  os.environ['SSL_CERT_FILE'] = certifi.where()
15
  os.environ['REQUESTS_CA_BUNDLE'] = certifi.where()
 
16
  except ImportError:
17
  print("⚠️ Warning: certifi not available, using alternative SSL fix")
18
 
@@ -33,35 +34,58 @@ if 'SSL_CERT_FILE' in os.environ:
33
  except:
34
  pass
35
 
 
 
 
 
36
  import gradio as gr
37
 
38
  def simple_test_function(vehicle_type, user_description):
39
- """Simple test function that returns results like Step 4 worked"""
40
  if not user_description:
41
  user_description = "No description provided"
42
 
43
- # Simple return (like Step 4 but with return instead of yield)
44
- text_output = f"βœ… COMPLETED!\nVehicle: {vehicle_type}\nDescription: {user_description}\nTest successful!"
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  json_output = {
46
  "vehicle_type": vehicle_type,
47
  "description": user_description,
48
- "test_status": "success",
49
  "parameters": {
50
  "speed": 5.2,
51
  "weight": 1.8,
52
- "dimensions": [10, 8, 6]
53
- }
 
 
 
 
 
 
54
  }
 
55
  progress_value = 100
56
- image_output = None
57
- file_output = None
58
 
59
- return text_output, json_output, progress_value, image_output, file_output
60
 
61
  def create_minimal_working_app():
62
- """MINIMAL working app based on successful Step 4"""
63
 
64
- # Exact same CSS as Step 4 (worked)
65
  custom_css = """
66
  .main-header {
67
  text-align: center;
@@ -72,150 +96,182 @@ def create_minimal_working_app():
72
  margin-bottom: 20px;
73
  box-shadow: 0 8px 16px rgba(0,0,0,0.1);
74
  }
 
 
 
 
 
 
75
  """
76
 
77
  with gr.Blocks(
78
- title="πŸ€–πŸš Agent2Robot - MINIMAL WORKING",
79
  theme=gr.themes.Soft(),
80
  css=custom_css
81
  ) as demo:
82
 
83
- # Exact same header as Step 4 (worked)
84
  gr.HTML("""
85
  <div class="main-header">
86
  <h1>πŸ€–πŸš Agent2Robot</h1>
87
- <h2>MINIMAL WORKING VERSION</h2>
88
- <p><strong>Based on successful Step 4 components</strong></p>
89
  </div>
90
  """)
91
 
92
- # Exact same layout as Step 4 (worked)
93
- gr.Markdown("## πŸ”§ MINIMAL WORKING TEST")
94
-
95
  with gr.Row():
96
  with gr.Column(scale=1):
97
- gr.Markdown("## 🎯 1. Define Your Vehicle Challenge")
98
 
99
- # Exact same components as Step 4 (worked)
100
- vehicle_type_input = gr.Radio(
101
  choices=["Robot", "Drone"],
102
- label="1. Choose Vehicle Type",
103
  value="Robot",
104
- info="Select whether you want a ground robot or flying drone"
105
  )
106
 
107
- user_description_input = gr.Textbox(
108
- lines=5,
109
- label="2. Describe Vehicle's Task & Success Criteria",
110
- placeholder="e.g., 'Design a robot that can cross the 5cm box obstacle quickly and without tipping over, then stop safely.'",
111
- value="Design a robot that can cross the 5cm high obstacle smoothly and come to a controlled stop."
112
  )
113
 
114
- start_button = gr.Button(
115
  "πŸš€ Start AI Design Process",
116
  variant="primary",
117
  size="lg"
118
  )
119
 
120
- gr.Markdown("""
121
- ### πŸ“‹ Status
122
- - **Version**: Minimal working (Step 4 base)
123
- - **Function**: Simple return (no yield)
124
- - **Goal**: Isolate the problematic component
 
 
 
 
 
125
  """)
126
 
127
  with gr.Column(scale=2):
128
- gr.Markdown("## πŸ€– 2. Test Outputs")
129
 
130
- # Exact same output components as Step 4 (worked)
131
- output_textbox = gr.Textbox(
132
- label="πŸ“ Text Output",
133
- lines=5,
134
- value="",
135
- interactive=False
136
- )
 
 
 
 
 
 
 
 
137
 
138
- with gr.Row():
139
- current_design_specs_output = gr.JSON(
140
- label="βš™οΈ JSON Output Test",
141
  value={}
142
  )
143
 
144
- progress_bar_output = gr.Slider(
145
- minimum=0,
146
  maximum=100,
147
  step=1,
148
- label="Progress (%)",
149
  interactive=False,
150
- show_label=True,
151
  value=0
152
  )
153
 
154
- simulation_video_output = gr.Image(
155
- label="🎬 Image Output Test",
156
- interactive=False,
157
- height=200,
158
- value=None
159
- )
160
-
161
- download_json_output = gr.File(
162
- label="πŸ“„ File Output Test",
163
- file_count="single",
164
- type="filepath",
165
- interactive=True,
166
- value=None
167
- )
 
168
 
169
- # Simple button connection (5 outputs like Step 4)
170
- start_button.click(
171
- fn=simple_test_function,
172
- inputs=[vehicle_type_input, user_description_input],
173
- outputs=[
174
- output_textbox,
175
- current_design_specs_output,
176
- progress_bar_output,
177
- simulation_video_output,
178
- download_json_output
179
- ]
180
  )
181
 
182
  gr.Markdown("---")
183
- gr.Markdown("**Status**: If this works, we can add components one by one to find the problematic one.")
 
 
 
 
 
 
184
 
185
  return demo
186
 
187
  if __name__ == "__main__":
188
- print("πŸ”§ Agent2Robot - MINIMAL WORKING VERSION")
189
- print("=" * 50)
190
- print("πŸš€ Testing minimal working components...")
 
191
 
192
  try:
193
  app = create_minimal_working_app()
194
- print("βœ… App created successfully")
195
- print("🌐 Launching with share=True (since localhost not accessible)...")
 
 
 
 
 
196
 
 
197
  app.launch(
198
- server_name="0.0.0.0",
199
  server_port=7860,
200
- share=True, # Fixed: Set to True since localhost is not accessible
201
  show_error=True,
202
- inbrowser=False, # Changed to False to avoid browser issues
203
  quiet=False,
204
- debug=True # Added debug mode for better error reporting
 
 
205
  )
 
206
  except Exception as e:
207
- print(f"❌ Error launching app: {e}")
208
- print("Even minimal version has issues!")
209
 
210
- # Additional debugging information
211
  import traceback
212
  print("\nπŸ” Full error traceback:")
213
  traceback.print_exc()
214
 
215
- # Try alternative launch with minimal options
216
- print("\nπŸ”„ Trying alternative launch configuration...")
217
  try:
218
- app.launch(share=True, debug=True)
 
 
 
 
 
219
  except Exception as e2:
220
- print(f"❌ Alternative launch also failed: {e2}")
221
- print("Please check Gradio installation and dependencies.")
 
 
 
 
 
13
  import certifi
14
  os.environ['SSL_CERT_FILE'] = certifi.where()
15
  os.environ['REQUESTS_CA_BUNDLE'] = certifi.where()
16
+ os.environ['CURL_CA_BUNDLE'] = certifi.where()
17
  except ImportError:
18
  print("⚠️ Warning: certifi not available, using alternative SSL fix")
19
 
 
34
  except:
35
  pass
36
 
37
+ # Additional environment fixes for Windows
38
+ os.environ['PYTHONHTTPSVERIFY'] = '0'
39
+ os.environ['PYTHONPATH'] = os.environ.get('PYTHONPATH', '') + ';.'
40
+
41
  import gradio as gr
42
 
43
  def simple_test_function(vehicle_type, user_description):
44
+ """Enhanced test function that returns comprehensive results"""
45
  if not user_description:
46
  user_description = "No description provided"
47
 
48
+ # Enhanced return with proper data types for Gradio 4.40.0
49
+ text_output = f"""βœ… DESIGN PROCESS COMPLETED!
50
+
51
+ 🚁 Vehicle Type: {vehicle_type}
52
+ πŸ“ Description: {user_description}
53
+
54
+ 🎯 Design Summary:
55
+ - Optimized for the specified task
56
+ - Performance parameters calculated
57
+ - Safety features integrated
58
+ - Ready for simulation testing
59
+
60
+ Status: βœ… SUCCESS"""
61
+
62
+ # JSON output as dictionary (works with Gradio 4.40.0)
63
  json_output = {
64
  "vehicle_type": vehicle_type,
65
  "description": user_description,
66
+ "status": "completed",
67
  "parameters": {
68
  "speed": 5.2,
69
  "weight": 1.8,
70
+ "dimensions": [10, 8, 6],
71
+ "battery_life": 45.0
72
+ },
73
+ "safety_features": [
74
+ "Obstacle detection",
75
+ "Emergency stop",
76
+ "Low battery warning"
77
+ ]
78
  }
79
+
80
  progress_value = 100
81
+ status_message = "πŸŽ‰ Design process completed successfully!"
 
82
 
83
+ return text_output, json_output, progress_value, status_message
84
 
85
  def create_minimal_working_app():
86
+ """Enhanced working app with more functionality"""
87
 
88
+ # Enhanced CSS for better appearance
89
  custom_css = """
90
  .main-header {
91
  text-align: center;
 
96
  margin-bottom: 20px;
97
  box-shadow: 0 8px 16px rgba(0,0,0,0.1);
98
  }
99
+ .status-box {
100
+ background: #f0f8ff;
101
+ padding: 15px;
102
+ border-radius: 8px;
103
+ border-left: 4px solid #4CAF50;
104
+ }
105
  """
106
 
107
  with gr.Blocks(
108
+ title="πŸ€–πŸš Agent2Robot - Enhanced Working Version",
109
  theme=gr.themes.Soft(),
110
  css=custom_css
111
  ) as demo:
112
 
113
+ # Enhanced header
114
  gr.HTML("""
115
  <div class="main-header">
116
  <h1>πŸ€–πŸš Agent2Robot</h1>
117
+ <h2>AI-Powered Vehicle Design Platform</h2>
118
+ <p><strong>Enhanced Working Version - Gradio 4.40.0 Compatible</strong></p>
119
  </div>
120
  """)
121
 
 
 
 
122
  with gr.Row():
123
  with gr.Column(scale=1):
124
+ gr.Markdown("## 🎯 1. Vehicle Design Input")
125
 
126
+ vehicle_input = gr.Radio(
 
127
  choices=["Robot", "Drone"],
128
+ label="🚁 Vehicle Type",
129
  value="Robot",
130
+ info="Select the type of vehicle to design"
131
  )
132
 
133
+ description_input = gr.Textbox(
134
+ label="πŸ“ Task Description & Requirements",
135
+ lines=4,
136
+ placeholder="Describe the vehicle's mission, obstacles to overcome, and success criteria...",
137
+ value="Design a robot that can navigate obstacles and perform specific tasks efficiently."
138
  )
139
 
140
+ design_button = gr.Button(
141
  "πŸš€ Start AI Design Process",
142
  variant="primary",
143
  size="lg"
144
  )
145
 
146
+ gr.HTML("""
147
+ <div class="status-box">
148
+ <h4>πŸ“‹ System Status</h4>
149
+ <ul>
150
+ <li>βœ… Gradio 4.40.0 Compatible</li>
151
+ <li>βœ… Schema validation fixed</li>
152
+ <li>βœ… SSL issues resolved</li>
153
+ <li>βœ… Ready for full functionality</li>
154
+ </ul>
155
+ </div>
156
  """)
157
 
158
  with gr.Column(scale=2):
159
+ gr.Markdown("## πŸ€– 2. AI Design Results")
160
 
161
+ # Enhanced output components
162
+ with gr.Tab("πŸ“Š Results Overview"):
163
+ result_textbox = gr.Textbox(
164
+ label="πŸ“ Design Process Output",
165
+ lines=8,
166
+ interactive=False,
167
+ value=""
168
+ )
169
+
170
+ status_output = gr.Textbox(
171
+ label="πŸ“ˆ Current Status",
172
+ lines=1,
173
+ interactive=False,
174
+ value=""
175
+ )
176
 
177
+ with gr.Tab("βš™οΈ Technical Specifications"):
178
+ specs_output = gr.JSON(
179
+ label="πŸ”§ Vehicle Parameters & Specifications",
180
  value={}
181
  )
182
 
183
+ progress_output = gr.Slider(
184
+ minimum=0,
185
  maximum=100,
186
  step=1,
187
+ label="🎯 Design Progress (%)",
188
  interactive=False,
 
189
  value=0
190
  )
191
 
192
+ with gr.Tab("πŸ“Š Performance Metrics"):
193
+ gr.Markdown("### πŸ“ˆ Key Performance Indicators")
194
+
195
+ with gr.Row():
196
+ efficiency_display = gr.Number(
197
+ label="⚑ Efficiency Score",
198
+ value=0,
199
+ interactive=False
200
+ )
201
+
202
+ safety_display = gr.Number(
203
+ label="πŸ›‘οΈ Safety Rating",
204
+ value=0,
205
+ interactive=False
206
+ )
207
 
208
+ # Enhanced button functionality
209
+ design_button.click(
210
+ fn=simple_test_function,
211
+ inputs=[vehicle_input, description_input],
212
+ outputs=[result_textbox, specs_output, progress_output, status_output]
 
 
 
 
 
 
213
  )
214
 
215
  gr.Markdown("---")
216
+ gr.Markdown("""
217
+ ### πŸŽ‰ Next Steps Available:
218
+ - **Add Simulation**: 3D vehicle simulation and testing
219
+ - **Add AI Integration**: LLM-powered design optimization
220
+ - **Add Export Features**: Download designs and specifications
221
+ - **Add Real-time Updates**: Live progress tracking
222
+ """)
223
 
224
  return demo
225
 
226
  if __name__ == "__main__":
227
+ print("πŸ€–πŸš Agent2Robot - Enhanced Working Version")
228
+ print("=" * 60)
229
+ print("🎯 Status: Schema validation issues resolved with Gradio 4.40.0")
230
+ print("πŸš€ Creating enhanced application...")
231
 
232
  try:
233
  app = create_minimal_working_app()
234
+ print("βœ… Enhanced app created successfully")
235
+ print("🌐 Launching application...")
236
+ print("\nπŸ“‹ Launch Options:")
237
+ print(" β€’ Local Access: http://127.0.0.1:7860")
238
+ print(" β€’ For public access, set share=True below")
239
+ print(" β€’ Press Ctrl+C to stop the server")
240
+ print("=" * 60)
241
 
242
+ # Enhanced launch configuration
243
  app.launch(
244
+ server_name="127.0.0.1",
245
  server_port=7860,
246
+ share=False, # Set to True if you need public access
247
  show_error=True,
248
+ inbrowser=True,
249
  quiet=False,
250
+ debug=False,
251
+ show_tips=True,
252
+ enable_queue=True
253
  )
254
+
255
  except Exception as e:
256
+ print(f"❌ Error launching enhanced app: {e}")
 
257
 
258
+ # Fallback options
259
  import traceback
260
  print("\nπŸ” Full error traceback:")
261
  traceback.print_exc()
262
 
263
+ print("\nπŸ”„ Trying fallback launch options...")
 
264
  try:
265
+ # Simple fallback
266
+ app.launch(
267
+ share=True, # Use share as fallback
268
+ debug=True,
269
+ server_name="0.0.0.0"
270
+ )
271
  except Exception as e2:
272
+ print(f"❌ Fallback launch failed: {e2}")
273
+ print("\nπŸ’‘ Troubleshooting suggestions:")
274
+ print(" 1. Check if port 7860 is available")
275
+ print(" 2. Try different Gradio version: pip install gradio==4.40.0")
276
+ print(" 3. Check firewall settings")
277
+ print(" 4. Try running with share=True for public access")
requirements.txt CHANGED
@@ -1,7 +1,11 @@
1
- # Minimal requirements for Phase 1 debugging
2
- gradio>=4.44.1,<5.0.0
3
- # gradio_client will be automatically installed with compatible version by gradio
 
 
4
  certifi>=2022.0.0
 
 
5
  # imageio>=2.20.0
6
  # transformers>=4.21.0
7
  # torch>=1.12.0
@@ -13,4 +17,9 @@ certifi>=2022.0.0
13
  # uvicorn>=0.20.0
14
  # scipy>=1.9.0
15
  # matplotlib>=3.5.0
16
- # imageio-ffmpeg>=0.4.7
 
 
 
 
 
 
1
+ # Enhanced requirements for Agent2Robot - Working Version
2
+ # Core UI Framework (Fixed version that resolves schema validation issues)
3
+ gradio==4.40.0
4
+
5
+ # Essential dependencies
6
  certifi>=2022.0.0
7
+
8
+ # Optional dependencies for future enhancements (commented out for minimal setup)
9
  # imageio>=2.20.0
10
  # transformers>=4.21.0
11
  # torch>=1.12.0
 
17
  # uvicorn>=0.20.0
18
  # scipy>=1.9.0
19
  # matplotlib>=3.5.0
20
+ # imageio-ffmpeg>=0.4.7
21
+
22
+ # Additional useful packages for enhanced functionality
23
+ # pandas>=1.3.0
24
+ # plotly>=5.0.0
25
+ # streamlit>=1.20.0 # Alternative UI framework if needed
test_components.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Component testing to identify schema validation issues
4
+ """
5
+
6
+ import os
7
+ import ssl
8
+
9
+ # SSL fixes
10
+ try:
11
+ import certifi
12
+ os.environ['SSL_CERT_FILE'] = certifi.where()
13
+ os.environ['REQUESTS_CA_BUNDLE'] = certifi.where()
14
+ except ImportError:
15
+ pass
16
+
17
+ ssl._create_default_https_context = ssl._create_unverified_context
18
+ os.environ['PYTHONHTTPSVERIFY'] = '0'
19
+
20
+ import gradio as gr
21
+
22
+ def test_basic_components():
23
+ """Test 1: Basic components only"""
24
+ with gr.Blocks(title="Test 1: Basic") as demo:
25
+ gr.HTML("<h1>Test 1: Basic Components</h1>")
26
+
27
+ vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
28
+ text_input = gr.Textbox(value="test")
29
+ button = gr.Button("Test")
30
+ output = gr.Textbox()
31
+
32
+ button.click(lambda v, t: f"{v}: {t}", [vehicle_input, text_input], output)
33
+
34
+ return demo
35
+
36
+ def test_with_slider():
37
+ """Test 2: Add Slider component"""
38
+ with gr.Blocks(title="Test 2: With Slider") as demo:
39
+ gr.HTML("<h1>Test 2: With Slider</h1>")
40
+
41
+ vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
42
+ text_input = gr.Textbox(value="test")
43
+ slider_input = gr.Slider(0, 100, value=50)
44
+ button = gr.Button("Test")
45
+ output = gr.Textbox()
46
+
47
+ button.click(lambda v, t, s: f"{v}: {t}, {s}", [vehicle_input, text_input, slider_input], output)
48
+
49
+ return demo
50
+
51
+ def test_with_json():
52
+ """Test 3: Add JSON component"""
53
+ with gr.Blocks(title="Test 3: With JSON") as demo:
54
+ gr.HTML("<h1>Test 3: With JSON</h1>")
55
+
56
+ vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
57
+ text_input = gr.Textbox(value="test")
58
+ button = gr.Button("Test")
59
+ output = gr.Textbox()
60
+ json_output = gr.JSON()
61
+
62
+ def test_func(v, t):
63
+ return f"{v}: {t}", {"vehicle": v, "text": t}
64
+
65
+ button.click(test_func, [vehicle_input, text_input], [output, json_output])
66
+
67
+ return demo
68
+
69
+ def test_with_image():
70
+ """Test 4: Add Image component"""
71
+ with gr.Blocks(title="Test 4: With Image") as demo:
72
+ gr.HTML("<h1>Test 4: With Image</h1>")
73
+
74
+ vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
75
+ text_input = gr.Textbox(value="test")
76
+ button = gr.Button("Test")
77
+ output = gr.Textbox()
78
+ image_output = gr.Image()
79
+
80
+ button.click(lambda v, t: (f"{v}: {t}", None), [vehicle_input, text_input], [output, image_output])
81
+
82
+ return demo
83
+
84
+ def test_with_file():
85
+ """Test 5: Add File component"""
86
+ with gr.Blocks(title="Test 5: With File") as demo:
87
+ gr.HTML("<h1>Test 5: With File</h1>")
88
+
89
+ vehicle_input = gr.Radio(choices=["Robot", "Drone"], value="Robot")
90
+ text_input = gr.Textbox(value="test")
91
+ button = gr.Button("Test")
92
+ output = gr.Textbox()
93
+ file_output = gr.File()
94
+
95
+ button.click(lambda v, t: (f"{v}: {t}", None), [vehicle_input, text_input], [output, file_output])
96
+
97
+ return demo
98
+
99
+ if __name__ == "__main__":
100
+ tests = [
101
+ ("Basic Components", test_basic_components),
102
+ ("With Slider", test_with_slider),
103
+ ("With JSON", test_with_json),
104
+ ("With Image", test_with_image),
105
+ ("With File", test_with_file)
106
+ ]
107
+
108
+ for i, (name, test_func) in enumerate(tests, 1):
109
+ print(f"\n{'='*50}")
110
+ print(f"Testing {i}: {name}")
111
+ print(f"{'='*50}")
112
+
113
+ try:
114
+ demo = test_func()
115
+ print(f"βœ… {name} - Demo created successfully")
116
+
117
+ # Try to launch briefly to trigger schema validation
118
+ try:
119
+ demo.launch(
120
+ server_port=7860 + i,
121
+ share=False,
122
+ prevent_thread_lock=True,
123
+ quiet=True
124
+ )
125
+ print(f"βœ… {name} - Launched successfully")
126
+ demo.close()
127
+ except Exception as e:
128
+ print(f"❌ {name} - Launch failed: {e}")
129
+ if "bool" in str(e) and "iterable" in str(e):
130
+ print(f"🎯 FOUND IT! {name} causes the schema error!")
131
+ break
132
+
133
+ except Exception as e:
134
+ print(f"❌ {name} - Creation failed: {e}")
135
+ if "bool" in str(e) and "iterable" in str(e):
136
+ print(f"🎯 FOUND IT! {name} causes the schema error!")
137
+ break
138
+
139
+ print("\n" + "="*50)
140
+ print("Component testing complete!")