VIATEUR-AI commited on
Commit
404aa40
Β·
verified Β·
1 Parent(s): c9f51e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -38
app.py CHANGED
@@ -1,39 +1,82 @@
1
 
2
- import gradio as gr
3
- import pandas as pd
4
-
5
- # Sample data: Courses and categories
6
- courses = pd.DataFrame({
7
- "Course": [
8
- "Calculus I", "Physics I", "Programming 101",
9
- "Linear Algebra", "Statistics", "Chemistry",
10
- "Data Structures", "Machine Learning"
11
- ],
12
- "Category": [
13
- "Mathematics", "Physics", "Computer Science",
14
- "Mathematics", "Mathematics", "Chemistry",
15
- "Computer Science", "Computer Science"
16
- ]
17
- })
18
-
19
- # Function to recommend courses based on subject
20
- def recommend_courses(favorite_subject):
21
- recommended = courses[courses["Category"] == favorite_subject]
22
- if recommended.empty:
23
- return "No courses found for this subject."
24
- return "\n".join(recommended["Course"].tolist())
25
-
26
- # Gradio interface with dropdown menu
27
- iface = gr.Interface(
28
- fn=recommend_courses,
29
- inputs=gr.Dropdown(
30
- choices=["Mathematics", "Physics", "Computer Science", "Chemistry"],
31
- label="Select your favorite subject"
32
- ),
33
- outputs=gr.Textbox(label="Recommended Courses"),
34
- title="University Course Recommendation System",
35
- description="Select your favorite subject to get course recommendations!"
36
- )
37
-
38
- # Launch the app
39
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ """)