Herc commited on
Commit
8bd8367
·
verified ·
1 Parent(s): 49a01f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -73
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import random
4
- from datetime import datetime
5
 
6
  # Helper function to generate a random date within the last year
7
  def random_date():
@@ -9,69 +9,33 @@ def random_date():
9
  random_days = random.randint(0, 365)
10
  return (start_date + timedelta(days=random_days)).strftime("%Y-%m-%d")
11
 
12
- # Cache the function that loads the product catalog
13
  @st.cache
14
-
15
- # Define the products and their categories
16
- products = {
17
- "Product Name": [
18
- "Notepad++", "WinRAR", "7-Zip", "CCleaner", "TeamViewer",
19
- "FileZilla", "PuTTY", "WinSCP", "Everything", "Greenshot",
20
- "Visual Studio Code", "JetBrains IntelliJ IDEA", "Sublime Text", "Atom", "Eclipse",
21
- "PyCharm", "NetBeans", "Xcode", "Android Studio", "GitLab",
22
- "Norton Antivirus", "McAfee Total Protection", "Kaspersky Internet Security", "Bitdefender Antivirus Plus", "Avast Free Antivirus",
23
- "Sophos Home", "Trend Micro Antivirus+", "ESET NOD32 Antivirus", "F-Secure SAFE", "Malwarebytes",
24
- "Microsoft Office 365", "Google Workspace", "Slack", "Trello", "Asana",
25
- "Zoom", "Evernote", "Notion", "Dropbox", "Adobe Acrobat Reader",
26
- "Adobe Photoshop", "Adobe Illustrator", "Adobe Premiere Pro", "Final Cut Pro", "Sketch",
27
- "Blender", "Autodesk Maya", "CorelDRAW", "GIMP", "Inkscape"
28
- ],
29
- "Category": [
30
- "Utility Tools", "Utility Tools", "Utility Tools", "Utility Tools", "Utility Tools",
31
- "Utility Tools", "Utility Tools", "Utility Tools", "Utility Tools", "Utility Tools",
32
- "Development Tools", "Development Tools", "Development Tools", "Development Tools", "Development Tools",
33
- "Development Tools", "Development Tools", "Development Tools", "Development Tools", "Development Tools",
34
- "Security Software", "Security Software", "Security Software", "Security Software", "Security Software",
35
- "Security Software", "Security Software", "Security Software", "Security Software", "Security Software",
36
- "Productivity Software", "Productivity Software", "Productivity Software", "Productivity Software", "Productivity Software",
37
- "Productivity Software", "Productivity Software", "Productivity Software", "Productivity Software", "Productivity Software",
38
- "Creative Software", "Creative Software", "Creative Software", "Creative Software", "Creative Software",
39
- "Creative Software", "Creative Software", "Creative Software", "Creative Software", "Creative Software"
40
- ],
41
- "Cyber Approved": [random.choice([True, False]) for _ in range(50)],
42
- "Accessibility Approved": [random.choice([True, False]) for _ in range(50)],
43
- "Privacy Approved": [random.choice([True, False]) for _ in range(50)],
44
- "Review Date": [random_date() for _ in range(50)]
45
- }
46
-
47
- # Example of caching a complex filtering operation
48
  @st.cache
49
- def filter_catalog(catalog, category=None, search_query=None):
50
  filtered = catalog
51
  if category:
52
  filtered = filtered[filtered["Category"].isin(category)]
 
 
 
 
 
 
53
  if search_query:
54
  filtered = filtered[filtered["Product Name"].str.contains(search_query, case=False)]
55
  return filtered
56
 
57
-
58
-
59
- # Create the DataFrame
60
- catalog = pd.DataFrame(products)
61
-
62
- # Apply filters based on user input
63
- category = st.sidebar.multiselect("Filter by Category", options=catalog["Category"].unique())
64
- search_query = st.sidebar.text_input("Search Products")
65
-
66
- filtered_catalog = filter_catalog(catalog, category, search_query)
67
-
68
-
69
-
70
- # Display the DataFrame for verification
71
- print(catalog)
72
-
73
-
74
-
75
 
