Spaces:
Sleeping
Sleeping
| 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() | |