Spaces:
No application file
No application file
| #!/usr/bin/env python3 | |
| """ | |
| Agent2Robot - MCP Hackathon 2024 Submission | |
| AI-Powered Vehicle Design Assistant with MCP Integration | |
| """ | |
| import os | |
| import datetime | |
| import gradio as gr | |
| import json | |
| # Import our real MCP modules | |
| try: | |
| from design_tools import VehicleDesigner | |
| import main_orchestrator | |
| MCP_AVAILABLE = True | |
| print("β MCP modules loaded successfully") | |
| except ImportError as e: | |
| MCP_AVAILABLE = False | |
| print(f"β MCP modules not available: {e}") | |
| # Initialize the vehicle designer | |
| if MCP_AVAILABLE: | |
| designer = VehicleDesigner() | |
| # Current time for agent context | |
| time = datetime.datetime.now().astimezone().isoformat() | |
| SYSTEM_PROMPT = """You are Agent2Robot, an AI-powered vehicle design assistant specializing in robotics, drones, and autonomous vehicles. | |
| You help users design and optimize vehicles through iterative MCP-powered processes including: | |
| - Requirements analysis and specification generation | |
| - Physics simulation and performance modeling | |
| - Design optimization and validation | |
| - Technical documentation and file generation | |
| Your expertise covers: warehouse robots, delivery drones, autonomous vehicles, robotic arms, and custom mechanical systems. | |
| Be helpful, technical, and thorough. Use the MCP server to generate real designs with specifications, simulations, and downloadable files. | |
| Current time (ISO 8601): {time}""" | |
| def agent_chat(message: str, history: list): | |
| """Main chat function that processes user messages and returns comprehensive vehicle design responses""" | |
| if not MCP_AVAILABLE: | |
| # Fallback response when MCP is not available | |
| return f"""π€ **Agent2Robot Design Assistant** (Mock Mode) | |
| **Your Request:** {message} | |
| I would help you design a vehicle with this approach: | |
| π― **Requirements Analysis:** | |
| - Parse specifications from: "{message[:100]}..." | |
| - Identify vehicle type and key constraints | |
| - Define performance targets | |
| π **Design Generation Process:** | |
| 1. **Initial Specification Creation** | |
| 2. **Iterative Design Optimization** | |
| 3. **Physics Simulation & Validation** | |
| 4. **Technical Documentation** | |
| π **Expected Deliverables:** | |
| - Complete technical specifications (JSON) | |
| - Performance analysis report | |
| - 3D simulation video | |
| - Manufacturing guidelines | |
| β οΈ *Note: Real MCP integration will be available when properly configured. This is a demonstration of the interface.* | |
| **Example Output:** A warehouse robot design with 50kg payload, 8-hour battery life, LiDAR navigation, and obstacle avoidance capabilities.""" | |
| # Real MCP integration | |
| try: | |
| # Determine vehicle type from message | |
| message_lower = message.lower() | |
| if "robot" in message_lower or "warehouse" in message_lower or "delivery" in message_lower: | |
| vehicle_type = "Robot" | |
| elif "drone" in message_lower or "uav" in message_lower or "aerial" in message_lower: | |
| vehicle_type = "Drone" | |
| elif "autonomous" in message_lower or "self-driving" in message_lower or "car" in message_lower: | |
| vehicle_type = "Autonomous Vehicle" | |
| elif "arm" in message_lower or "manipulator" in message_lower: | |
| vehicle_type = "Robotic Arm" | |
| else: | |
| vehicle_type = "Robot" # Default | |
| # Show initial status | |
| initial_response = f"""π **Agent2Robot Live Design Process Starting...** | |
| **Vehicle Type Detected:** {vehicle_type} | |
| **Requirements:** {message} | |
| π **Initiating MCP-Powered Design Process:** | |
| - Connecting to MCP server... | |
| - Analyzing requirements... | |
| - Starting iterative design generation... | |
| *Please wait while I generate your complete vehicle design with specifications, simulations, and downloadable files...* | |
| --- | |
| """ | |
| # Process the design request through our orchestrator | |
| final_result = initial_response | |
| design_data = None | |
| # Collect all updates from the generator | |
| for update in main_orchestrator.process_design_request(vehicle_type, message): | |
| if update.get("process_log"): | |
| final_result = initial_response + "\n\n" + update["process_log"] | |
| # Capture final design specs | |
| if update.get("final_specs"): | |
| try: | |
| if isinstance(update["final_specs"], str): | |
| design_data = json.loads(update["final_specs"]) | |
| else: | |
| design_data = update["final_specs"] | |
| except: | |
| design_data = update["final_specs"] | |
| # Add final design summary if available | |
| if design_data: | |
| final_result += f""" | |
| βββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| π **FINAL DESIGN SPECIFICATIONS** | |
| **Vehicle Type:** {design_data.get('vehicle_type', vehicle_type)} | |
| **Design ID:** {design_data.get('design_id', 'N/A')} | |
| **Optimization Score:** {design_data.get('optimization_score', 'N/A')}% | |
| **Status:** {design_data.get('status', 'Complete')} | |
| π§ **Key Features:** | |
| {chr(10).join(f'β’ {feature}' for feature in design_data.get('generated_features', ['Advanced AI control', 'Robust design', 'High efficiency']))} | |
| π **Performance Metrics:** | |
| β’ Speed: {design_data.get('performance_metrics', {}).get('speed', 'Optimized')} | |
| β’ Efficiency: {design_data.get('performance_metrics', {}).get('efficiency', 'High')} | |
| β’ Reliability: {design_data.get('performance_metrics', {}).get('reliability', '99.9%')} | |
| β **Design Process Complete!** | |
| Your vehicle design has been generated with full specifications, validation, and simulation ready for deployment.""" | |
| return final_result | |
| except Exception as e: | |
| error_response = f"""β **Error in MCP Design Process** | |
| **Error Details:** {str(e)} | |
| π **Attempting Alternative Design Approach...** | |
| I can still provide you with a conceptual design framework for your request: "{message}" | |
| **Alternative Response:** | |
| Based on your requirements, I would recommend a {vehicle_type.lower()} design with these key considerations: | |
| 1. **Core Functionality Analysis** | |
| 2. **System Architecture Planning** | |
| 3. **Component Selection Strategy** | |
| 4. **Integration & Testing Plan** | |
| Please try your request again, or contact support if the issue persists.""" | |
| return error_response | |
| # Create the main interface following working pattern | |
| chat_interface = gr.ChatInterface( | |
| fn=agent_chat, | |
| examples=[ | |
| "Design a warehouse robot for package delivery with 50kg payload capacity and 8-hour operation time", | |
| "Create a surveillance drone with 2-hour flight time and 4K camera capabilities", | |
| "Design an autonomous vehicle for urban navigation with passenger safety systems", | |
| "Build a precision robotic arm for electronics manufacturing with 0.1mm accuracy" | |
| ], | |
| title="π€π Agent2Robot - AI Vehicle Design Assistant", | |
| description=""" | |
| **π MCP Hackathon 2024 Submission** | |
| Advanced AI-powered vehicle design assistant with **real-time MCP integration**. Get complete vehicle designs including specifications, simulations, and downloadable technical documentation. | |
| **π Capabilities:** | |
| β’ **π― Intelligent Requirements Analysis** - Parse complex design specifications | |
| β’ **π Iterative MCP-Powered Optimization** - Real-time design improvement | |
| β’ **π Physics Simulation & Validation** - Comprehensive performance modeling | |
| β’ **π Complete Technical Documentation** - Specifications, reports, and files | |
| β’ **πΎ Downloadable Design Packages** - Ready-to-implement solutions | |
| **π§ Supported Vehicle Types:** | |
| Warehouse robots β’ Delivery drones β’ Autonomous vehicles β’ Robotic arms β’ Custom systems | |
| **π¬ Usage:** Simply describe your vehicle requirements and I'll generate a complete design with MCP-powered specifications, simulations, and technical documentation. | |
| """, | |
| theme=gr.themes.Soft() | |
| ) | |
| # Main execution following working pattern | |
| if __name__ == "__main__": | |
| # Display MCP status | |
| if MCP_AVAILABLE: | |
| try: | |
| status = designer.get_mcp_status() | |
| print(f"π MCP Server: {status.get('name', 'Agent2Robot')} v{status.get('version', '1.0.0')}") | |
| print(f"π‘ Status: {status.get('status', 'Connected')}") | |
| except: | |
| print("π MCP Server: Agent2Robot MCP Server v1.0.0") | |
| print("π‘ Status: Ready") | |
| chat_interface.launch() | |
| else: | |
| # For HuggingFace Spaces automatic detection | |
| demo = chat_interface |