houlie3 commited on
Commit
77495ad
·
verified ·
1 Parent(s): c13b104

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +82 -0
  2. requirements.txt +45 -0
app.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import streamlit as st
3
+ import pandas as pd
4
+ import seaborn as sns
5
+ import matplotlib.pyplot as plt
6
+
7
+ # Apply the default theme and activate color codes
8
+ sns.set_theme()
9
+ sns.set(color_codes=True)
10
+
11
+
12
+ ################### import dataset
13
+ penguins = sns.load_dataset("penguins")
14
+
15
+ ########### set the title and subtitle
16
+ st.title("Differences between penguins")
17
+
18
+ st.subheader("My flipper is longer!!!")
19
+
20
+ ########## we add image
21
+ st.image("https://raw.githubusercontent.com/allisonhorst/palmerpenguins/main/man/figures/lter_penguins.png")
22
+
23
+ ############## we create filters for our interactive plot
24
+ with st.sidebar:
25
+ st.subheader("Filters")
26
+
27
+ all_species = sorted(penguins["species"].dropna().unique().tolist())
28
+ selected_species = st.multiselect(
29
+ "Species to show",
30
+ options=all_species,
31
+ default=all_species,
32
+ )
33
+
34
+ feature_options = {
35
+ "Flipper length (mm)": "flipper_length_mm",
36
+ "Bill length (mm)": "bill_length_mm",
37
+ "Bill depth (mm)": "bill_depth_mm",
38
+ "Body mass (g)": "body_mass_g",
39
+ }
40
+ feature_label = st.selectbox("Feature (x-axis)", list(feature_options.keys()))
41
+ x_col = feature_options[feature_label]
42
+
43
+ # KDE options
44
+ fill = st.checkbox("Shade area", value=True)
45
+ bw_adjust = st.slider("Smoothing (bw_adjust)", 0.2, 2.0, 1.0, 0.1)
46
+ common_norm = st.checkbox("Normalize across species", value=False)
47
+
48
+ if not selected_species:
49
+ st.info("Select at least one species to display the plot.")
50
+ else:
51
+ data = penguins[penguins["species"].isin(selected_species)].dropna(subset=[x_col])
52
+
53
+ g = sns.displot(
54
+ data=data,
55
+ x=x_col,
56
+ kind="kde",
57
+ hue="species",
58
+ fill=fill,
59
+ bw_adjust=bw_adjust,
60
+ common_norm=common_norm,
61
+ height=4,
62
+ aspect=1.6,
63
+ )
64
+ fig = g.fig if hasattr(g, "fig") else g.figure
65
+ st.pyplot(fig)
66
+ plt.close(fig)
67
+
68
+ ######## add button to save image
69
+ from io import BytesIO
70
+
71
+ buf = BytesIO()
72
+ fig.savefig(buf, format="png", dpi=200, bbox_inches="tight")
73
+ buf.seek(0)
74
+ st.download_button(
75
+ "Save image",
76
+ data=buf,
77
+ file_name=f"penguins_{x_col}.png",
78
+ mime="image/png",
79
+ )
80
+
81
+ ########### Footer
82
+ st.caption("Developed for SDS M1 course.")
requirements.txt ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ altair==5.5.0
2
+ attrs==25.3.0
3
+ blinker==1.9.0
4
+ cachetools==6.2.0
5
+ certifi==2025.8.3
6
+ charset-normalizer==3.4.3
7
+ click==8.2.1
8
+ contourpy==1.3.3
9
+ cycler==0.12.1
10
+ et_xmlfile==2.0.0
11
+ fonttools==4.59.2
12
+ gitdb==4.0.12
13
+ GitPython==3.1.45
14
+ idna==3.10
15
+ Jinja2==3.1.6
16
+ jsonschema==4.25.1
17
+ jsonschema-specifications==2025.9.1
18
+ kiwisolver==1.4.9
19
+ MarkupSafe==3.0.2
20
+ matplotlib==3.10.6
21
+ narwhals==2.4.0
22
+ numpy==2.3.3
23
+ openpyxl==3.1.5
24
+ packaging==25.0
25
+ pandas==2.3.2
26
+ pillow==11.3.0
27
+ protobuf==6.32.0
28
+ pyarrow==21.0.0
29
+ pydeck==0.9.1
30
+ pyparsing==3.2.3
31
+ python-dateutil==2.9.0.post0
32
+ pytz==2025.2
33
+ referencing==0.36.2
34
+ requests==2.32.5
35
+ rpds-py==0.27.1
36
+ seaborn==0.13.2
37
+ six==1.17.0
38
+ smmap==5.0.2
39
+ streamlit==1.49.1
40
+ tenacity==9.1.2
41
+ toml==0.10.2
42
+ tornado==6.5.2
43
+ typing_extensions==4.15.0
44
+ tzdata==2025.2
45
+ urllib3==2.5.0