Herc's picture
Update app.py
3226f49 verified
raw
history blame
6.04 kB
import streamlit as st
import pandas as pd
import random
from datetime import datetime, timedelta
# 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")
# Function to load and cache the product catalog
@st.cache_data
def load_catalog():
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)]
}
return pd.DataFrame(products)
# Enhanced function to filter the catalog based on multiple attributes
@st.cache_data
def filter_catalog(catalog, search_query=None, cyber_approved=None, accessibility_approved=None, privacy_approved=None):
filtered = catalog
if search_query:
# Filtering by checking if the search_query is in any of the specified attributes
filtered = filtered[filtered.apply(lambda row: search_query.lower() in str(row).lower(), axis=1)]
if cyber_approved is not None:
filtered = filtered[filtered["Cyber Approved"] == cyber_approved]
if accessibility_approved is not None:
filtered = filtered[filtered["Accessibility Approved"] == accessibility_approved]
if privacy_approved is not None:
filtered = filtered[filtered["Privacy Approved"] == privacy_approved]
return filtered
catalog = load_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.")
# Custom CSS for styling product details
st.markdown("""
<style>
.detail-box {
border-radius: 10px;
padding: 10px;
margin: 5px 0;
background-color: #f0f2f6;
}
.detail-header {
color: #4f8bf9;
font-weight: bold;
}
.detail-text {
color: #333;
}
</style>
""", unsafe_allow_html=True)
# Display product names as clickable items
for index, row in catalog.iterrows():
if st.button(row['Product Name'], key=str(index)):
with st.expander("Product Details", expanded=True):
st.markdown(f"<div class='detail-box'>"
f"<p class='detail-header'>Product Name:</p> <p class='detail-text'>{row['Product Name']}</p>"
f"<p class='detail-header'>Category:</p> <p class='detail-text'>{row['Category']}</p>"
f"<p class='detail-header'>Cyber Approved:</p> <p class='detail-text'>{'Yes' if row['Cyber Approved'] else 'No'}</p>"
f"<p class='detail-header'>Accessibility Approved:</p> <p class='detail-text'>{'Yes' if row['Accessibility Approved'] else 'No'}</p>"
f"<p class='detail-header'>Privacy Approved:</p> <p class='detail-text'>{'Yes' if row['Privacy Approved'] else 'No'}</p>"
f"<p class='detail-header'>Review Date:</p> <p class='detail-text'>{row['Review Date']}</p>"
"</div>", unsafe_allow_html=True)
# Note: Streamlit's layout is linear and stateless; this approach recreates the UI on each interaction.
# Sidebar for Advanced Search and Filtering
with st.sidebar.expander("Advanced Search Options"):
search_query = st.text_input("Search by Any Attribute", key='search_query')
cyber_approved = st.checkbox("Cyber Approved", key='cyber_approved')
accessibility_approved = st.checkbox("Accessibility Approved", key='accessibility_approved')
privacy_approved = st.checkbox("Privacy Approved", key='privacy_approved')
# Apply the enhanced filter based on user input
filtered_catalog = filter_catalog(catalog, search_query, cyber_approved, accessibility_approved, privacy_approved)
# Display the filtered product catalog
st.header("Product Catalog")
st.dataframe(filtered_catalog)