Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Airline Dataset
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dhruvang Patel
Airline Dataset
Commits
5410bb83
Commit
5410bb83
authored
2 months ago
by
jevin3107
Browse files
Options
Downloads
Patches
Plain Diff
Main Streamlit File
parent
51a7964e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app.py
+39
-43
39 additions, 43 deletions
app.py
with
39 additions
and
43 deletions
app.py
+
39
−
43
View file @
5410bb83
import
pandas
as
pd
import
pandas
as
pd
import
streamlit
as
st
import
streamlit
as
st
import
matplotlib.pyplot
as
plt
import
altair
as
alt
import
altair
as
alt
import
os
import
os
from
sklearn.preprocessing
import
LabelEncoder
from
sklearn.preprocessing
import
LabelEncoder
...
@@ -53,49 +52,14 @@ else:
...
@@ -53,49 +52,14 @@ else:
st
.
title
(
"
Airline Chatbot & Data Explorer with Predictions
"
)
st
.
title
(
"
Airline Chatbot & Data Explorer with Predictions
"
)
# Adding the Bot image
# 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
# Add navigation
menu
=
st
.
sidebar
.
selectbox
(
"
Select a Feature
"
,
[
"
Chatbot
"
,
"
Data Explorer
"
,
"
Visualizations
"
,
"
Predictions
"
])
menu
=
st
.
sidebar
.
selectbox
(
"
Select a Feature
"
,
[
"
Chatbot
"
,
"
Data Explorer
"
,
"
Visualizations
"
,
"
Predictions
"
])
def
show_chatbot_section
():
def
show_chatbot_section
():
st
.
subheader
(
"
Chat with Airline Assistant
"
)
st
.
subheader
(
"
Chat with Airline Assistant
"
)
st
.
write
(
"
Chatbot functionality goes here...
"
)
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.
"
)
def
show_data_explorer_section
():
def
show_data_explorer_section
():
st
.
subheader
(
"
Explore the Airline Dataset
"
)
st
.
subheader
(
"
Explore the Airline Dataset
"
)
...
@@ -115,7 +79,7 @@ def show_visualizations_section():
...
@@ -115,7 +79,7 @@ def show_visualizations_section():
# Flight Status Bar Chart
# Flight Status Bar Chart
status_counts
=
df
[
"
Flight Status
"
].
value_counts
().
reset_index
()
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
(
status_chart
=
alt
.
Chart
(
status_counts
).
mark_bar
().
encode
(
x
=
alt
.
X
(
"
Flight Status
"
,
title
=
"
Flight Status
"
),
x
=
alt
.
X
(
"
Flight Status
"
,
title
=
"
Flight Status
"
),
y
=
alt
.
Y
(
"
Count
"
,
title
=
"
Count
"
),
y
=
alt
.
Y
(
"
Count
"
,
title
=
"
Count
"
),
...
@@ -125,7 +89,7 @@ def show_visualizations_section():
...
@@ -125,7 +89,7 @@ def show_visualizations_section():
# Passenger Nationality Pie Chart
# Passenger Nationality Pie Chart
nationality_counts
=
df
[
"
Nationality
"
].
value_counts
().
reset_index
().
head
(
10
)
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
(
nationality_chart
=
alt
.
Chart
(
nationality_counts
).
mark_arc
().
encode
(
theta
=
"
Count
"
,
theta
=
"
Count
"
,
color
=
"
Nationality
"
,
color
=
"
Nationality
"
,
...
@@ -152,10 +116,25 @@ def show_predictions_section():
...
@@ -152,10 +116,25 @@ def show_predictions_section():
# Model 1 Prediction
# Model 1 Prediction
if
st
.
button
(
"
Predict Satisfaction
"
):
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
)
satisfaction_prediction
=
model_1
.
predict
(
satisfaction_input
)
st
.
write
(
f
"
Predicted Passenger Satisfaction:
{
'
Satisfied
'
if
satisfaction_prediction
[
0
]
==
1
else
'
Not Satisfied
'
}
"
)
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
st
.
write
(
"
---
"
)
# Separator
# Input fields for Model 2 (Flight Delay Prediction)
# Input fields for Model 2 (Flight Delay Prediction)
...
@@ -182,11 +161,28 @@ def show_predictions_section():
...
@@ -182,11 +161,28 @@ def show_predictions_section():
airport_country_code_encoded
=
country_code_encoder
.
transform
([
airport_country_code
])[
0
]
airport_country_code_encoded
=
country_code_encoder
.
transform
([
airport_country_code
])[
0
]
arrival_airport_encoded
=
airport_encoder
.
transform
([
arrival_airport
])[
0
]
arrival_airport_encoded
=
airport_encoder
.
transform
([
arrival_airport
])[
0
]
# Prepare input for prediction
# Prepare input for prediction as a DataFrame
delay_input
=
[[
airport_country_code_encoded
,
arrival_airport_encoded
,
departure_time
]]
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
)
delay_prediction
=
model_2
.
predict
(
delay_input
)
st
.
write
(
f
"
Predicted Flight Delay:
{
'
Delayed
'
if
delay_prediction
[
0
]
==
1
else
'
On Time
'
}
"
)
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
:
except
ValueError
as
e
:
st
.
error
(
f
"
Error:
{
e
}
. Please ensure the input values are valid and match the training data.
"
)
st
.
error
(
f
"
Error:
{
e
}
. Please ensure the input values are valid and match the training data.
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment