import gradio as gr # AI decision function def ai_robot_simulator(distance): # AI decision logic if distance > 25: action = "Moving Forward 🚗" robot_movement = "🤖 ➡️ ➡️ ➡️ Moving Forward..." elif 10 < distance <= 25: action = "Slowing Down ⚠️" robot_movement = "🤖 ➡️ ⚠️ Slowing Down..." else: action = "STOP + Turning Right 🔄" robot_movement = "🤖 ⛔ 🔄 Turning Right to Avoid Obstacle..." # Arduino logic code to show arduino_code = """ if (distance > 25) { moveForward(); } else if (distance > 10) { slowDown(); } else { stopRobot(); turnRight(); } """ # Return all outputs return f"Distance: {distance} cm", action, robot_movement, arduino_code # Gradio interface iface = gr.Interface( fn=ai_robot_simulator, inputs=gr.Slider(minimum=0, maximum=100, step=1, label="Set Distance from Obstacle (cm)"), outputs=[ gr.Textbox(label="Sensor Reading"), gr.Textbox(label="AI Decision"), gr.Textbox(label="Robot Movement Simulation"), gr.Code(label="Arduino Logic") ], title="🤖 AI Obstacle Avoiding Robot Simulator", description="Interactive simulation of an Arduino AI robot with ultrasonic sensor. Move the slider to simulate obstacle distance." ) # Launch the app iface.launch()