shukdevdatta123's picture
Update app.py
b4dc1f8 verified
raw
history blame
2.72 kB
import streamlit as st
import pandas as pd
# Load the Excel file into a DataFrame (adjust the file path accordingly)
df = pd.read_excel('Book1.xlsx')
# Clean up the DataFrame (strip any unnecessary whitespaces in column names)
df.columns = df.columns.str.strip()
# Function to clean routes and remove unwanted characters
def clean_route(route):
# Remove the "_x000D_" carriage return issue and other unwanted characters
return route.replace("_x000D_", "").strip()
# Function to search buses by location
def search_by_location(location):
# Filter buses that have the location in their routes
buses_with_location = df[df['Routes'].str.contains(location, case=False, na=False)]
return buses_with_location
# Function to get the route of a selected bus
def get_route_by_bus(bus_name):
# Get the route for the selected bus
bus_route = df[df['Dhaka Local Buses'] == bus_name]['Routes'].values
if len(bus_route) > 0:
return clean_route(bus_route[0]) # Clean the route before returning
else:
return "No route found for this bus."
# Streamlit app
def main():
st.title("Dhaka Local 🚌 and 🏞 Finder")
# Bus Name Search Section
st.header("Search Bus Name")
# Add a placeholder as the default option for the selectbox
bus_name = st.selectbox(
'Select a Bus Name from dropdown',
['Select Bus Name from dropdown'] + df['Dhaka Local Buses'].tolist() # Adding the placeholder at the beginning
)
if bus_name != 'Select Bus Name from dropdown': # Proceed only if a valid bus is selected
route = get_route_by_bus(bus_name)
st.write(f"Routes for **{bus_name}**:")
st.write(route)
# Expander for location names (moved here)
with st.expander("Bus Names for your assistance!!!", expanded=False):
st.write(
"Achim Paribahan Bus Route (আছিম পরিবহন), Active Paribahan Bus Route (এক্টিভ পরিবহন), Agradut Bus Route (অগ্রদূত), Airport Bangabandhu Avenue Bus Route(এয়ারপোর্ট বঙ্গবন্ধু এভিনিউ ট্রান্সপোর্ট), Ajmeri Glory Bus Route (আজমেরী গ্লোরী), ..."
)
# Layout hack using empty and columns for bottom-right placement
col1, col2 = st.columns([1, 6]) # The first column is narrow
with col2:
# Place the image in the bottom-right of the screen
st.image("149656-200.png", width=150, height=150)
# Add space at the bottom to simulate the "bottom-right" positioning
st.markdown("<br><br><br><br>", unsafe_allow_html=True)
if __name__ == "__main__":
main()