Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import numpy as np
|
|
4 |
import os
|
5 |
|
6 |
# Configure the page to be mobile-friendly
|
7 |
-
st.set_page_config(layout="centered", page_title="Restaurant Data Viewer")
|
8 |
|
9 |
# URLs for the logos
|
10 |
MAIN_LOGO_URL = "https://islamictrusthk.org/assets/images/top-logo.png"
|
@@ -70,46 +70,6 @@ def display_tiles(df, cols):
|
|
70 |
st.markdown(f"**E-mail:** {row['E-mail']}")
|
71 |
st.markdown("---")
|
72 |
|
73 |
-
# Function to detect the format and standardize the data
|
74 |
-
def standardize_data(df):
|
75 |
-
format_1_columns = {'Name', 'Address', 'Tel', 'Cuisine', 'Expiry Date', 'Location', 'Restaurant Type', 'Website', 'Directions'}
|
76 |
-
format_2_columns = {'Issued Date', 'Expiry Date', 'Cert. No', 'Company Name', 'Address', 'Region', 'Factory Type', 'Contact', 'Phone', 'E-mail', 'Status', 'Member Since'}
|
77 |
-
|
78 |
-
if format_1_columns.issubset(df.columns):
|
79 |
-
df = df.rename(columns={
|
80 |
-
'Name': 'Company Name',
|
81 |
-
'Address': 'Address',
|
82 |
-
'Tel': 'Phone',
|
83 |
-
'Cuisine': 'Factory Type',
|
84 |
-
'Expiry Date': 'Expiry Date',
|
85 |
-
'Location': 'Region',
|
86 |
-
'Restaurant Type': 'Factory Type',
|
87 |
-
'Website': 'Website',
|
88 |
-
'Directions': 'Directions'
|
89 |
-
})
|
90 |
-
required_columns = ['Company Name', 'Address', 'Phone', 'Factory Type', 'Expiry Date', 'Region', 'Website', 'Directions']
|
91 |
-
elif format_2_columns.issubset(df.columns):
|
92 |
-
df = df.rename(columns={
|
93 |
-
'Issued Date': 'Issued Date',
|
94 |
-
'Expiry Date': 'Expiry Date',
|
95 |
-
'Cert. No': 'Cert No',
|
96 |
-
'Company Name': 'Company Name',
|
97 |
-
'Address': 'Address',
|
98 |
-
'Region': 'Region',
|
99 |
-
'Factory Type': 'Factory Type',
|
100 |
-
'Contact': 'Contact',
|
101 |
-
'Phone': 'Phone',
|
102 |
-
'E-mail': 'E-mail',
|
103 |
-
'Status': 'Status',
|
104 |
-
'Member Since': 'Member Since'
|
105 |
-
})
|
106 |
-
required_columns = ['Issued Date', 'Expiry Date', 'Cert No', 'Company Name', 'Address', 'Region', 'Factory Type', 'Contact', 'Phone', 'E-mail', 'Status', 'Member Since']
|
107 |
-
else:
|
108 |
-
st.error("Unsupported file format")
|
109 |
-
return None, []
|
110 |
-
|
111 |
-
return df, required_columns
|
112 |
-
|
113 |
# Initialize session state
|
114 |
if 'df' not in st.session_state:
|
115 |
st.session_state.df = None
|
@@ -120,8 +80,8 @@ if 'login_attempt' not in st.session_state:
|
|
120 |
|
121 |
# List of valid usernames and passwords
|
122 |
user_credentials = {
|
123 |
-
'
|
124 |
-
'
|
125 |
}
|
126 |
|
127 |
# Authentication function
|
@@ -149,7 +109,7 @@ if not st.session_state.authenticated:
|
|
149 |
else:
|
150 |
st.write("User authenticated successfully")
|
151 |
st.image(MAIN_LOGO_URL, use_column_width=True)
|
152 |
-
st.title("Restaurant Data Viewer")
|
153 |
|
154 |
# File upload logic
|
155 |
with st.sidebar:
|
@@ -168,10 +128,7 @@ else:
|
|
168 |
|
169 |
st.success(f"File '{uploaded_file.name}' uploaded successfully.")
|
170 |
df = load_data(file_path)
|
171 |
-
df
|
172 |
-
if df is not None:
|
173 |
-
st.session_state.df = df
|
174 |
-
st.session_state.required_columns = required_columns
|
175 |
except Exception as e:
|
176 |
st.error(f"An error occurred: {e}")
|
177 |
|
@@ -189,10 +146,7 @@ else:
|
|
189 |
try:
|
190 |
file_path = os.path.join(UPLOAD_DIR, selected_file)
|
191 |
df = load_data(file_path)
|
192 |
-
df
|
193 |
-
if df is not None:
|
194 |
-
st.session_state.df = df
|
195 |
-
st.session_state.required_columns = required_columns
|
196 |
except Exception as e:
|
197 |
st.error(f"An error occurred: {e}")
|
198 |
else:
|
@@ -202,12 +156,19 @@ else:
|
|
202 |
if st.session_state.df is not None:
|
203 |
df = st.session_state.df
|
204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
# Verify required columns
|
206 |
-
missing_columns = verify_columns(df,
|
207 |
if missing_columns:
|
208 |
st.error(f"The following required columns are missing from the uploaded file: {', '.join(missing_columns)}")
|
209 |
else:
|
210 |
# Format the date columns to remove time
|
|
|
211 |
df = format_date_column(df, 'Expiry Date')
|
212 |
|
213 |
# Display the dataframe
|
@@ -223,11 +184,11 @@ else:
|
|
223 |
# Filter by Company Name
|
224 |
company_name_filter = st.text_input("Company Name contains")
|
225 |
with col2:
|
226 |
-
# Filter by
|
227 |
-
|
228 |
with col3:
|
229 |
-
# Filter by
|
230 |
-
|
231 |
with col4:
|
232 |
# Filter by Expiry Date
|
233 |
expiry_date_filter = st.date_input("Expiry Date", [])
|
@@ -237,10 +198,10 @@ else:
|
|
237 |
|
238 |
if company_name_filter:
|
239 |
filtered_df = filtered_df[filtered_df['Company Name'].str.contains(company_name_filter, case=False, na=False)]
|
240 |
-
if
|
241 |
-
filtered_df = filtered_df[filtered_df['Region'].isin(
|
242 |
-
if
|
243 |
-
filtered_df = filtered_df[filtered_df['Factory Type'].isin(
|
244 |
if expiry_date_filter:
|
245 |
if len(expiry_date_filter) == 1:
|
246 |
filtered_df = filtered_df[filtered_df['Expiry Date'] == expiry_date_filter[0]]
|
@@ -264,4 +225,4 @@ else:
|
|
264 |
mime='text/csv',
|
265 |
)
|
266 |
else:
|
267 |
-
st.info("No data matches the filter criteria.")
|
|
|
4 |
import os
|
5 |
|
6 |
# Configure the page to be mobile-friendly
|
7 |
+
st.set_page_config(layout="centered", page_title="Halal Restaurant Data Viewer")
|
8 |
|
9 |
# URLs for the logos
|
10 |
MAIN_LOGO_URL = "https://islamictrusthk.org/assets/images/top-logo.png"
|
|
|
70 |
st.markdown(f"**E-mail:** {row['E-mail']}")
|
71 |
st.markdown("---")
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
# Initialize session state
|
74 |
if 'df' not in st.session_state:
|
75 |
st.session_state.df = None
|
|
|
80 |
|
81 |
# List of valid usernames and passwords
|
82 |
user_credentials = {
|
83 |
+
'ubaid': 'Password@123',
|
84 |
+
'bot': 'Trust@123'
|
85 |
}
|
86 |
|
87 |
# Authentication function
|
|
|
109 |
else:
|
110 |
st.write("User authenticated successfully")
|
111 |
st.image(MAIN_LOGO_URL, use_column_width=True)
|
112 |
+
st.title("Hong Kong Halal Restaurant Data Viewer")
|
113 |
|
114 |
# File upload logic
|
115 |
with st.sidebar:
|
|
|
128 |
|
129 |
st.success(f"File '{uploaded_file.name}' uploaded successfully.")
|
130 |
df = load_data(file_path)
|
131 |
+
st.session_state.df = df
|
|
|
|
|
|
|
132 |
except Exception as e:
|
133 |
st.error(f"An error occurred: {e}")
|
134 |
|
|
|
146 |
try:
|
147 |
file_path = os.path.join(UPLOAD_DIR, selected_file)
|
148 |
df = load_data(file_path)
|
149 |
+
st.session_state.df = df
|
|
|
|
|
|
|
150 |
except Exception as e:
|
151 |
st.error(f"An error occurred: {e}")
|
152 |
else:
|
|
|
156 |
if st.session_state.df is not None:
|
157 |
df = st.session_state.df
|
158 |
|
159 |
+
# Define required columns
|
160 |
+
required_columns = [
|
161 |
+
'Issued Date', 'Expiry Date', 'Cert. No', 'Company Name', 'Address', 'Region',
|
162 |
+
'Factory Type', 'Contact', 'Phone', 'E-mail', 'Status', 'Member Since'
|
163 |
+
]
|
164 |
+
|
165 |
# Verify required columns
|
166 |
+
missing_columns = verify_columns(df, required_columns)
|
167 |
if missing_columns:
|
168 |
st.error(f"The following required columns are missing from the uploaded file: {', '.join(missing_columns)}")
|
169 |
else:
|
170 |
# Format the date columns to remove time
|
171 |
+
df = format_date_column(df, 'Issued Date')
|
172 |
df = format_date_column(df, 'Expiry Date')
|
173 |
|
174 |
# Display the dataframe
|
|
|
184 |
# Filter by Company Name
|
185 |
company_name_filter = st.text_input("Company Name contains")
|
186 |
with col2:
|
187 |
+
# Filter by Region
|
188 |
+
region_filter = st.multiselect("Region", df['Region'].drop_duplicates())
|
189 |
with col3:
|
190 |
+
# Filter by Factory Type
|
191 |
+
factory_type_filter = st.multiselect("Factory Type", df['Factory Type'].drop_duplicates())
|
192 |
with col4:
|
193 |
# Filter by Expiry Date
|
194 |
expiry_date_filter = st.date_input("Expiry Date", [])
|
|
|
198 |
|
199 |
if company_name_filter:
|
200 |
filtered_df = filtered_df[filtered_df['Company Name'].str.contains(company_name_filter, case=False, na=False)]
|
201 |
+
if region_filter:
|
202 |
+
filtered_df = filtered_df[filtered_df['Region'].isin(region_filter)]
|
203 |
+
if factory_type_filter:
|
204 |
+
filtered_df = filtered_df[filtered_df['Factory Type'].isin(factory_type_filter)]
|
205 |
if expiry_date_filter:
|
206 |
if len(expiry_date_filter) == 1:
|
207 |
filtered_df = filtered_df[filtered_df['Expiry Date'] == expiry_date_filter[0]]
|
|
|
225 |
mime='text/csv',
|
226 |
)
|
227 |
else:
|
228 |
+
st.info("No data matches the filter criteria.")
|