Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,29 +4,44 @@ import pandas as pd
|
|
| 4 |
# Load the dataset
|
| 5 |
@st.cache_data
|
| 6 |
def load_data():
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
data = load_data()
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
st.title("🚌 Karachi Bus Route Finder")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 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.")
|
|
|
|
| 4 |
# Load the dataset
|
| 5 |
@st.cache_data
|
| 6 |
def load_data():
|
| 7 |
+
df = pd.read_excel("routes.xlsx")
|
| 8 |
+
return df
|
| 9 |
|
| 10 |
data = load_data()
|
| 11 |
|
| 12 |
+
# Extract unique stops
|
| 13 |
+
all_stops = set()
|
| 14 |
+
for stops in data["Bus Stops"]:
|
| 15 |
+
cleaned_stops = [stop.strip().lower() for stop in stops.split("->")]
|
| 16 |
+
all_stops.update(cleaned_stops)
|
| 17 |
+
|
| 18 |
+
# Sort and title-case for dropdown display
|
| 19 |
+
sorted_stops = sorted([stop.title() for stop in all_stops])
|
| 20 |
+
|
| 21 |
st.title("🚌 Karachi Bus Route Finder")
|
| 22 |
+
st.markdown("Select a **Start Point** and **Destination** to find a direct bus route.")
|
| 23 |
+
|
| 24 |
+
# User input using dropdowns
|
| 25 |
+
start_point = st.selectbox("Select Start Point", sorted_stops)
|
| 26 |
+
end_point = st.selectbox("Select Destination", sorted_stops)
|
| 27 |
+
|
| 28 |
+
# Button to trigger route search
|
| 29 |
+
if st.button("Find Route"):
|
| 30 |
+
start = start_point.lower().strip()
|
| 31 |
+
end = end_point.lower().strip()
|
| 32 |
+
found = False
|
| 33 |
+
|
| 34 |
+
for idx, row in data.iterrows():
|
| 35 |
+
stops = [s.strip().lower() for s in row["Bus Stops"].split("->")]
|
| 36 |
+
if start in stops and end in stops:
|
| 37 |
+
start_idx = stops.index(start)
|
| 38 |
+
end_idx = stops.index(end)
|
| 39 |
+
if start_idx < end_idx:
|
| 40 |
+
found = True
|
| 41 |
+
st.success(f"✅ Bus **{row['Bus No.']}** goes from **{start_point}** to **{end_point}**")
|
| 42 |
+
st.write("**Full Route:**")
|
| 43 |
+
st.markdown(" → ".join([s.title() for s in stops]))
|
| 44 |
+
break
|
| 45 |
|
| 46 |
+
if not found:
|
| 47 |
+
st.error("❌ No direct route found with the given start and end points.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|