saoter commited on
Commit
dbac965
·
verified ·
1 Parent(s): 876117d

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +83 -0
  2. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+
4
+
5
+ import seaborn as sns
6
+ import matplotlib.pyplot as plt
7
+
8
+ # Apply the default theme and activate color codes
9
+ sns.set_theme()
10
+ sns.set(color_codes=True)
11
+
12
+
13
+ ################### import dataset
14
+ penguins = sns.load_dataset("penguins")
15
+
16
+ ########### set the title and subtitle
17
+ st.title("Differences between penguins")
18
+
19
+ st.subheader("My flipper is longer!!!")
20
+
21
+ ########## we add image
22
+ st.image("https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/man/figures/lter_penguins.png")
23
+
24
+ ############## we create filters for our interactive plot
25
+ with st.sidebar:
26
+ st.subheader("Filters")
27
+
28
+ all_species = sorted(penguins["species"].dropna().unique().tolist())
29
+ selected_species = st.multiselect(
30
+ "Species to show",
31
+ options=all_species,
32
+ default=all_species,
33
+ )
34
+
35
+ feature_options = {
36
+ "Flipper length (mm)": "flipper_length_mm",
37
+ "Bill length (mm)": "bill_length_mm",
38
+ "Bill depth (mm)": "bill_depth_mm",
39
+ "Body mass (g)": "body_mass_g",
40
+ }
41
+ feature_label = st.selectbox("Feature (x-axis)", list(feature_options.keys()))
42
+ x_col = feature_options[feature_label]
43
+
44
+ # KDE options
45
+ fill = st.checkbox("Shade area", value=True)
46
+ bw_adjust = st.slider("Smoothing (bw_adjust)", 0.2, 2.0, 1.0, 0.1)
47
+ common_norm = st.checkbox("Normalize across species", value=False)
48
+
49
+ if not selected_species:
50
+ st.info("Select at least one species to display the plot.")
51
+ else:
52
+ data = penguins[penguins["species"].isin(selected_species)].dropna(subset=[x_col])
53
+
54
+ g = sns.displot(
55
+ data=data,
56
+ x=x_col,
57
+ kind="kde",
58
+ hue="species",
59
+ fill=fill,
60
+ bw_adjust=bw_adjust,
61
+ common_norm=common_norm,
62
+ height=4,
63
+ aspect=1.6,
64
+ )
65
+ fig = g.fig if hasattr(g, "fig") else g.figure
66
+ st.pyplot(fig)
67
+ plt.close(fig)
68
+
69
+ ######## add button to save image
70
+ from io import BytesIO
71
+
72
+ buf = BytesIO()
73
+ fig.savefig(buf, format="png", dpi=200, bbox_inches="tight")
74
+ buf.seek(0)
75
+ st.download_button(
76
+ "Save image",
77
+ data=buf,
78
+ file_name=f"penguins_{x_col}.png",
79
+ mime="image/png",
80
+ )
81
+
82
+ ########### Footer
83
+ st.caption("Developed for SDS M1 course.")
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ streamlit==1.45.1
2
+ pandas==2.2.3
3
+ numpy==2.2.5
4
+ seaborn==0.13.2
5
+ matplotlib==3.10.0
6
+ duckdb==1.3.2
7
+ pyarrow==19.0.0
8
+ altair==5.5.0