Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
# Load the dataset
|
| 5 |
+
@st.cache_data
|
| 6 |
+
def load_data():
|
| 7 |
+
return pd.read_csv("bus_routes.csv")
|
| 8 |
+
|
| 9 |
+
data = load_data()
|
| 10 |
+
|
| 11 |
+
st.title("🚌 Karachi Bus Route Finder")
|
| 12 |
+
|
| 13 |
+
start_point = st.text_input("Enter Start Point").strip().title()
|
| 14 |
+
end_point = st.text_input("Enter Destination").strip().title()
|
| 15 |
+
|
| 16 |
+
if st.button("Find Bus Route"):
|
| 17 |
+
if not start_point or not end_point:
|
| 18 |
+
st.warning("Please enter both start point and destination.")
|
| 19 |
+
else:
|
| 20 |
+
found = False
|
| 21 |
+
for idx, row in data.iterrows():
|
| 22 |
+
stops = row["Bus Stops"].split(" -> ")
|
| 23 |
+
if start_point in stops and end_point in stops:
|
| 24 |
+
start_idx = stops.index(start_point)
|
| 25 |
+
end_idx = stops.index(end_point)
|
| 26 |
+
if start_idx < end_idx: # Ensure proper direction
|
| 27 |
+
found = True
|
| 28 |
+
st.success(f"✅ Bus {row['Bus No.']} goes from {start_point} to {end_point}")
|
| 29 |
+
st.write("**Route:**")
|
| 30 |
+
st.markdown(" → ".join(stops))
|
| 31 |
+
if not found:
|
| 32 |
+
st.error("❌ No direct route found with the given start and end points.")
|