Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,11 +10,6 @@ st.set_page_config(layout="centered", page_title="Restaurant Data Viewer")
|
|
| 10 |
MAIN_LOGO_URL = "https://islamictrusthk.org/assets/images/top-logo.png"
|
| 11 |
SIDEBAR_LOGO_URL = "https://bot.islamictrusthk.org/assets/content_files/20240606095159123011.png"
|
| 12 |
|
| 13 |
-
# Print the versions of the packages
|
| 14 |
-
st.write(f"Streamlit version: {st.__version__}")
|
| 15 |
-
st.write(f"Pandas version: {pd.__version__}")
|
| 16 |
-
st.write(f"Numpy version: {np.__version__}")
|
| 17 |
-
|
| 18 |
# Inject custom CSS for better mobile compatibility
|
| 19 |
st.markdown(
|
| 20 |
"""
|
|
@@ -66,13 +61,13 @@ def display_tiles(df, cols):
|
|
| 66 |
for i, (_, row) in enumerate(df.iterrows()):
|
| 67 |
col = cols[i % len(cols)]
|
| 68 |
with col:
|
| 69 |
-
st.markdown(f"**Name:** {row['Name']}")
|
| 70 |
-
st.markdown(f"**
|
| 71 |
-
st.markdown(f"**
|
| 72 |
-
st.markdown(f"**Restaurant Type:** {row['Restaurant Type']}")
|
| 73 |
st.markdown(f"**Expiry Date:** {row['Expiry Date']}")
|
| 74 |
-
st.markdown(f"**
|
| 75 |
-
st.markdown(f"**
|
|
|
|
| 76 |
st.markdown("---")
|
| 77 |
|
| 78 |
# Initialize session state
|
|
@@ -95,14 +90,15 @@ def authenticate(username, password):
|
|
| 95 |
|
| 96 |
# Function to trigger rerun
|
| 97 |
def trigger_rerun():
|
| 98 |
-
st.
|
| 99 |
|
| 100 |
# Authentication block
|
| 101 |
if not st.session_state.authenticated:
|
| 102 |
st.title("Login")
|
| 103 |
username = st.text_input("Username")
|
| 104 |
password = st.text_input("Password", type="password")
|
| 105 |
-
|
|
|
|
| 106 |
if authenticate(username, password):
|
| 107 |
st.session_state.authenticated = True
|
| 108 |
trigger_rerun()
|
|
@@ -159,14 +155,18 @@ else:
|
|
| 159 |
df = st.session_state.df
|
| 160 |
|
| 161 |
# Define required columns
|
| 162 |
-
required_columns = [
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
# Verify required columns
|
| 165 |
missing_columns = verify_columns(df, required_columns)
|
| 166 |
if missing_columns:
|
| 167 |
st.error(f"The following required columns are missing from the uploaded file: {', '.join(missing_columns)}")
|
| 168 |
else:
|
| 169 |
-
# Format the
|
|
|
|
| 170 |
df = format_date_column(df, 'Expiry Date')
|
| 171 |
|
| 172 |
# Display the dataframe
|
|
@@ -179,14 +179,14 @@ else:
|
|
| 179 |
col1, col2, col3, col4 = st.columns(4)
|
| 180 |
|
| 181 |
with col1:
|
| 182 |
-
# Filter by Name
|
| 183 |
-
|
| 184 |
with col2:
|
| 185 |
-
# Filter by
|
| 186 |
-
|
| 187 |
with col3:
|
| 188 |
-
# Filter by
|
| 189 |
-
|
| 190 |
with col4:
|
| 191 |
# Filter by Expiry Date
|
| 192 |
expiry_date_filter = st.date_input("Expiry Date", [])
|
|
@@ -194,12 +194,12 @@ else:
|
|
| 194 |
# Apply filters
|
| 195 |
filtered_df = df.copy()
|
| 196 |
|
| 197 |
-
if
|
| 198 |
-
filtered_df = filtered_df[filtered_df['Name'].str.contains(
|
| 199 |
-
if
|
| 200 |
-
filtered_df = filtered_df[filtered_df['
|
| 201 |
-
if
|
| 202 |
-
filtered_df = filtered_df[filtered_df['
|
| 203 |
if expiry_date_filter:
|
| 204 |
if len(expiry_date_filter) == 1:
|
| 205 |
filtered_df = filtered_df[filtered_df['Expiry Date'] == expiry_date_filter[0]]
|
|
@@ -223,4 +223,4 @@ else:
|
|
| 223 |
mime='text/csv',
|
| 224 |
)
|
| 225 |
else:
|
| 226 |
-
st.info("No data matches the filter criteria.")
|
|
|
|
| 10 |
MAIN_LOGO_URL = "https://islamictrusthk.org/assets/images/top-logo.png"
|
| 11 |
SIDEBAR_LOGO_URL = "https://bot.islamictrusthk.org/assets/content_files/20240606095159123011.png"
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# Inject custom CSS for better mobile compatibility
|
| 14 |
st.markdown(
|
| 15 |
"""
|
|
|
|
| 61 |
for i, (_, row) in enumerate(df.iterrows()):
|
| 62 |
col = cols[i % len(cols)]
|
| 63 |
with col:
|
| 64 |
+
st.markdown(f"**Company Name:** {row['Company Name']}")
|
| 65 |
+
st.markdown(f"**Region:** {row['Region']}")
|
| 66 |
+
st.markdown(f"**Factory Type:** {row['Factory Type']}")
|
|
|
|
| 67 |
st.markdown(f"**Expiry Date:** {row['Expiry Date']}")
|
| 68 |
+
st.markdown(f"**Contact:** {row['Contact']}")
|
| 69 |
+
st.markdown(f"**Phone:** {row['Phone']}")
|
| 70 |
+
st.markdown(f"**E-mail:** {row['E-mail']}")
|
| 71 |
st.markdown("---")
|
| 72 |
|
| 73 |
# Initialize session state
|
|
|
|
| 90 |
|
| 91 |
# Function to trigger rerun
|
| 92 |
def trigger_rerun():
|
| 93 |
+
st.experimental_rerun()
|
| 94 |
|
| 95 |
# Authentication block
|
| 96 |
if not st.session_state.authenticated:
|
| 97 |
st.title("Login")
|
| 98 |
username = st.text_input("Username")
|
| 99 |
password = st.text_input("Password", type="password")
|
| 100 |
+
login_button = st.button("Login")
|
| 101 |
+
if login_button:
|
| 102 |
if authenticate(username, password):
|
| 103 |
st.session_state.authenticated = True
|
| 104 |
trigger_rerun()
|
|
|
|
| 155 |
df = st.session_state.df
|
| 156 |
|
| 157 |
# Define required columns
|
| 158 |
+
required_columns = [
|
| 159 |
+
'Issued Date', 'Expiry Date', 'Cert. No', 'Company Name', 'Address', 'Region',
|
| 160 |
+
'Factory Type', 'Contact', 'Phone', 'E-mail', 'Status', 'Member Since'
|
| 161 |
+
]
|
| 162 |
|
| 163 |
# Verify required columns
|
| 164 |
missing_columns = verify_columns(df, required_columns)
|
| 165 |
if missing_columns:
|
| 166 |
st.error(f"The following required columns are missing from the uploaded file: {', '.join(missing_columns)}")
|
| 167 |
else:
|
| 168 |
+
# Format the date columns to remove time
|
| 169 |
+
df = format_date_column(df, 'Issued Date')
|
| 170 |
df = format_date_column(df, 'Expiry Date')
|
| 171 |
|
| 172 |
# Display the dataframe
|
|
|
|
| 179 |
col1, col2, col3, col4 = st.columns(4)
|
| 180 |
|
| 181 |
with col1:
|
| 182 |
+
# Filter by Company Name
|
| 183 |
+
company_name_filter = st.text_input("Company Name contains")
|
| 184 |
with col2:
|
| 185 |
+
# Filter by Region
|
| 186 |
+
region_filter = st.multiselect("Region", df['Region'].drop_duplicates())
|
| 187 |
with col3:
|
| 188 |
+
# Filter by Factory Type
|
| 189 |
+
factory_type_filter = st.multiselect("Factory Type", df['Factory Type'].drop_duplicates())
|
| 190 |
with col4:
|
| 191 |
# Filter by Expiry Date
|
| 192 |
expiry_date_filter = st.date_input("Expiry Date", [])
|
|
|
|
| 194 |
# Apply filters
|
| 195 |
filtered_df = df.copy()
|
| 196 |
|
| 197 |
+
if company_name_filter:
|
| 198 |
+
filtered_df = filtered_df[filtered_df['Company Name'].str.contains(company_name_filter, case=False, na=False)]
|
| 199 |
+
if region_filter:
|
| 200 |
+
filtered_df = filtered_df[filtered_df['Region'].isin(region_filter)]
|
| 201 |
+
if factory_type_filter:
|
| 202 |
+
filtered_df = filtered_df[filtered_df['Factory Type'].isin(factory_type_filter)]
|
| 203 |
if expiry_date_filter:
|
| 204 |
if len(expiry_date_filter) == 1:
|
| 205 |
filtered_df = filtered_df[filtered_df['Expiry Date'] == expiry_date_filter[0]]
|
|
|
|
| 223 |
mime='text/csv',
|
| 224 |
)
|
| 225 |
else:
|
| 226 |
+
st.info("No data matches the filter criteria.")
|