trohith89 commited on
Commit
fb34b67
·
verified ·
1 Parent(s): 20d106b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -27
app.py CHANGED
@@ -1,29 +1,69 @@
1
  import streamlit as st
 
 
2
 
3
- # Custom HTML + CSS for background image
4
- # st.markdown("""
5
- # <style>
6
- # body {
7
- # background-image: url('Black Minimalist Galaxy Space Desktop Wallpaper.png');
8
- # background-size: cover;
9
- # background-position: center center;
10
- # }
11
- # </style>
12
- # """, unsafe_allow_html=True)
13
-
14
- # st.background("Background_Image.png")
15
-
16
- # Home Page
17
- st.title("Welcome to the Hotel Data Analysis App")
18
- st.markdown("""
19
- This application is designed to help analyze hotel data, uncover insights, and build predictive models.
20
- Navigate through the app using the sidebar to explore various functionalities.
21
- ### Features:
22
- - **Introduction and About Data**: Learn about the dataset and download a sample file.
23
- - **EDA and Feature Engineering**: Upload and analyze your dataset to uncover patterns and relationships.
24
- - **Model Creation**: Build and evaluate machine learning models using your data.
25
- - **Conclusion**: Summarize findings and key insights.
26
- ### Purpose:
27
- This app is tailored for exploring relationships between features like price, ratings, discounts, cashback, and hotel categories, ultimately enabling data-driven decision-making.
28
- **Get started by selecting a page from the sidebar!**
29
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ import os
4
 
5
+ # Load the default dataset or upload a new one
6
+ @st.cache_data
7
+ def load_default_dataset():
8
+ file_path = "static_dataset.csv"
9
+ if os.path.exists(file_path):
10
+ return pd.read_csv(file_path)
11
+ else:
12
+ st.error("Default dataset not found. Please upload a dataset.")
13
+ return pd.DataFrame()
14
+
15
+ # Main App
16
+ st.set_page_config(page_title="Streamlit App with Static Dataset", layout="wide")
17
+ st.title("Static Dataset App with Upload Feature")
18
+
19
+ # Sidebar Navigation
20
+ st.sidebar.title("Navigation")
21
+ page = st.sidebar.radio("Go to", ["Home", "Dataset", "Other Pages"])
22
+
23
+ # Global state for dataset
24
+ if "dataset" not in st.session_state:
25
+ st.session_state.dataset = load_default_dataset()
26
+
27
+ # Upload a new dataset
28
+ def handle_upload():
29
+ uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
30
+ if uploaded_file is not None:
31
+ try:
32
+ data = pd.read_csv(uploaded_file)
33
+ st.session_state.dataset = data
34
+ st.success("Dataset uploaded successfully!")
35
+ except Exception as e:
36
+ st.error(f"Error reading file: {e}")
37
+
38
+ if page == "Home":
39
+ st.header("Welcome to the Static Dataset App")
40
+ st.write("This app uses a static dataset but also supports uploading a new dataset.")
41
+ st.write("Navigate to the 'Dataset' page to view or upload a dataset.")
42
+
43
+ elif page == "Dataset":
44
+ st.header("Dataset")
45
+
46
+ # Dataset Preview
47
+ st.write("### Dataset Preview")
48
+ if not st.session_state.dataset.empty:
49
+ st.dataframe(st.session_state.dataset)
50
+
51
+ # Download button for the displayed dataset
52
+ st.write("### Download the Dataset")
53
+ csv_data = st.session_state.dataset.to_csv(index=False).encode("utf-8")
54
+ st.download_button(
55
+ label="Download Dataset",
56
+ data=csv_data,
57
+ file_name="dataset.csv",
58
+ mime="text/csv",
59
+ )
60
+ else:
61
+ st.write("No dataset available. Please upload a dataset below.")
62
+
63
+ # Upload a new dataset
64
+ st.write("### Upload a New Dataset")
65
+ handle_upload()
66
+
67
+ elif page == "Other Pages":
68
+ st.header("Other Pages")
69
+ st.write("This section can be customized further based on the app's needs.")