Skip to content
Snippets Groups Projects
Commit 5410bb83 authored by jevin3107's avatar jevin3107
Browse files

Main Streamlit File

parent 51a7964e
No related branches found
No related tags found
No related merge requests found
import pandas as pd
import streamlit as st
import matplotlib.pyplot as plt
import altair as alt
import os
from sklearn.preprocessing import LabelEncoder
......@@ -53,49 +52,14 @@ else:
st.title("Airline Chatbot & Data Explorer with Predictions")
# Adding the Bot image
st.image("Chatbot_image.gif", caption="Welcome to the Airline Chatbot & Data Explorer!", use_container_width=True,)
st.image("Chatbot_image.gif", caption="Welcome to the Airline Chatbot & Data Explorer!", use_container_width=True)
# Add navigation
menu = st.sidebar.selectbox("Select a Feature", ["Chatbot", "Data Explorer", "Visualizations", "Predictions"])
def show_chatbot_section():
st.subheader("Chat with Airline Assistant")
if "greeted" not in st.session_state:
st.session_state.greeted = False
if not st.session_state.greeted:
st.write("Hello! I am here to assist you with flight details.")
st.session_state.greeted = True
passenger_id = st.text_input("Please enter your Passenger ID:")
last_name = st.text_input("Please enter your Last Name:")
if st.button("Get Flight Details"):
if not passenger_id:
st.warning("Please enter your Passenger ID.")
elif not last_name:
st.warning("Please enter your Last Name.")
else:
result = df[df.applymap(lambda x: passenger_id.lower() in str(x).lower() if pd.notnull(x) else False).any(axis=1)]
result = result[result["Last Name"].str.lower() == last_name.lower()]
if not result.empty:
st.success("**Here are your flight details:**")
for index, row in result.iterrows():
st.markdown(f"**Passenger ID:** <code>{row['Passenger ID']}</code>", unsafe_allow_html=True)
st.markdown(f"**First Name:** <code>{row['First Name']}</code>", unsafe_allow_html=True)
st.markdown(f"**Last Name:** <code>{row['Last Name']}</code>", unsafe_allow_html=True)
st.markdown(f"**Gender:** <code>{row['Gender']}</code>", unsafe_allow_html=True)
st.markdown(f"**Age:** <code>{row['Age']}</code>", unsafe_allow_html=True)
st.markdown(f"**Nationality:** <code>{row['Nationality']}</code>", unsafe_allow_html=True)
st.markdown(f"**Airport Name:** <code>{row['Airport Name']}</code>", unsafe_allow_html=True)
st.markdown(f"**Departure Date:** <code>{row['Departure Date']}</code>", unsafe_allow_html=True)
st.markdown(f"**Arrival Airport:** <code>{row['Arrival Airport']}</code>", unsafe_allow_html=True)
st.markdown(f"**Pilot Name:** <code>{row['Pilot Name']}</code>", unsafe_allow_html=True)
st.markdown(f"**Flight Status:** <code>{row['Flight Status']}</code>", unsafe_allow_html=True)
st.write("---")
else:
st.error("No matching records found. Please check the Passenger ID or Last Name.")
st.write("Chatbot functionality goes here...")
def show_data_explorer_section():
st.subheader("Explore the Airline Dataset")
......@@ -115,7 +79,7 @@ def show_visualizations_section():
# Flight Status Bar Chart
status_counts = df["Flight Status"].value_counts().reset_index()
status_counts.columns = ["Flight Status", "Count"] # Ensure proper column naming
status_counts.columns = ["Flight Status", "Count"]
status_chart = alt.Chart(status_counts).mark_bar().encode(
x=alt.X("Flight Status", title="Flight Status"),
y=alt.Y("Count", title="Count"),
......@@ -125,7 +89,7 @@ def show_visualizations_section():
# Passenger Nationality Pie Chart
nationality_counts = df["Nationality"].value_counts().reset_index().head(10)
nationality_counts.columns = ["Nationality", "Count"] # Ensure proper column naming
nationality_counts.columns = ["Nationality", "Count"]
nationality_chart = alt.Chart(nationality_counts).mark_arc().encode(
theta="Count",
color="Nationality",
......@@ -152,10 +116,25 @@ def show_predictions_section():
# Model 1 Prediction
if st.button("Predict Satisfaction"):
satisfaction_input = [[age, gender_num, flight_class_num, flight_duration]]
satisfaction_input = pd.DataFrame(
[[age, gender_num, flight_class_num, flight_duration]],
columns=["Age", "Gender", "Flight Class", "Flight Duration"]
)
satisfaction_prediction = model_1.predict(satisfaction_input)
st.write(f"Predicted Passenger Satisfaction: {'Satisfied' if satisfaction_prediction[0] == 1 else 'Not Satisfied'}")
# Generate live graph for Satisfaction Prediction
satisfaction_data = pd.DataFrame({
"Category": ["Not Satisfied", "Satisfied"],
"Prediction": [1 - satisfaction_prediction[0], satisfaction_prediction[0]],
})
satisfaction_chart = alt.Chart(satisfaction_data).mark_bar().encode(
x="Category",
y="Prediction",
color="Category"
).properties(title="Passenger Satisfaction Prediction")
st.altair_chart(satisfaction_chart, use_container_width=True)
st.write("---") # Separator
# Input fields for Model 2 (Flight Delay Prediction)
......@@ -182,11 +161,28 @@ def show_predictions_section():
airport_country_code_encoded = country_code_encoder.transform([airport_country_code])[0]
arrival_airport_encoded = airport_encoder.transform([arrival_airport])[0]
# Prepare input for prediction
delay_input = [[airport_country_code_encoded, arrival_airport_encoded, departure_time]]
# Prepare input for prediction as a DataFrame
delay_input = pd.DataFrame(
[[airport_country_code_encoded, arrival_airport_encoded, departure_time]],
columns=["Airport Country Code", "Arrival Airport", "Departure Time"]
)
# Perform prediction
delay_prediction = model_2.predict(delay_input)
st.write(f"Predicted Flight Delay: {'Delayed' if delay_prediction[0] == 1 else 'On Time'}")
# Generate live graph for Delay Prediction
delay_data = pd.DataFrame({
"Category": ["On Time", "Delayed"],
"Prediction": [1 - delay_prediction[0], delay_prediction[0]],
})
delay_chart = alt.Chart(delay_data).mark_bar().encode(
x="Category",
y="Prediction",
color="Category"
).properties(title="Flight Delay Prediction")
st.altair_chart(delay_chart, use_container_width=True)
except ValueError as e:
st.error(f"Error: {e}. Please ensure the input values are valid and match the training data.")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment