shukdevdatta123's picture
Update app.py
3ed15d0 verified
raw
history blame
4.73 kB
import streamlit as st
import pandas as pd
# Load the Excel file
file_path = 'Dhaka Metro Rail Fare 2.XLSX' # Ensure the correct file path
df = pd.read_excel(file_path)
# Ensure necessary columns are present
required_columns = ['Origin', 'Destination', 'Fare (ΰ§³)']
if not all(col in df.columns for col in required_columns):
st.write("Please ensure the file contains 'Origin', 'Destination', and 'Fare' columns.")
else:
# Streamlit UI setup
st.title("Dhaka Metro Rail Fare Checker πŸš‡")
st.write("Below is the fare chart for Dhaka Metro Rail πŸ’Ά:")
# Instruction sidebar
st.sidebar.title("Instructions")
st.sidebar.write("""
**Welcome to the Dhaka Metro Rail Fare Checker!**
*How to use:*
1. Select your **Location station** from the dropdown menu.
2. Select your **destination(s)** by clicking the destination buttons.
3. The fare from your location to the selected destination(s) will be displayed below.
4. You can select multiple destinations to check the fares for all of them.
**Note:** Please select a valid origin station first.
If you face any issues or need further assistance, feel free to [Contact Support on WhatsApp](https://wa.me/+8801719296601).
""")
# Define the default "Select Journey from" message
default_origin = "Select Journey from"
# Dropdown for selecting origin (with "Select Journey from" as a default placeholder)
origin = st.selectbox(
"Select your Location:",
[default_origin] + df['Origin'].unique().tolist(), # Add the "Select Journey from" option at the top
index=0 # Ensure the first option is selected by default
)
# Initialize session state for destination selection if not already set
if 'destination_select' not in st.session_state:
st.session_state.destination_select = []
# Display buttons for each destination in 3 columns
if origin != default_origin:
st.write(f"Select your destination(s) from {origin}:")
# Create 3 columns
cols = st.columns(3)
# Loop through all possible destinations and create a button for each in the columns
dest_buttons = df['Destination'].unique()
for i, dest in enumerate(dest_buttons):
col_idx = i % 3 # Determine column index based on button position
with cols[col_idx]:
if st.button(f"Select {dest}", key=f"btn_{dest}"):
if dest not in st.session_state.destination_select:
st.session_state.destination_select.append(dest)
else:
st.session_state.destination_select.remove(dest)
# Clear all selected destinations button
if st.button("Clear All Destinations"):
st.session_state.destination_select = []
# Display selected destinations and calculate fares
destinations = st.session_state.destination_select
if origin == default_origin:
st.write("Please select a valid origin station to proceed.")
elif origin and destinations:
# Filter the dataframe based on user selection
fare_data = df[(df['Origin'] == origin) & (df['Destination'].isin(destinations))]
# Display the fare data
# Display the fare data in a creative and aesthetic format
if not fare_data.empty:
for index, row in fare_data.iterrows():
origin_to_dest_fare = row['Fare (ΰ§³)']
destination = row['Destination']
# Creative output with icons, emojis, and styled text
fare_message = f"""
<div style="background-color: #f0f8ff; padding: 10px; margin-bottom: 12px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);">
<h4 style="font-family: 'Arial', sans-serif; color: #003366;">
πŸš‡ <strong>{origin}</strong> to <strong>{destination}</strong> Fare
</h4>
<p style="font-family: 'Arial', sans-serif; font-size: 18px; color: #009688;">
πŸ’΅ Fare: <strong style="font-size: 20px; color: #e91e63;">{origin_to_dest_fare}ΰ§³</strong>
</p>
<p style="font-family: 'Arial', sans-serif; font-size: 14px; color: #555555;">
✨ Enjoy your journey on the Dhaka Metro! πŸš‰
</p>
</div>
"""
st.markdown(fare_message, unsafe_allow_html=True)
else:
st.write("No fare data available for the selected origin and destinations.")
else:
st.write("Please select both an origin and at least one destination.")