Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,82 @@
|
|
| 1 |
|
| 2 |
-
|
| 3 |
-
import
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
+
# Page setup
|
| 6 |
+
st.set_page_config(page_title="AI Robot Simulator", layout="centered")
|
| 7 |
+
|
| 8 |
+
st.title("π€ AI Obstacle Avoiding Robot Simulator")
|
| 9 |
+
st.markdown("### Online Simulation of Arduino AI Decision-Making")
|
| 10 |
+
|
| 11 |
+
st.markdown("---")
|
| 12 |
+
|
| 13 |
+
# Sensor Input
|
| 14 |
+
st.subheader("π‘ Ultrasonic Sensor Input")
|
| 15 |
+
|
| 16 |
+
distance = st.slider("Set Distance from Obstacle (cm)", 0, 100, 50)
|
| 17 |
+
|
| 18 |
+
st.write(f"**Current Distance:** {distance} cm")
|
| 19 |
+
|
| 20 |
+
st.markdown("---")
|
| 21 |
+
|
| 22 |
+
# AI Decision Logic
|
| 23 |
+
st.subheader("π§ AI Robot Decision System")
|
| 24 |
+
|
| 25 |
+
action = ""
|
| 26 |
+
|
| 27 |
+
if distance > 25:
|
| 28 |
+
action = "Moving Forward π"
|
| 29 |
+
st.success(action)
|
| 30 |
+
|
| 31 |
+
elif 10 < distance <= 25:
|
| 32 |
+
action = "Slowing Down β οΈ"
|
| 33 |
+
st.warning(action)
|
| 34 |
+
|
| 35 |
+
else:
|
| 36 |
+
action = "STOP + Turning Right π"
|
| 37 |
+
st.error(action)
|
| 38 |
+
|
| 39 |
+
# Robot Animation
|
| 40 |
+
st.markdown("---")
|
| 41 |
+
st.subheader("π₯ Robot Movement Simulation")
|
| 42 |
+
|
| 43 |
+
robot = st.empty()
|
| 44 |
+
|
| 45 |
+
if "Forward" in action:
|
| 46 |
+
for i in range(3):
|
| 47 |
+
robot.markdown("π€ β‘οΈ β‘οΈ β‘οΈ")
|
| 48 |
+
time.sleep(0.3)
|
| 49 |
+
|
| 50 |
+
elif "Slowing" in action:
|
| 51 |
+
for i in range(2):
|
| 52 |
+
robot.markdown("π€ β‘οΈ β οΈ")
|
| 53 |
+
time.sleep(0.5)
|
| 54 |
+
|
| 55 |
+
else:
|
| 56 |
+
for i in range(2):
|
| 57 |
+
robot.markdown("π€ β π")
|
| 58 |
+
time.sleep(0.6)
|
| 59 |
+
|
| 60 |
+
# Arduino Code Explanation
|
| 61 |
+
st.markdown("---")
|
| 62 |
+
st.subheader("π» Arduino AI Logic Used")
|
| 63 |
+
|
| 64 |
+
st.code("""
|
| 65 |
+
if (distance > 25) {
|
| 66 |
+
moveForward();
|
| 67 |
+
}
|
| 68 |
+
else if (distance > 10) {
|
| 69 |
+
slowDown();
|
| 70 |
+
}
|
| 71 |
+
else {
|
| 72 |
+
stopRobot();
|
| 73 |
+
turnRight();
|
| 74 |
+
}
|
| 75 |
+
""")
|
| 76 |
+
|
| 77 |
+
# Project Info
|
| 78 |
+
st.markdown("---")
|
| 79 |
+
st.info("""
|
| 80 |
+
β
This simulator represents an AI-based obstacle avoiding robot
|
| 81 |
+
Built with Streamlit for Hugging Face Spaces deployment.
|
| 82 |
+
""")
|