Update app.py
Browse files
app.py
CHANGED
|
@@ -16,13 +16,12 @@ tab1, tab2, tab3, tab4 = st.tabs(["📖 About", "📊 Dataset Overview", "🧑
|
|
| 16 |
with tab1:
|
| 17 |
st.write("""
|
| 18 |
This app segments customers based on their purchasing behavior using unsupervised learning.
|
| 19 |
-
You can upload
|
| 20 |
""")
|
| 21 |
|
| 22 |
# File uploader in the Dataset Tab
|
| 23 |
with tab2:
|
| 24 |
-
|
| 25 |
-
uploaded_file2 = st.file_uploader("Upload Second Dataset (Optional)", type=["csv", "xlsx"], key="file2")
|
| 26 |
|
| 27 |
def load_data(uploaded_file):
|
| 28 |
if uploaded_file is not None:
|
|
@@ -36,25 +35,11 @@ with tab2:
|
|
| 36 |
st.error(f"Error loading dataset: {e}")
|
| 37 |
return None
|
| 38 |
|
| 39 |
-
|
| 40 |
-
df2 = load_data(uploaded_file2)
|
| 41 |
|
| 42 |
-
if
|
| 43 |
-
st.write("###
|
| 44 |
-
st.write(
|
| 45 |
-
|
| 46 |
-
if df2 is not None:
|
| 47 |
-
st.write("### Second Dataset Overview")
|
| 48 |
-
st.write(df2.head())
|
| 49 |
-
|
| 50 |
-
if df1 is not None and df2 is not None:
|
| 51 |
-
merge_option = st.radio("How would you like to combine the datasets?", ("Concatenate", "Keep Separate"))
|
| 52 |
-
if merge_option == "Concatenate":
|
| 53 |
-
df = pd.concat([df1, df2], ignore_index=True)
|
| 54 |
-
else:
|
| 55 |
-
df = None # Handle separately in clustering
|
| 56 |
-
else:
|
| 57 |
-
df = df1 if df1 is not None else df2
|
| 58 |
|
| 59 |
# Customer Segmentation Tab
|
| 60 |
with tab3:
|
|
@@ -94,4 +79,4 @@ with tab3:
|
|
| 94 |
csv = customer_data.to_csv(index=True)
|
| 95 |
st.download_button("Download Segmented Customer Data", data=csv, file_name="segmented_customer_data.csv", mime="text/csv")
|
| 96 |
else:
|
| 97 |
-
st.write("Please upload
|
|
|
|
| 16 |
with tab1:
|
| 17 |
st.write("""
|
| 18 |
This app segments customers based on their purchasing behavior using unsupervised learning.
|
| 19 |
+
You can upload any dataset file type (CSV, Excel) for analysis.
|
| 20 |
""")
|
| 21 |
|
| 22 |
# File uploader in the Dataset Tab
|
| 23 |
with tab2:
|
| 24 |
+
uploaded_file = st.file_uploader("Upload Your Dataset", type=["csv", "xlsx"])
|
|
|
|
| 25 |
|
| 26 |
def load_data(uploaded_file):
|
| 27 |
if uploaded_file is not None:
|
|
|
|
| 35 |
st.error(f"Error loading dataset: {e}")
|
| 36 |
return None
|
| 37 |
|
| 38 |
+
df = load_data(uploaded_file)
|
|
|
|
| 39 |
|
| 40 |
+
if df is not None:
|
| 41 |
+
st.write("### Dataset Overview")
|
| 42 |
+
st.write(df.head())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Customer Segmentation Tab
|
| 45 |
with tab3:
|
|
|
|
| 79 |
csv = customer_data.to_csv(index=True)
|
| 80 |
st.download_button("Download Segmented Customer Data", data=csv, file_name="segmented_customer_data.csv", mime="text/csv")
|
| 81 |
else:
|
| 82 |
+
st.write("Please upload a dataset to start.")
|