76
  # Streamlit app layout
77
  st.title("Enterprise Software Product Catalog")
@@ -79,25 +43,20 @@ st.write("This is the source of truth for app approval statuses within the enter
79
 
80
  # Sidebar for filters
81
  category = st.sidebar.multiselect("Filter by Category", options=catalog["Category"].unique())
82
- cyber_approved = st.sidebar.checkbox("Cyber Approved")
83
- accessibility_approved = st.sidebar.checkbox("Accessibility Approved")
84
- privacy_approved = st.sidebar.checkbox("Privacy Approved")
85
-
86
-
87
- # Filtering logic
88
- filtered_catalog = catalog
89
- if category:
90
- filtered_catalog = filtered_catalog[filtered_catalog["Category"].isin(category)]
91
- if cyber_approved:
92
- filtered_catalog = filtered_catalog[filtered_catalog["Cyber Approved"] == True]
93
- if accessibility_approved:
94
- filtered_catalog = filtered_catalog[filtered_catalog["Accessibility Approved"] == True]
95
- if privacy_approved:
96
- filtered_catalog = filtered_catalog[filtered_catalog["Privacy Approved"] == True]
97
-
98
 
 
 
 
 
 
 
 
 
 
99
 
100
  # Display the filtered product catalog
101
  st.dataframe(filtered_catalog)
102
-
103
-
 
1
  import streamlit as st
2
  import pandas as pd
3
  import random
4
+ from datetime import datetime, timedelta
5
 
6
  # Helper function to generate a random date within the last year
7
  def random_date():
 
9
  random_days = random.randint(0, 365)
10
  return (start_date + timedelta(days=random_days)).strftime("%Y-%m-%d")
11
 
12
+ # Function to load and cache the product catalog
13
  @st.cache
14
+ def load_catalog():
15
+ products = {
16
+ # Products and categories as defined previously...
17
+ "Review Date": [random_date() for _ in range(50)]
18
+ }
19
+ return pd.DataFrame(products)
20
+
21
+ # Cached function for filtering the catalog
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  @st.cache
23
+ def filter_catalog(catalog, category=None, cyber_approved=None, accessibility_approved=None, privacy_approved=None, search_query=None):
24
  filtered = catalog
25
  if category:
26
  filtered = filtered[filtered["Category"].isin(category)]
27
+ if cyber_approved is not None:
28
+ filtered = filtered[filtered["Cyber Approved"] == cyber_approved]
29
+ if accessibility_approved is not None:
30
+ filtered = filtered[filtered["Accessibility Approved"] == accessibility_approved]
31
+ if privacy_approved is not None:
32
+ filtered = filtered[filtered["Privacy Approved"] == privacy_approved]
33
  if search_query:
34
  filtered = filtered[filtered["Product Name"].str.contains(search_query, case=False)]
35
  return filtered
36
 
37
+ # Load the catalog
38
+ catalog = load_catalog()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  # Streamlit app layout
41
  st.title("Enterprise Software Product Catalog")
 
43
 
44
  # Sidebar for filters
45
  category = st.sidebar.multiselect("Filter by Category", options=catalog["Category"].unique())
46
+ cyber_approved = st.sidebar.checkbox("Cyber Approved", value=True, key="cyber")
47
+ accessibility_approved = st.sidebar.checkbox("Accessibility Approved", value=True, key="accessibility")
48
+ privacy_approved = st.sidebar.checkbox("Privacy Approved", value=True, key="privacy")
49
+ search_query = st.sidebar.text_input("Search Products", key="search")
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
+ # Apply filters based on user input
52
+ filtered_catalog = filter_catalog(
53
+ catalog,
54
+ category=category,
55
+ cyber_approved=cyber_approved,
56
+ accessibility_approved=accessibility_approved,
57
+ privacy_approved=privacy_approved,
58
+ search_query=search_query
59
+ )
60
 
61
  # Display the filtered product catalog
62
  st.dataframe(filtered_catalog)