Spaces:
Sleeping
Sleeping
File size: 5,503 Bytes
2fb9655 bf40d1d ac2109d a2a0e52 ac2109d 2fb9655 6191c86 47a1844 6191c86 2fa9e1d 6191c86 2fb9655 36df90c 6191c86 c8cae69 36df90c 6191c86 2fb9655 ac2109d b843cdb 6191c86 ac2109d c401ea4 9732f2a c401ea4 ac2109d 9732f2a 64947ac c401ea4 ac2109d b0b23e6 2a005d4 2fa9e1d d156a3e a2a5a91 d156a3e 2a005d4 2fa9e1d bf40d1d 47133e1 0da0765 91c79f2 0da0765 47133e1 eb25aab 0da0765 eb25aab 0da0765 eb25aab 0da0765 eb25aab 0da0765 47133e1 b0b23e6 47133e1 bfa4234 e0a8f2c 2a005d4 2fa9e1d 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
import streamlit as st
import pandas as pd
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
def load_videos():
with open('./config/videos.json', 'r') as file:
videos_data = json.load(file)
return videos_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 Trends'):
# Assuming images_data is loaded from your JSON file
images_data = load_images() # Make sure this function is defined and loads your images data
videos_data = load_videos()
filtered_images = filter_images(images_data, selected_options, selected_category)
print(selected_options)
print(selected_category)
print(category)
#filtered_images = ['arhaus_video_5_frame_268.png',
#'arhaus_video_5_frame_237.png',
#'arhaus_video_5_frame_269.png']
if filtered_images:
for image_name in filtered_images:
source_video = images_data[image_name].get("source_video")
col1, col2, col3 = st.columns([1, 1, 3])
with col1:
st.image('./images/'+image_name, width=150)
with col2:
if source_video and source_video in videos_data:
video_url = videos_data[source_video]["url"]
#st.video(video_url)
video_html = """
<video width="320" height="240" controls>
<source src="""+ video_url + """ type="video/mp4">
</video>
"""
st.markdown(video_html, unsafe_allow_html=True)
with col3:
# Custom CSS to style the table
table_css = """
<style>
.stDataFrame {
width: 100%;
max-height: 300px;
overflow-y: auto;
}
table.dataframe {
border-collapse: collapse;
}
table.dataframe th, table.dataframe td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
table.dataframe th {
background-color: #f2f2f2;
}
</style>
"""
if source_video and source_video in videos_data:
with st.expander(f"Show Metadata"):
video_metadata = videos_data[source_video]
# Convert the metadata dictionary to a DataFrame
metadata_df = pd.DataFrame(video_metadata.items(), columns=['Attribute', 'Value'])
# Display the DataFrame as a table
st.table(metadata_df)
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)
|