Update pages/1_Data_Card_and_Data_collection.py
Browse files
pages/1_Data_Card_and_Data_collection.py
CHANGED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import streamlit as st
|
| 4 |
+
from io import StringIO
|
| 5 |
+
import sys
|
| 6 |
+
|
| 7 |
+
# Define a persistent file path for the dataset
|
| 8 |
+
DATA_FILE_PATH = "dataset.csv"
|
| 9 |
+
|
| 10 |
+
# Page Title
|
| 11 |
+
st.markdown("<h1 style='text-align:center; color:white;'>Electronics Sales Data Set</h1>", unsafe_allow_html=True)
|
| 12 |
+
|
| 13 |
+
# Function to load the dataset
|
| 14 |
+
def load_dataset():
|
| 15 |
+
if os.path.exists(DATA_FILE_PATH):
|
| 16 |
+
return pd.read_csv(DATA_FILE_PATH)
|
| 17 |
+
else:
|
| 18 |
+
return None
|
| 19 |
+
|
| 20 |
+
# Check if dataset is in session state or load it from disk
|
| 21 |
+
if "dataset" not in st.session_state:
|
| 22 |
+
st.session_state["dataset"] = load_dataset()
|
| 23 |
+
|
| 24 |
+
# File uploader widget to upload a new dataset
|
| 25 |
+
uploaded_file = st.file_uploader("Choose a CSV file", type=["csv"])
|
| 26 |
+
|
| 27 |
+
if uploaded_file is not None:
|
| 28 |
+
# Read the uploaded CSV file into a pandas DataFrame
|
| 29 |
+
df = pd.read_csv(uploaded_file)
|
| 30 |
+
|
| 31 |
+
# Save the dataset permanently to disk
|
| 32 |
+
df.to_csv(DATA_FILE_PATH, index=False)
|
| 33 |
+
|
| 34 |
+
# Store in session state
|
| 35 |
+
st.session_state["dataset"] = df
|
| 36 |
+
|
| 37 |
+
# Display success message
|
| 38 |
+
st.success(f"Dataset uploaded and saved permanently as {DATA_FILE_PATH}!")
|
| 39 |
+
|
| 40 |
+
# Access the dataset from session state
|
| 41 |
+
df = st.session_state.get("dataset")
|
| 42 |
+
|
| 43 |
+
if df is not None:
|
| 44 |
+
st.subheader("Dataset Preview:")
|
| 45 |
+
st.write(df) # Display the first 5 rows
|
| 46 |
+
|
| 47 |
+
st.subheader("Info of the Dataset:")
|
| 48 |
+
# Redirect the output of df.info() to a string buffer
|
| 49 |
+
buffer = StringIO()
|
| 50 |
+
df.info(buf=buffer)
|
| 51 |
+
|
| 52 |
+
# Display the content in Streamlit
|
| 53 |
+
st.write(buffer.getvalue())
|
| 54 |
+
|
| 55 |
+
st.subheader("Dataset Shape (Rows, Columns):")
|
| 56 |
+
st.write(df.shape)
|
| 57 |
+
else:
|
| 58 |
+
st.info("No dataset found. Please upload a CSV file.")
|
| 59 |
+
# Define the URL of the background image (use your own image URL)
|
| 60 |
+
background_image_url = "https://cdn-uploads.huggingface.co/production/uploads/67441c51a784a9d15cb12871/xpoN_mbctlrQAgRU06EPt.jpeg"
|
| 61 |
+
# Apply custom CSS for the background image and overlay
|
| 62 |
+
st.markdown(
|
| 63 |
+
f"""
|
| 64 |
+
<style>
|
| 65 |
+
.stApp {{
|
| 66 |
+
background-image: url("{background_image_url}");
|
| 67 |
+
background-size: cover;
|
| 68 |
+
background-position: center;
|
| 69 |
+
height: 100vh;
|
| 70 |
+
}}
|
| 71 |
+
|
| 72 |
+
/* Semi-transparent overlay */
|
| 73 |
+
.stApp::before {{
|
| 74 |
+
content: "";
|
| 75 |
+
position: absolute;
|
| 76 |
+
top: 0;
|
| 77 |
+
left: 0;
|
| 78 |
+
width: 100%;
|
| 79 |
+
height: 100%;
|
| 80 |
+
background: rgba(0, 0, 0, 0.4); /* Adjust transparency here (0.4 for 40% transparency) */
|
| 81 |
+
z-index: -1;
|
| 82 |
+
}}
|
| 83 |
+
/* Styling the content to ensure text visibility */
|
| 84 |
+
.stMarkdown {{
|
| 85 |
+
color: white; /* White text to ensure visibility */
|
| 86 |
+
font-size: 100px; /* Adjust font size for better readability */
|
| 87 |
+
}}
|
| 88 |
+
</style>
|
| 89 |
+
""",
|
| 90 |
+
unsafe_allow_html=True
|
| 91 |
+
)
|