Herc commited on
Commit
1455079
·
verified ·
1 Parent(s): be56d1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -44,19 +44,20 @@ def load_catalog():
44
  }
45
  return pd.DataFrame(products)
46
 
47
- # Enhanced function to filter the catalog based on multiple attributes
48
  @st.cache_data
49
- def filter_catalog(catalog, search_query=None, cyber_approved=None, accessibility_approved=None, privacy_approved=None):
50
  filtered = catalog
51
  if search_query:
52
- # Filtering by checking if the search_query is in any of the specified attributes
53
  filtered = filtered[filtered.apply(lambda row: search_query.lower() in str(row).lower(), axis=1)]
54
- if cyber_approved is not None:
55
- filtered = filtered[filtered["Cyber Approved"] == cyber_approved]
56
- if accessibility_approved is not None:
57
- filtered = filtered[filtered["Accessibility Approved"] == accessibility_approved]
58
- if privacy_approved is not None:
59
- filtered = filtered[filtered["Privacy Approved"] == privacy_approved]
 
 
60
  return filtered
61
 
62
  catalog = load_catalog()
@@ -72,14 +73,16 @@ st.write("This is the source of truth for app approval statuses within the enter
72
 
73
 
74
  # Sidebar for Advanced Search and Filtering
75
- with st.sidebar.expander("Advanced Search Options"):
 
76
  search_query = st.text_input("Search by Any Attribute", key='search_query')
 
77
  cyber_approved = st.checkbox("Cyber Approved", key='cyber_approved')
78
  accessibility_approved = st.checkbox("Accessibility Approved", key='accessibility_approved')
79
  privacy_approved = st.checkbox("Privacy Approved", key='privacy_approved')
80
 
81
  # Apply the enhanced filter based on user input
82
- filtered_catalog = filter_catalog(catalog, search_query, cyber_approved, accessibility_approved, privacy_approved)
83
 
84
  # Display the filtered product catalog
85
  st.header("Product Catalog")
 
44
  }
45
  return pd.DataFrame(products)
46
 
47
+ # Function to filter the catalog based on multiple attributes with AND logic
48
  @st.cache_data
49
+ def filter_catalog(catalog, search_query=None, selected_category=None, cyber_approved=None, accessibility_approved=None, privacy_approved=None):
50
  filtered = catalog
51
  if search_query:
 
52
  filtered = filtered[filtered.apply(lambda row: search_query.lower() in str(row).lower(), axis=1)]
53
+ if selected_category and selected_category != 'All':
54
+ filtered = filtered[filtered["Category"] == selected_category]
55
+ if cyber_approved:
56
+ filtered = filtered[filtered["Cyber Approved"] == True]
57
+ if accessibility_approved:
58
+ filtered = filtered[filtered["Accessibility Approved"] == True]
59
+ if privacy_approved:
60
+ filtered = filtered[filtered["Privacy Approved"] == True]
61
  return filtered
62
 
63
  catalog = load_catalog()
 
73
 
74
 
75
  # Sidebar for Advanced Search and Filtering
76
+ with st.sidebar:
77
+ st.header("Advanced Search Options")
78
  search_query = st.text_input("Search by Any Attribute", key='search_query')
79
+ selected_category = st.selectbox("Select Category", ['All'] + list(catalog["Category"].unique()), key='search_category')
80
  cyber_approved = st.checkbox("Cyber Approved", key='cyber_approved')
81
  accessibility_approved = st.checkbox("Accessibility Approved", key='accessibility_approved')
82
  privacy_approved = st.checkbox("Privacy Approved", key='privacy_approved')
83
 
84
  # Apply the enhanced filter based on user input
85
+ filtered_catalog = filter_catalog(catalog, search_query, selected_category, cyber_approved, accessibility_approved, privacy_approved)
86
 
87
  # Display the filtered product catalog
88
  st.header("Product Catalog")