File size: 1,546 Bytes
6a2f12e
 
 
 
 
 
0384c75
b814d7b
6a2f12e
 
 
b814d7b
 
 
 
 
 
 
 
 
6a2f12e
b814d7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6a2f12e
b814d7b
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import streamlit as st
import pandas as pd

# Load the dataset
@st.cache_data
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.")