Spaces:
Sleeping
Sleeping
Upload 2 files (#1)
Browse files- Upload 2 files (551f45c5c2db069655ef07f715c29fd4d96d4bea)
- app.py +110 -0
- requirements.txt +34 -0
app.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import serial
|
| 3 |
+
import time
|
| 4 |
+
import folium
|
| 5 |
+
from folium.plugins import MarkerCluster
|
| 6 |
+
import io
|
| 7 |
+
import base64
|
| 8 |
+
|
| 9 |
+
# Setup serial connection
|
| 10 |
+
arduino_port = "COM3" # Replace with your Arduino port. If necessary, change to a different port.
|
| 11 |
+
baud_rate = 9600
|
| 12 |
+
|
| 13 |
+
# Check if the port is available before attempting to open it
|
| 14 |
+
try:
|
| 15 |
+
ser = serial.Serial(arduino_port, baud_rate)
|
| 16 |
+
except serial.SerialException as e:
|
| 17 |
+
st.error(f"Error: {e}")
|
| 18 |
+
st.stop() # Stop the script if the serial connection fails
|
| 19 |
+
|
| 20 |
+
# Dummy user credentials (for login)
|
| 21 |
+
USER_CREDENTIALS = {
|
| 22 |
+
"admin": "password123", # Username: admin, Password: password123
|
| 23 |
+
"user1": "mypassword" # Username: user1, Password: mypassword
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
# Function to display login page
|
| 27 |
+
def login_page():
|
| 28 |
+
st.title("Bus System Status Monitoring")
|
| 29 |
+
st.subheader("Please login to access the system")
|
| 30 |
+
|
| 31 |
+
# Input for username and password
|
| 32 |
+
username = st.text_input("Username", "")
|
| 33 |
+
password = st.text_input("Password", "", type="password")
|
| 34 |
+
|
| 35 |
+
# Check if the user submits the login form
|
| 36 |
+
if st.button("Login"):
|
| 37 |
+
if username in USER_CREDENTIALS and USER_CREDENTIALS[username] == password:
|
| 38 |
+
st.success("Login Successful!")
|
| 39 |
+
return username # return username to proceed to the monitoring page
|
| 40 |
+
else:
|
| 41 |
+
st.error("Invalid credentials, please try again.")
|
| 42 |
+
return None
|
| 43 |
+
|
| 44 |
+
# Function to read data from Arduino (simulating bus data including GPS location)
|
| 45 |
+
def read_data_from_arduino():
|
| 46 |
+
bus_name = ""
|
| 47 |
+
seat_status = ""
|
| 48 |
+
distance = 0
|
| 49 |
+
latitude = 0.0
|
| 50 |
+
longitude = 0.0
|
| 51 |
+
|
| 52 |
+
while True:
|
| 53 |
+
if ser.in_waiting > 0:
|
| 54 |
+
data = ser.readline().decode('utf-8').strip()
|
| 55 |
+
if "Bus Name:" in data:
|
| 56 |
+
bus_name = data.split("Bus Name: ")[1]
|
| 57 |
+
if "Seat Status:" in data:
|
| 58 |
+
seat_status = data.split("Seat Status: ")[1]
|
| 59 |
+
if "Distance:" in data:
|
| 60 |
+
distance = int(data.split("Distance: ")[1])
|
| 61 |
+
if "Latitude:" in data:
|
| 62 |
+
latitude = float(data.split("Latitude: ")[1])
|
| 63 |
+
if "Longitude:" in data:
|
| 64 |
+
longitude = float(data.split("Longitude: ")[1])
|
| 65 |
+
|
| 66 |
+
# Display data in Streamlit
|
| 67 |
+
st.subheader(f"Bus Name: {bus_name}")
|
| 68 |
+
st.subheader(f"Seat Status: {seat_status}")
|
| 69 |
+
st.subheader(f"Distance to Bus: {distance} cm")
|
| 70 |
+
st.subheader(f"Latitude: {latitude}, Longitude: {longitude}")
|
| 71 |
+
|
| 72 |
+
# Plot Bus on Map
|
| 73 |
+
plot_map(latitude, longitude)
|
| 74 |
+
|
| 75 |
+
time.sleep(1) # Delay for 1 second before reading next set of data
|
| 76 |
+
|
| 77 |
+
# Function to plot the map with the bus location
|
| 78 |
+
def plot_map(latitude, longitude):
|
| 79 |
+
# Create a map centered around the bus location
|
| 80 |
+
bus_map = folium.Map(location=[latitude, longitude], zoom_start=15)
|
| 81 |
+
|
| 82 |
+
# Add a marker for the bus location
|
| 83 |
+
folium.Marker([latitude, longitude], popup="Bus Location").add_to(bus_map)
|
| 84 |
+
|
| 85 |
+
# Render the map in Streamlit
|
| 86 |
+
st.subheader("Real-Time Bus Location")
|
| 87 |
+
# Save the map to a PNG image
|
| 88 |
+
map_stream = io.BytesIO()
|
| 89 |
+
bus_map.save(map_stream, close_file=False)
|
| 90 |
+
|
| 91 |
+
# Convert the map to base64 for display in Streamlit
|
| 92 |
+
map_stream.seek(0)
|
| 93 |
+
map_data = base64.b64encode(map_stream.getvalue()).decode()
|
| 94 |
+
st.markdown(f'<img src="data:image/png;base64,{map_data}" width="100%" />', unsafe_allow_html=True)
|
| 95 |
+
|
| 96 |
+
# Main function for the Streamlit app
|
| 97 |
+
def main():
|
| 98 |
+
# Show the login page
|
| 99 |
+
username = login_page()
|
| 100 |
+
|
| 101 |
+
# If the user is logged in, show the bus system page
|
| 102 |
+
if username:
|
| 103 |
+
st.write("Loading the Bus System Monitoring Dashboard...")
|
| 104 |
+
|
| 105 |
+
# Run the real-time data reading from Arduino
|
| 106 |
+
read_data_from_arduino()
|
| 107 |
+
|
| 108 |
+
# Run the app
|
| 109 |
+
if __name__ == "__main__":
|
| 110 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
PyPDF2
|
| 2 |
+
streamlit
|
| 3 |
+
transformers
|
| 4 |
+
gspread
|
| 5 |
+
google-auth
|
| 6 |
+
pandas
|
| 7 |
+
matplotlib
|
| 8 |
+
reportlab
|
| 9 |
+
SpeechRecognition
|
| 10 |
+
google-auth-oauthlib
|
| 11 |
+
google-auth-httplib2
|
| 12 |
+
plotly
|
| 13 |
+
torch
|
| 14 |
+
datasets
|
| 15 |
+
vaderSentiment
|
| 16 |
+
seaborn
|
| 17 |
+
fuzzywuzzy
|
| 18 |
+
pygame
|
| 19 |
+
gradio
|
| 20 |
+
gym
|
| 21 |
+
stable-baselines3
|
| 22 |
+
Flask-SocketIO
|
| 23 |
+
pyserial
|
| 24 |
+
xgboost
|
| 25 |
+
elasticsearch
|
| 26 |
+
graphviz
|
| 27 |
+
folium
|
| 28 |
+
pyserial==3.5
|
| 29 |
+
streamlit-leaflet==0.1.0
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|