Spaces:
Build error
Build error
| import streamlit as st | |
| import pandas as pd | |
| import random | |
| from datetime import datetime | |
| # Helper function to generate a random date within the last year | |
| def random_date(): | |
| start_date = datetime.now() - timedelta(days=365) | |
| random_days = random.randint(0, 365) | |
| return (start_date + timedelta(days=random_days)).strftime("%Y-%m-%d") | |
| # Cache the function that loads the product catalog | |
| # Define the products and their categories | |
| products = { | |
| "Product Name": [ | |
| "Notepad++", "WinRAR", "7-Zip", "CCleaner", "TeamViewer", | |
| "FileZilla", "PuTTY", "WinSCP", "Everything", "Greenshot", | |
| "Visual Studio Code", "JetBrains IntelliJ IDEA", "Sublime Text", "Atom", "Eclipse", | |
| "PyCharm", "NetBeans", "Xcode", "Android Studio", "GitLab", | |
| "Norton Antivirus", "McAfee Total Protection", "Kaspersky Internet Security", "Bitdefender Antivirus Plus", "Avast Free Antivirus", | |
| "Sophos Home", "Trend Micro Antivirus+", "ESET NOD32 Antivirus", "F-Secure SAFE", "Malwarebytes", | |
| "Microsoft Office 365", "Google Workspace", "Slack", "Trello", "Asana", | |
| "Zoom", "Evernote", "Notion", "Dropbox", "Adobe Acrobat Reader", | |
| "Adobe Photoshop", "Adobe Illustrator", "Adobe Premiere Pro", "Final Cut Pro", "Sketch", | |
| "Blender", "Autodesk Maya", "CorelDRAW", "GIMP", "Inkscape" | |
| ], | |
| "Category": [ | |
| "Utility Tools", "Utility Tools", "Utility Tools", "Utility Tools", "Utility Tools", | |
| "Utility Tools", "Utility Tools", "Utility Tools", "Utility Tools", "Utility Tools", | |
| "Development Tools", "Development Tools", "Development Tools", "Development Tools", "Development Tools", | |
| "Development Tools", "Development Tools", "Development Tools", "Development Tools", "Development Tools", | |
| "Security Software", "Security Software", "Security Software", "Security Software", "Security Software", | |
| "Security Software", "Security Software", "Security Software", "Security Software", "Security Software", | |
| "Productivity Software", "Productivity Software", "Productivity Software", "Productivity Software", "Productivity Software", | |
| "Productivity Software", "Productivity Software", "Productivity Software", "Productivity Software", "Productivity Software", | |
| "Creative Software", "Creative Software", "Creative Software", "Creative Software", "Creative Software", | |
| "Creative Software", "Creative Software", "Creative Software", "Creative Software", "Creative Software" | |
| ], | |
| "Cyber Approved": [random.choice([True, False]) for _ in range(50)], | |
| "Accessibility Approved": [random.choice([True, False]) for _ in range(50)], | |
| "Privacy Approved": [random.choice([True, False]) for _ in range(50)], | |
| "Review Date": [random_date() for _ in range(50)] | |
| } | |
| # Example of caching a complex filtering operation | |
| def filter_catalog(catalog, category=None, search_query=None): | |
| filtered = catalog | |
| if category: | |
| filtered = filtered[filtered["Category"].isin(category)] | |
| if search_query: | |
| filtered = filtered[filtered["Product Name"].str.contains(search_query, case=False)] | |
| return filtered | |
| # Create the DataFrame | |
| catalog = pd.DataFrame(products) | |
| # Apply filters based on user input | |
| category = st.sidebar.multiselect("Filter by Category", options=catalog["Category"].unique()) | |
| search_query = st.sidebar.text_input("Search Products") | |
| filtered_catalog = filter_catalog(catalog, category, search_query) | |
| # Display the DataFrame for verification | |
| print(catalog) | |
| # Streamlit app layout | |
| st.title("Enterprise Software Product Catalog") | |
| st.write("This is the source of truth for app approval statuses within the enterprise.") | |
| # Sidebar for filters | |
| category = st.sidebar.multiselect("Filter by Category", options=catalog["Category"].unique()) | |
| cyber_approved = st.sidebar.checkbox("Cyber Approved") | |
| accessibility_approved = st.sidebar.checkbox("Accessibility Approved") | |
| privacy_approved = st.sidebar.checkbox("Privacy Approved") | |
| # Filtering logic | |
| filtered_catalog = catalog | |
| if category: | |
| filtered_catalog = filtered_catalog[filtered_catalog["Category"].isin(category)] | |
| if cyber_approved: | |
| filtered_catalog = filtered_catalog[filtered_catalog["Cyber Approved"] == True] | |
| if accessibility_approved: | |
| filtered_catalog = filtered_catalog[filtered_catalog["Accessibility Approved"] == True] | |
| if privacy_approved: | |
| filtered_catalog = filtered_catalog[filtered_catalog["Privacy Approved"] == True] | |
| # Display the filtered product catalog | |
| st.dataframe(filtered_catalog) | |