Spaces:
Sleeping
Sleeping
Update pages/Hotel Data.py
Browse files- pages/Hotel Data.py +28 -20
pages/Hotel Data.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
import os
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Define a persistent file path for the dataset
|
| 6 |
DATA_FILE_PATH = "dataset.csv"
|
|
@@ -8,22 +8,16 @@ DATA_FILE_PATH = "dataset.csv"
|
|
| 8 |
# Page Title
|
| 9 |
st.markdown("<h1 style='text-align:center; color:yellow;'>Hotel Data Set</h1>", unsafe_allow_html=True)
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
st.subheader("Current Dataset (Previously Uploaded):")
|
| 18 |
-
st.write(df) # Display the first 5 rows of the dataset
|
| 19 |
-
|
| 20 |
-
st.subheader("Dataset Description:")
|
| 21 |
-
st.write(df.describe())
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
st.info("No dataset found. Please upload a CSV file.")
|
| 27 |
|
| 28 |
# File uploader widget to upload a new dataset
|
| 29 |
uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
|
|
@@ -35,9 +29,23 @@ if uploaded_file is not None:
|
|
| 35 |
# Save the dataset permanently to disk
|
| 36 |
df.to_csv(DATA_FILE_PATH, index=False)
|
| 37 |
|
| 38 |
-
#
|
| 39 |
-
st.
|
| 40 |
-
st.write(df.head()) # Display the first 5 rows
|
| 41 |
|
| 42 |
# Display success message
|
| 43 |
st.success(f"Dataset uploaded and saved permanently as {DATA_FILE_PATH}!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import streamlit as st
|
| 4 |
|
| 5 |
# Define a persistent file path for the dataset
|
| 6 |
DATA_FILE_PATH = "dataset.csv"
|
|
|
|
| 8 |
# Page Title
|
| 9 |
st.markdown("<h1 style='text-align:center; color:yellow;'>Hotel Data Set</h1>", unsafe_allow_html=True)
|
| 10 |
|
| 11 |
+
# Function to load the dataset
|
| 12 |
+
def load_dataset():
|
| 13 |
+
if os.path.exists(DATA_FILE_PATH):
|
| 14 |
+
return pd.read_csv(DATA_FILE_PATH)
|
| 15 |
+
else:
|
| 16 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
# Check if dataset is in session state or load it from disk
|
| 19 |
+
if "dataset" not in st.session_state:
|
| 20 |
+
st.session_state["dataset"] = load_dataset()
|
|
|
|
| 21 |
|
| 22 |
# File uploader widget to upload a new dataset
|
| 23 |
uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
|
|
|
|
| 29 |
# Save the dataset permanently to disk
|
| 30 |
df.to_csv(DATA_FILE_PATH, index=False)
|
| 31 |
|
| 32 |
+
# Store in session state
|
| 33 |
+
st.session_state["dataset"] = df
|
|
|
|
| 34 |
|
| 35 |
# Display success message
|
| 36 |
st.success(f"Dataset uploaded and saved permanently as {DATA_FILE_PATH}!")
|
| 37 |
+
|
| 38 |
+
# Access the dataset from session state
|
| 39 |
+
df = st.session_state.get("dataset")
|
| 40 |
+
|
| 41 |
+
if df is not None:
|
| 42 |
+
st.subheader("Dataset Preview:")
|
| 43 |
+
st.write(df.head()) # Display the first 5 rows
|
| 44 |
+
|
| 45 |
+
st.subheader("Dataset Description:")
|
| 46 |
+
st.write(df.describe())
|
| 47 |
+
|
| 48 |
+
st.subheader("Dataset Shape (Rows, Columns):")
|
| 49 |
+
st.write(df.shape)
|
| 50 |
+
else:
|
| 51 |
+
st.info("No dataset found. Please upload a CSV file.")
|