VIATEUR-AI commited on
Commit
21154f7
Β·
verified Β·
1 Parent(s): 50623a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -75
app.py CHANGED
@@ -1,82 +1,46 @@
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
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
+ import gradio as gr
3
+
4
+ # AI decision function
5
+ def ai_robot_simulator(distance):
6
+ # AI decision logic
7
+ if distance > 25:
8
+ action = "Moving Forward πŸš—"
9
+ robot_movement = "πŸ€– ➑️ ➑️ ➑️ Moving Forward..."
10
+ elif 10 < distance <= 25:
11
+ action = "Slowing Down ⚠️"
12
+ robot_movement = "πŸ€– ➑️ ⚠️ Slowing Down..."
13
+ else:
14
+ action = "STOP + Turning Right πŸ”„"
15
+ robot_movement = "πŸ€– β›” πŸ”„ Turning Right to Avoid Obstacle..."
16
+
17
+ # Arduino logic code to show
18
+ arduino_code = """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  if (distance > 25) {
20
  moveForward();
21
+ } else if (distance > 10) {
 
22
  slowDown();
23
+ } else {
 
24
  stopRobot();
25
  turnRight();
26
  }
27
+ """
28
+ # Return all outputs
29
+ return f"Distance: {distance} cm", action, robot_movement, arduino_code
30
+
31
+ # Gradio interface
32
+ iface = gr.Interface(
33
+ fn=ai_robot_simulator,
34
+ inputs=gr.Slider(minimum=0, maximum=100, step=1, label="Set Distance from Obstacle (cm)"),
35
+ outputs=[
36
+ gr.Textbox(label="Sensor Reading"),
37
+ gr.Textbox(label="AI Decision"),
38
+ gr.Textbox(label="Robot Movement Simulation"),
39
+ gr.Code(label="Arduino Logic")
40
+ ],
41
+ title="πŸ€– AI Obstacle Avoiding Robot Simulator",
42
+ description="Interactive simulation of an Arduino AI robot with ultrasonic sensor. Move the slider to simulate obstacle distance."
43
+ )
44
+
45
+ # Launch the app
46
+ iface.launch()