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(""" """, 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)