File size: 3,597 Bytes
9529bc2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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)