Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,58 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
from sklearn import datasets
|
| 5 |
+
from sklearn.cluster import KMeans
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
|
| 8 |
+
# JS hack to add a toggle button for the sidebar
|
| 9 |
+
st.markdown("""
|
| 10 |
+
<style>
|
| 11 |
+
.reportview-container .main .block-container {
|
| 12 |
+
max-width: 100%;
|
| 13 |
+
}
|
| 14 |
+
</style>
|
| 15 |
+
""", unsafe_allow_html=True)
|
| 16 |
+
|
| 17 |
+
# Load iris dataset
|
| 18 |
+
iris = datasets.load_iris()
|
| 19 |
+
X = iris.data
|
| 20 |
+
|
| 21 |
+
st.title('Understanding K-Means Clustering')
|
| 22 |
+
|
| 23 |
+
tab1, tab2 = st.tabs(["Basic ☕", "Advanced 🔬"])
|
| 24 |
+
|
| 25 |
+
if "toggle" not in st.session_state:
|
| 26 |
+
st.session_state.toggle = True
|
| 27 |
+
|
| 28 |
+
toggle_button = st.button("Toggle Sidebar")
|
| 29 |
+
|
| 30 |
+
if toggle_button:
|
| 31 |
+
st.session_state.toggle = not st.session_state.toggle
|
| 32 |
+
|
| 33 |
+
if st.session_state.toggle:
|
| 34 |
+
|
| 35 |
+
# User Input on Sidebar
|
| 36 |
+
st.sidebar.header('Input Your Flower Data')
|
| 37 |
+
def user_input_features():
|
| 38 |
+
sepal_length = st.sidebar.slider('Sepal Length (cm)', 4.0, 8.0, 6.5)
|
| 39 |
+
sepal_width = st.sidebar.slider('Sepal Width (cm)', 2.0, 4.5, 3.5)
|
| 40 |
+
petal_length = st.sidebar.slider('Petal Length (cm)', 1.0, 7.0, 4.5)
|
| 41 |
+
petal_width = st.sidebar.slider('Petal Width (cm)', 0.1, 2.5, 1.5)
|
| 42 |
+
return [sepal_length, sepal_width, petal_length, petal_width]
|
| 43 |
+
|
| 44 |
+
user_features = user_input_features()
|
| 45 |
+
|
| 46 |
+
# Rest of your code remains largely unchanged
|
| 47 |
+
# We just use the st.session_state.toggle to conditionally display certain elements
|
| 48 |
+
|
| 49 |
+
with tab1:
|
| 50 |
+
# ...
|
| 51 |
+
# Rest of your code for tab1
|
| 52 |
+
# ...
|
| 53 |
+
pass
|
| 54 |
+
with tab2:
|
| 55 |
+
# ...
|
| 56 |
+
# Rest of your code for tab2
|
| 57 |
+
# ...
|
| 58 |
+
pass
|