Spaces:
No application file
No application file
sam133
Refactor: Restructure codebase with modular design patterns and fix orchestrator implementation
9529bc2
| import os | |
| import gradio as gr | |
| from ..core.orchestrator import DesignOrchestrator | |
| # Optimize for Hugging Face Spaces | |
| os.environ["GRADIO_ANALYTICS_ENABLED"] = "False" | |
| os.environ["GRADIO_TEMP_DIR"] = "/tmp" | |
| os.environ["TRANSFORMERS_CACHE"] = "/tmp/transformers_cache" | |
| os.environ["HF_HOME"] = "/tmp/hf_home" | |
| class GradioInterface: | |
| def __init__(self): | |
| self.orchestrator = DesignOrchestrator() | |
| def create_interface(self): | |
| with gr.Blocks(title="Agent2Robot - AI-Powered Vehicle Design") as interface: | |
| gr.Markdown(""" | |
| # π€ Agent2Robot - Real LLM-Physics Integration System | |
| Transform robot design with AI-driven physics simulation! | |
| """) | |
| with gr.Row(): | |
| with gr.Column(): | |
| prompt = gr.Textbox( | |
| label="Design Requirements", | |
| placeholder="Enter your robot design requirements...", | |
| lines=3 | |
| ) | |
| vehicle_type = gr.Dropdown( | |
| choices=["wheeled", "tracked", "legged"], | |
| value="wheeled", | |
| label="Vehicle Type" | |
| ) | |
| max_iterations = gr.Slider( | |
| minimum=1, | |
| maximum=5, | |
| value=3, | |
| step=1, | |
| label="Max Iterations" | |
| ) | |
| submit_btn = gr.Button("π Design Robot") | |
| with gr.Column(): | |
| design_json = gr.JSON(label="Design Specifications") | |
| process_log = gr.Textbox(label="Process Log", lines=10) | |
| simulation_gif = gr.Image(label="Simulation Results") | |
| results_json = gr.JSON(label="Simulation Results") | |
| def process_design(prompt_text: str, v_type: str, iterations: int): | |
| if not prompt_text.strip(): | |
| return None, "Please enter design requirements", None, None | |
| try: | |
| design_json, process_log, gif_path, results = self.orchestrator.process_design_request( | |
| prompt=prompt_text, | |
| vehicle_type=v_type, | |
| max_iterations=iterations | |
| ) | |
| return design_json, process_log, gif_path, results | |
| except Exception as e: | |
| return None, f"Error: {str(e)}", None, None | |
| submit_btn.click( | |
| fn=process_design, | |
| inputs=[prompt, vehicle_type, max_iterations], | |
| outputs=[design_json, process_log, simulation_gif, results_json] | |
| ) | |
| gr.Markdown(""" | |
| ## How it works | |
| 1. Enter your design requirements | |
| 2. Select vehicle type and max iterations | |
| 3. Click "Design Robot" to start the AI-Physics process | |
| 4. View the results in real-time | |
| The system will: | |
| - Generate robot designs using AI | |
| - Simulate them in a physics engine | |
| - Optimize based on performance | |
| - Show you the results | |
| """) | |
| return interface | |
| def create_app(): | |
| interface = GradioInterface() | |
| return interface.create_interface() | |
| if __name__ == "__main__": | |
| app = create_app() | |
| app.launch(server_name="0.0.0.0", server_port=7861) |