gkdivya commited on
Commit
6191c86
·
1 Parent(s): 20fcc67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -3
app.py CHANGED
@@ -7,6 +7,13 @@ def load_furniture_data():
7
  data = json.load(file)
8
  return data
9
 
 
 
 
 
 
 
 
10
  # Custom CSS to style the buttons
11
  st.markdown("""
12
  <style>
@@ -14,6 +21,26 @@ st.markdown("""
14
  </style>
15
  """, unsafe_allow_html=True)
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  # Function to display the main page
18
  def main_page(furniture_data):
19
  st.title("Social Media - What's Trending")
@@ -22,6 +49,9 @@ def main_page(furniture_data):
22
  brands = ['Arhaus', 'Crate&Barrel', 'Williams Sonoma', 'Pottery Barn', 'West Elm', 'Z Gallerie']
23
  brand = st.selectbox('Select Brand', brands)
24
 
 
 
 
25
  # Dropdown for selecting furniture category
26
  categories = list(furniture_data['Furniture'].keys())
27
  selected_category = st.selectbox('Select Category', categories)
@@ -30,10 +60,17 @@ def main_page(furniture_data):
30
  attributes = furniture_data['Furniture'][selected_category]['attributes']
31
  for attribute, options in attributes.items():
32
  st.multiselect(f'Choose {attribute}', options)
 
 
 
 
 
33
 
34
- if st.button('Show Trending TikToks'):
35
- st.write("Display trending TikTok images here...")
36
- # Display TikTok images and links (implementation depends on data source)
 
 
37
 
38
  # Function to display the TikTok video page
39
  def tiktok_video_page():
@@ -46,6 +83,7 @@ def tiktok_video_page():
46
 
47
  # Main app logic
48
  furniture_data = load_furniture_data()
 
49
  if 'page' not in st.session_state:
50
  st.session_state.page = 'main'
51
 
 
7
  data = json.load(file)
8
  return data
9
 
10
+ def load_images():
11
+ with open('images.json', 'r') as file:
12
+ images_data = json.load(file)
13
+ return images_data
14
+
15
+
16
+
17
  # Custom CSS to style the buttons
18
  st.markdown("""
19
  <style>
 
21
  </style>
22
  """, unsafe_allow_html=True)
23
 
24
+ def filter_images(images_data, selected_options):
25
+ filtered_images = []
26
+
27
+ for image_name, image_info in images_data.items():
28
+ matches_all = True # A flag to check if the image matches all selected attributes
29
+
30
+ for attribute, selected_values in selected_options.items():
31
+ if selected_values: # Check if any value is selected for this attribute
32
+ image_attribute_value = image_info.get('attributes', {}).get(attribute)
33
+ if image_attribute_value not in selected_values:
34
+ matches_all = False
35
+ break # Break the loop if any attribute does not match
36
+
37
+ if matches_all:
38
+ filtered_images.append(image_name)
39
+
40
+ return filtered_images
41
+
42
+
43
+
44
  # Function to display the main page
45
  def main_page(furniture_data):
46
  st.title("Social Media - What's Trending")
 
49
  brands = ['Arhaus', 'Crate&Barrel', 'Williams Sonoma', 'Pottery Barn', 'West Elm', 'Z Gallerie']
50
  brand = st.selectbox('Select Brand', brands)
51
 
52
+ # Dictionary to store selected options for each attribute
53
+ selected_options = {}
54
+
55
  # Dropdown for selecting furniture category
56
  categories = list(furniture_data['Furniture'].keys())
57
  selected_category = st.selectbox('Select Category', categories)
 
60
  attributes = furniture_data['Furniture'][selected_category]['attributes']
61
  for attribute, options in attributes.items():
62
  st.multiselect(f'Choose {attribute}', options)
63
+ # Create a multi-select widget for each attribute
64
+ for attribute, options in attributes.items():
65
+ selected_options[attribute] = st.multiselect(f'Choose {attribute}', options)
66
+
67
+ filtered_images = filter_images(images_data, selected_options)
68
 
69
+ if filtered_images:
70
+ for image in filtered_images:
71
+ st.image(image) # Display each filtered image
72
+ else:
73
+ st.write("Not Trending")
74
 
75
  # Function to display the TikTok video page
76
  def tiktok_video_page():
 
83
 
84
  # Main app logic
85
  furniture_data = load_furniture_data()
86
+ images_data = load_images()
87
  if 'page' not in st.session_state:
88
  st.session_state.page = 'main'
89