Spaces:
No application file
No application file
sam133
οΏ½ Fix MCP status and add simulation video: Auto-connect MCP client, display connected status, add MCP simulation generation functionality
07f1a08
| #!/usr/bin/env python3 | |
| """ | |
| Agent2Robot - MCP Hackathon 2024 Submission | |
| AI-Powered Vehicle Design Assistant with MCP Integration | |
| """ | |
| import os | |
| import ssl | |
| import json | |
| # Minimal SSL fix for local development (won't affect HuggingFace Spaces) | |
| try: | |
| # Only apply SSL fix if needed | |
| ssl._create_default_https_context = ssl._create_unverified_context | |
| except: | |
| pass | |
| import gradio as gr | |
| from design_tools import VehicleDesigner | |
| # Initialize the vehicle designer with MCP integration | |
| designer = VehicleDesigner() | |
| def design_vehicle_interface(vehicle_type, description): | |
| """ | |
| Interface function for Gradio that uses MCP-integrated design tools | |
| """ | |
| try: | |
| # Use the MCP-integrated designer with simulation | |
| report, json_output, simulation_info = designer.design_vehicle_with_simulation(vehicle_type, description) | |
| return report, json_output, simulation_info | |
| except Exception as e: | |
| error_msg = f"Error in design process: {str(e)}" | |
| return error_msg, "{\"error\": \"Design process failed\"}", "Simulation failed" | |
| def get_mcp_status(): | |
| """Get MCP server status for display""" | |
| status = designer.get_mcp_status() | |
| return f"MCP Server: {status['name']} v{status['version']} - Status: {status['status']}" | |
| # Create Gradio interface | |
| def create_app(): | |
| with gr.Blocks( | |
| title="π€π Agent2Robot - MCP Hackathon 2024", | |
| theme=gr.themes.Soft() | |
| ) as app: | |
| # Header | |
| gr.HTML(""" | |
| <div style="text-align: center; padding: 20px; background: linear-gradient(90deg, #667eea 0%, #764ba2 100%); color: white; border-radius: 10px; margin-bottom: 20px;"> | |
| <h1>π€π Agent2Robot Design Assistant</h1> | |
| <p>AI-Powered Vehicle Design with MCP Integration</p> | |
| <p><strong>MCP Hackathon 2024 Submission</strong></p> | |
| </div> | |
| """) | |
| # MCP Status Display | |
| with gr.Row(): | |
| gr.Markdown("### π MCP Server Status") | |
| mcp_status = gr.Textbox( | |
| value=get_mcp_status(), | |
| label="Server Connection", | |
| interactive=False | |
| ) | |
| with gr.Row(): | |
| # Input Section | |
| with gr.Column(scale=1): | |
| gr.Markdown("## π― Design Parameters") | |
| vehicle_type = gr.Dropdown( | |
| choices=["Robot", "Drone", "Autonomous Vehicle", "Robotic Arm"], | |
| label="π Vehicle Type", | |
| value="Robot" | |
| ) | |
| description = gr.Textbox( | |
| label="π Design Requirements", | |
| lines=6, | |
| placeholder="Describe your vehicle requirements and specifications...\n\nExample: Design a warehouse robot for navigation and package delivery with 50kg payload capacity, 8-hour operation time, and obstacle avoidance.", | |
| value="Design a robot for warehouse navigation and package delivery" | |
| ) | |
| generate_btn = gr.Button("π Generate Design with MCP", variant="primary", size="lg") | |
| # Output Section | |
| with gr.Column(scale=2): | |
| gr.Markdown("## π MCP Design Results") | |
| design_report = gr.Textbox( | |
| label="π― Complete Design Report", | |
| lines=25, | |
| interactive=False, | |
| show_copy_button=True | |
| ) | |
| design_json = gr.Textbox( | |
| label="π Technical Specifications (JSON)", | |
| lines=12, | |
| interactive=False, | |
| show_copy_button=True | |
| ) | |
| # Simulation Video Section | |
| with gr.Row(): | |
| with gr.Column(): | |
| gr.Markdown("## π¬ MCP Simulation Video") | |
| simulation_output = gr.Textbox( | |
| label="π₯ Simulation Generated via MCP Server", | |
| lines=15, | |
| interactive=False, | |
| show_copy_button=True, | |
| placeholder="Simulation video information will appear here after design generation..." | |
| ) | |
| # Connect functionality | |
| generate_btn.click( | |
| fn=design_vehicle_interface, | |
| inputs=[vehicle_type, description], | |
| outputs=[design_report, design_json, simulation_output] | |
| ) | |
| # Additional MCP Info Section | |
| with gr.Row(): | |
| with gr.Column(): | |
| gr.Markdown(""" | |
| ### π§ MCP Integration Features | |
| **Model Context Protocol (MCP) Integration:** | |
| - **π Server Communication**: Direct integration with MCP servers for design generation | |
| - **π Real-time Validation**: Live design validation through MCP protocols | |
| - **π― Context Awareness**: Maintains design context across sessions | |
| - **π¬ Simulation Generation**: MCP-powered video simulation creation | |
| - **π Scalable Architecture**: Modular design supporting multiple MCP servers | |
| """) | |
| with gr.Column(): | |
| gr.Markdown(""" | |
| ### π MCP Hackathon 2024 - Technical Stack | |
| **Core Components:** | |
| - **MCP Client**: `mcp_client.py` - Handles server communication | |
| - **Design Tools**: `design_tools.py` - Core vehicle design logic | |
| - **Gradio Interface**: `app.py` - User interaction layer | |
| - **Simulation Engine**: MCP-integrated video generation | |
| - **Modular Architecture**: Clean separation of concerns | |
| """) | |
| # Footer | |
| gr.Markdown(""" | |
| --- | |
| ### π Agent2Robot - MCP Hackathon 2024 | |
| **AI-Powered Vehicle Design Assistant** with **Model Context Protocol Integration** | |
| Create optimized designs for robots, drones, autonomous vehicles, and robotic arms using advanced AI algorithms and MCP server communication. | |
| **MCP Features**: Server integration β’ Real-time validation β’ Context preservation β’ Simulation generation β’ Modular architecture | |
| Built with β€οΈ for the MCP Hackathon 2024 | Powered by Gradio + MCP | |
| """) | |
| return app | |
| # Launch the application | |
| if __name__ == "__main__": | |
| app = create_app() | |
| app.launch() |