Agent2Robot / app.py
sam133
οΏ½ PHASE 5
0fe9c4b
raw
history blame
7.82 kB
#!/usr/bin/env python3
"""
Agent2Robot - MINIMAL WORKING VERSION
Based on successful Step 4 but with simple return function
"""
import os
import ssl
# Multiple SSL fixes for Windows/conda environments
try:
# Try to fix SSL certificate path
import certifi
os.environ['SSL_CERT_FILE'] = certifi.where()
os.environ['REQUESTS_CA_BUNDLE'] = certifi.where()
except ImportError:
print("⚠️ Warning: certifi not available, using alternative SSL fix")
# Disable SSL verification if needed (for development only)
ssl._create_default_https_context = ssl._create_unverified_context
# Alternative approach: Set empty SSL_CERT_FILE if the current one is problematic
if 'SSL_CERT_FILE' in os.environ:
try:
with open(os.environ['SSL_CERT_FILE'], 'r') as f:
pass # Test if file is readable
except:
# If the current SSL_CERT_FILE is problematic, try to unset it
del os.environ['SSL_CERT_FILE']
try:
import certifi
os.environ['SSL_CERT_FILE'] = certifi.where()
except:
pass
import gradio as gr
def simple_test_function(vehicle_type, user_description):
"""Simple test function that returns results like Step 4 worked"""
if not user_description:
user_description = "No description provided"
# Simple return (like Step 4 but with return instead of yield)
text_output = f"βœ… COMPLETED!\nVehicle: {vehicle_type}\nDescription: {user_description}\nTest successful!"
json_output = {
"vehicle_type": vehicle_type,
"description": user_description,
"test_status": "success",
"parameters": {
"speed": 5.2,
"weight": 1.8,
"dimensions": [10, 8, 6]
}
}
progress_value = 100
image_output = None
file_output = None
return text_output, json_output, progress_value, image_output, file_output
def create_minimal_working_app():
"""MINIMAL working app based on successful Step 4"""
# Exact same CSS as Step 4 (worked)
custom_css = """
.main-header {
text-align: center;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
border-radius: 15px;
margin-bottom: 20px;
box-shadow: 0 8px 16px rgba(0,0,0,0.1);
}
"""
with gr.Blocks(
title="πŸ€–πŸš Agent2Robot - MINIMAL WORKING",
theme=gr.themes.Soft(),
css=custom_css
) as demo:
# Exact same header as Step 4 (worked)
gr.HTML("""
<div class="main-header">
<h1>πŸ€–πŸš Agent2Robot</h1>
<h2>MINIMAL WORKING VERSION</h2>
<p><strong>Based on successful Step 4 components</strong></p>
</div>
""")
# Exact same layout as Step 4 (worked)
gr.Markdown("## πŸ”§ MINIMAL WORKING TEST")
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("## 🎯 1. Define Your Vehicle Challenge")
# Exact same components as Step 4 (worked)
vehicle_type_input = gr.Radio(
choices=["Robot", "Drone"],
label="1. Choose Vehicle Type",
value="Robot",
info="Select whether you want a ground robot or flying drone"
)
user_description_input = gr.Textbox(
lines=5,
label="2. Describe Vehicle's Task & Success Criteria",
placeholder="e.g., 'Design a robot that can cross the 5cm box obstacle quickly and without tipping over, then stop safely.'",
value="Design a robot that can cross the 5cm high obstacle smoothly and come to a controlled stop."
)
start_button = gr.Button(
"πŸš€ Start AI Design Process",
variant="primary",
size="lg"
)
gr.Markdown("""
### πŸ“‹ Status
- **Version**: Minimal working (Step 4 base)
- **Function**: Simple return (no yield)
- **Goal**: Isolate the problematic component
""")
with gr.Column(scale=2):
gr.Markdown("## πŸ€– 2. Test Outputs")
# Exact same output components as Step 4 (worked)
output_textbox = gr.Textbox(
label="πŸ“ Text Output",
lines=5,
value="",
interactive=False
)
with gr.Row():
current_design_specs_output = gr.JSON(
label="βš™οΈ JSON Output Test",
value={}
)
progress_bar_output = gr.Slider(
minimum=0,
maximum=100,
step=1,
label="Progress (%)",
interactive=False,
show_label=True,
value=0
)
simulation_video_output = gr.Image(
label="🎬 Image Output Test",
interactive=False,
height=200,
value=None
)
download_json_output = gr.File(
label="πŸ“„ File Output Test",
file_count="single",
type="filepath",
interactive=True,
value=None
)
# Simple button connection (5 outputs like Step 4)
start_button.click(
fn=simple_test_function,
inputs=[vehicle_type_input, user_description_input],
outputs=[
output_textbox,
current_design_specs_output,
progress_bar_output,
simulation_video_output,
download_json_output
]
)
gr.Markdown("---")
gr.Markdown("**Status**: If this works, we can add components one by one to find the problematic one.")
return demo
if __name__ == "__main__":
print("πŸ”§ Agent2Robot - MINIMAL WORKING VERSION")
print("=" * 50)
print("πŸš€ Testing minimal working components...")
try:
app = create_minimal_working_app()
print("βœ… App created successfully")
print("🌐 Launching with share=True (since localhost not accessible)...")
app.launch(
server_name="0.0.0.0",
server_port=7860,
share=True, # Fixed: Set to True since localhost is not accessible
show_error=True,
inbrowser=False, # Changed to False to avoid browser issues
quiet=False,
debug=True # Added debug mode for better error reporting
)
except Exception as e:
print(f"❌ Error launching app: {e}")
print("Even minimal version has issues!")
# Additional debugging information
import traceback
print("\nπŸ” Full error traceback:")
traceback.print_exc()
# Try alternative launch with minimal options
print("\nπŸ”„ Trying alternative launch configuration...")
try:
app.launch(share=True, debug=True)
except Exception as e2:
print(f"❌ Alternative launch also failed: {e2}")
print("Please check Gradio installation and dependencies.")