Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| # Load the dataset | |
| def load_data(): | |
| df = pd.read_excel("bus_routes.csv") | |
| return df | |
| data = load_data() | |
| # Extract unique stops | |
| all_stops = set() | |
| for stops in data["Bus Stops"]: | |
| cleaned_stops = [stop.strip().lower() for stop in stops.split("->")] | |
| all_stops.update(cleaned_stops) | |
| # Sort and title-case for dropdown display | |
| sorted_stops = sorted([stop.title() for stop in all_stops]) | |
| st.title("🚌 Karachi Bus Route Finder") | |
| st.markdown("Select a **Start Point** and **Destination** to find a direct bus route.") | |
| # User input using dropdowns | |
| start_point = st.selectbox("Select Start Point", sorted_stops) | |
| end_point = st.selectbox("Select Destination", sorted_stops) | |
| # Button to trigger route search | |
| if st.button("Find Route"): | |
| start = start_point.lower().strip() | |
| end = end_point.lower().strip() | |
| found = False | |
| for idx, row in data.iterrows(): | |
| stops = [s.strip().lower() for s in row["Bus Stops"].split("->")] | |
| if start in stops and end in stops: | |
| start_idx = stops.index(start) | |
| end_idx = stops.index(end) | |
| if start_idx < end_idx: | |
| found = True | |
| st.success(f"✅ Bus **{row['Bus No.']}** goes from **{start_point}** to **{end_point}**") | |
| st.write("**Full Route:**") | |
| st.markdown(" → ".join([s.title() for s in stops])) | |
| break | |
| if not found: | |
| st.error("❌ No direct route found with the given start and end points.") | |