RECOMENDATION / app.py
VIATEUR-AI's picture
Update app.py
c4b3cc5 verified
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()