Spaces:
Sleeping
Sleeping
File size: 1,381 Bytes
a9587f9 c4b3cc5 21154f7 404aa40 21154f7 404aa40 21154f7 404aa40 21154f7 | 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 |
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()
|