File size: 3,022 Bytes
2fb9655
ac2109d
 
a2a0e52
 
ac2109d
 
 
 
 
2fb9655
6191c86
47a1844
6191c86
 
 
 
 
2fb9655
 
 
 
 
 
 
36df90c
 
 
6191c86
36df90c
 
 
 
 
6191c86
 
 
2fb9655
ac2109d
b843cdb
6191c86
 
 
ac2109d
 
c401ea4
 
9732f2a
c401ea4
 
 
 
 
 
 
 
 
 
ac2109d
 
 
9732f2a
64947ac
 
c401ea4
 
 
 
ac2109d
2a005d4
 
 
 
36df90c
2a005d4
 
 
9f7a518
2a005d4
 
 
2fb9655
 
ac2109d
a2a0e52
2fb9655
 
826c404
2fb9655
ac2109d
826c404
1
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import streamlit as st
import json

st.set_page_config(layout='wide')

# Load furniture categories and attributes from a JSON file
def load_furniture_data():
    with open('./config/furniture_taxonomy.json', 'r') as file:
        data = json.load(file)
    return data

def load_images():
    with open('./config/images.json', 'r') as file:
        images_data = json.load(file)
    return images_data



# Custom CSS to style the buttons
st.markdown("""
<style>
.streamlit-button { background-color: #0052CC; color: white; }
</style>
""", unsafe_allow_html=True)

# Function to filter images based on selected options and category
def filter_images(images_data, selected_options, category):
    matched_images = []
    for image_name, image_info in images_data.items():
        if image_info['category'] == category:
            if all(image_info['attributes'][attribute] in options 
                   for attribute, options in selected_options.items()):
                matched_images.append(image_name)
    return matched_images


    
# Function to display the main page
def main_page(furniture_data):
    st.title("Social Media - What's Trending")
    # Dictionary to store selected options for each attribute
    selected_options = {}

    # Dropdown for selecting furniture category
    categories = list(furniture_data['Furniture'].keys())
    brands = ['Arhaus', 'Crate&Barrel', 'Williams Sonoma', 'Pottery Barn', 'West Elm', 'Z Gallerie']
    
    col1, col2, col3 = st.columns(3)

    with col1:
        category = st.selectbox('Select Category', ['Apparel', 'Furnitures', 'Beauty'])

    with col2:
        brand = st.selectbox('Select Brand', brands)

    with col3:
        selected_category = st.selectbox('Select Category', categories)
    

    # Load attributes based on the selected category
    attributes = furniture_data['Furniture'][selected_category]['attributes']
    columns = st.columns(len(attributes))
        
    # Create a multi-select widget for each attribute with a unique key
    for i, (attribute, options) in enumerate(attributes.items()):
        with columns[i]:
            key = f"{selected_category}_{attribute}"  # Unique key combining category and attribute
            selected_options[attribute] = st.multiselect(f'Choose {attribute}', options, key=key)

    if st.button('Show Filtered Images'):
        # Assuming images_data is loaded from your JSON file
        images_data = load_images()  # Make sure this function is defined and loads your images data
    
        filtered_images = filter_images(images_data, selected_options, selected_category)
    
        if filtered_images:
            for image in filtered_images:
                st.image('./images/'+image, width=300)  # Adjust width as needed
        else:
            st.write("Not Trending")
            

# Main app logic
furniture_data = load_furniture_data()

if 'page' not in st.session_state:
    st.session_state.page = 'main'
    
if st.session_state.page == 'main':
    main_page(furniture_data)