import os
import pandas as pd
import streamlit as st
from io import StringIO
import sys
# Define a persistent file path for the dataset
DATA_FILE_PATH = "dataset.csv"
# Page Title
st.markdown("
Hotel Data Set
", unsafe_allow_html=True)
# CSS styles
st.markdown(
"""
""",
unsafe_allow_html=True,
)
# Function to load the dataset
def load_dataset():
if os.path.exists(DATA_FILE_PATH):
return pd.read_csv(DATA_FILE_PATH)
else:
return None
# Check if dataset is in session state or load it from disk
if "dataset" not in st.session_state:
st.session_state["dataset"] = load_dataset()
# File uploader widget to upload a new dataset
uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
if uploaded_file is not None:
# Read the uploaded CSV file into a pandas DataFrame
df = pd.read_csv(uploaded_file)
# Save the dataset permanently to disk
df.to_csv(DATA_FILE_PATH, index=False)
# Store in session state
st.session_state["dataset"] = df
# Display success message
st.success(f"Dataset uploaded and saved permanently as {DATA_FILE_PATH}!")
# Access the dataset from session state
df = st.session_state.get("dataset")
if df is not None:
st.subheader("Dataset Preview:")
st.write(df) # Display the first 5 rows
# Redirect the output of df.info() to a string buffer
buffer = StringIO()
df.info(buf=buffer)
# Display the content in Streamlit as Markdown
st.subheader("Info of the Dataset:")
st.markdown(f"```{buffer.getvalue()}```")
st.subheader("Dataset Shape (Rows, Columns):")
st.write(df.shape)
else:
st.info("No dataset found. Please upload a CSV file.")
# Define the URL of the background image (use your own image URL)
background_image_url = "https://cdn-uploads.huggingface.co/production/uploads/675fab3a2d0851e23d23cad3/vulm4WwHmmA14tsVXYaTM.jpeg"
# Apply custom CSS for the background image and overlay
st.markdown(
f"""
""",
unsafe_allow_html=True
)
st.markdown(
"""
""",
unsafe_allow_html=True,
)
# Navigation Buttons
st.markdown(
"""
""",
unsafe_allow_html=True,
)