Quetiento commited on
Commit
80b765e
1 Parent(s): 5e96976

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -73
app.py CHANGED
@@ -1,74 +1,74 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import matplotlib.pyplot as plt
4
- import seaborn as sns
5
-
6
- # read the dataset
7
- df = pd.read_csv('diamonds.csv')
8
-
9
- st.title('Diamond APP sorting festivity')
10
- # Display shopping tips
11
- shopping_tips = """
12
- ### Shopping Tips:
13
- - Tip 1: Consider the 4Cs: Cut, Color, Clarity, and Carat weight when choosing a diamond.
14
- - Tip 2: Use filters like price range, carat range,cut, color and clarity to narrow down options and find the perfect diamond.
15
-
16
- Wishing you a joyful shopping experience! Find your dream diamond and make it a cherished symbol of love and happiness.
17
- """
18
- st.sidebar.markdown(shopping_tips)
19
-
20
- df = df.drop(["Unnamed: 0"], axis=1)
21
-
22
- #Potential diamonds with a impossible dimensions are dropped, for example a diamond that has a 0 in x, y or z should not be possible.
23
- df = df.drop(df[df["x"]==0].index)
24
- df = df.drop(df[df["y"]==0].index)
25
- df = df.drop(df[df["z"]==0].index)
26
-
27
- st.image('diamonds.jpg')
28
- st.write(f"the price range is {326} to {18823}")
29
-
30
- # users set the price range
31
- min_price, max_price = st.slider('Select Price Range', int(df['price'].min()), int(df['price'].max()), (int(df['price'].min()), int(df['price'].max())))
32
- # users set the carat
33
- min_carat, max_carat = st.slider('Select Carat Range', float(df['carat'].min()), float(df['carat'].max()), (float(df['carat'].min()), float(df['carat'].max())))
34
- #users select
35
- selected_cuts = st.multiselect('choosing cut (Fair, Good, Very Good, Premium, Ideal)', df['cut'].unique())
36
- selected_colors = st.multiselect('choosing color, J (worst), I, H, G, F, E, D (best)', df['color'].unique())
37
- # Display diamond color image
38
- st.image('color.png', caption='Diamond Color', use_column_width=True)
39
-
40
- selected_clarities = st.multiselect('choosing clarity, I1 (worst), SI2, SI1, VS2, VS1, VVS2, VVS1, IF (best)', df['clarity'].unique())
41
- # Display diamond cut image
42
- st.image('cut.png', caption='Diamond Clarity', use_column_width=True)
43
-
44
- # Check if any cuts are selected, if not, consider all cuts
45
- if not selected_cuts:
46
- selected_cuts = df['cut'].unique()
47
- # Check if any colors are selected, if not, consider all colors
48
- if not selected_colors:
49
- selected_colors = df['color'].unique()
50
- # Check if any clarities are selected, if not, consider all clarities
51
- if not selected_clarities:
52
- selected_clarities = df['clarity'].unique()
53
- # Filter diamonds based on selected criteria
54
- filtered_diamonds = df[(df['price'] >= min_price) & (df['price'] <= max_price) &
55
- (df['carat'] >= min_carat) & (df['carat'] <= max_carat) &
56
- (df['cut'].isin(selected_cuts)) &
57
- (df['color'].isin(selected_colors)) &
58
- (df['clarity'].isin(selected_clarities))]
59
- # show the results
60
- if not filtered_diamonds.empty:
61
- st.write(f"find {len(filtered_diamonds)} diamonds for you.")
62
- st.dataframe(filtered_diamonds)
63
- # Create a scatterplot based on the selected criteria
64
- fig, ax = plt.subplots()
65
- sns.scatterplot(x='carat', y='price', data=filtered_diamonds, ax=ax)
66
- ax.set_title('Prices by Carat')
67
- st.pyplot(fig)
68
- # Recommended top ten diamonds
69
- st.write("Top ten diamonds with the best value for money:")
70
- recommended_diamonds = filtered_diamonds.nsmallest(10, 'price')
71
- st.dataframe(recommended_diamonds)
72
-
73
- else:
74
  st.write("No diamonds fit you")
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ import seaborn as sns
5
+
6
+ # read the dataset
7
+ df = pd.read_csv('diamonds.csv')
8
+
9
+ st.title('Diamond APP sorting festivity')
10
+ # Display shopping tips
11
+ shopping_tips = """
12
+ ### Shopping Tips:
13
+ - Tip 1: Consider the 4Cs: Cut, Color, Clarity, and Carat weight when choosing a diamond.
14
+ - Tip 2: Use filters like price range, carat range,cut, color and clarity to narrow down options and find the perfect diamond.
15
+
16
+ Wishing you a joyful shopping experience! Find your dream diamond and make it a cherished symbol of love and happiness.
17
+ """
18
+ st.sidebar.markdown(shopping_tips)
19
+
20
+ df = df.drop(["Unnamed: 0"], axis=1)
21
+
22
+ #Potential diamonds with a impossible dimensions are dropped, for example a diamond that has a 0 in x, y or z should not be possible.
23
+ df = df.drop(df[df["x"]==0].index)
24
+ df = df.drop(df[df["y"]==0].index)
25
+ df = df.drop(df[df["z"]==0].index)
26
+
27
+ st.image('diamonds.jpg')
28
+ st.write(f"the price range is {326} to {18823}")
29
+
30
+ # users set the price range
31
+ min_price, max_price = st.slider('Select Price Range', int(df['price'].min()), int(df['price'].max()), (int(df['price'].min()), int(df['price'].max())))
32
+ # users set the carat
33
+ min_carat, max_carat = st.slider('Select Carat Range', float(df['carat'].min()), float(df['carat'].max()), (float(df['carat'].min()), float(df['carat'].max())))
34
+ #users select
35
+ selected_cuts = st.multiselect('choosing cut (Fair, Good, Very Good, Premium, Ideal)', df['cut'].unique())
36
+ selected_colors = st.multiselect('choosing color, J (worst), I, H, G, F, E, D (best)', df['color'].unique())
37
+ # Display diamond color image
38
+ st.image('color.png', caption='Diamond Color', use_column_width=True)
39
+
40
+ selected_clarities = st.multiselect('choosing clarity, I1 (worst), SI2, SI1, VS2, VS1, VVS2, VVS1, IF (best)', df['clarity'].unique())
41
+ # Display diamond clarity image
42
+ st.image('clarity.png', caption='Diamond Clarity', use_column_width=True)
43
+
44
+ # Check if any cuts are selected, if not, consider all cuts
45
+ if not selected_cuts:
46
+ selected_cuts = df['cut'].unique()
47
+ # Check if any colors are selected, if not, consider all colors
48
+ if not selected_colors:
49
+ selected_colors = df['color'].unique()
50
+ # Check if any clarities are selected, if not, consider all clarities
51
+ if not selected_clarities:
52
+ selected_clarities = df['clarity'].unique()
53
+ # Filter diamonds based on selected criteria
54
+ filtered_diamonds = df[(df['price'] >= min_price) & (df['price'] <= max_price) &
55
+ (df['carat'] >= min_carat) & (df['carat'] <= max_carat) &
56
+ (df['cut'].isin(selected_cuts)) &
57
+ (df['color'].isin(selected_colors)) &
58
+ (df['clarity'].isin(selected_clarities))]
59
+ # show the results
60
+ if not filtered_diamonds.empty:
61
+ st.write(f"find {len(filtered_diamonds)} diamonds for you.")
62
+ st.dataframe(filtered_diamonds)
63
+ # Create a scatterplot based on the selected criteria
64
+ fig, ax = plt.subplots()
65
+ sns.scatterplot(x='carat', y='price', data=filtered_diamonds, ax=ax)
66
+ ax.set_title('Prices by Carat')
67
+ st.pyplot(fig)
68
+ # Recommended top ten diamonds
69
+ st.write("Top ten diamonds with the best value for money:")
70
+ recommended_diamonds = filtered_diamonds.nsmallest(10, 'price')
71
+ st.dataframe(recommended_diamonds)
72
+
73
+ else:
74
  st.write("No diamonds fit you")