maringetxway commited on
Commit
156531b
Β·
verified Β·
1 Parent(s): 520d961

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -14
app.py CHANGED
@@ -129,29 +129,35 @@ def filter_by_fields(selected_country, selected_city, selected_language):
129
 
130
  df = pd.DataFrame(data)
131
 
132
- # Normalize key fields
133
  df["Country"] = df["Country"].astype(str).str.strip().str.title()
134
  df["City"] = df["City"].astype(str).str.strip().str.title()
 
 
135
  df["Languages"] = df["Languages"].apply(
136
  lambda x: ", ".join(x) if isinstance(x, list) else str(x)
137
- ).str.lower().str.strip()
138
 
139
- # Apply filters
140
  if selected_country != "All":
141
- df = df[df["Country"] == selected_country.strip().title()]
 
 
142
  if selected_city != "All":
143
- df = df[df["City"] == selected_city.strip().title()]
 
 
144
  if selected_language != "All":
145
- df = df[df["Languages"].str.contains(selected_language.lower())]
 
146
 
147
  if df.empty:
148
  return "<p>No participants match your filters.</p>"
149
 
150
- # Optional: hide address
151
  if "Address" in df.columns:
152
  df = df.drop(columns=["Address"])
153
 
154
- # Optional: rename headers
155
  display_names = {
156
  "Discord": "Discord",
157
  "Name": "Name",
@@ -168,16 +174,14 @@ def filter_by_fields(selected_country, selected_city, selected_language):
168
  "Project Idea": "Project Idea"
169
  }
170
 
171
- html = '<h3 style="margin-top:20px;">πŸ” Find your matching Teammates & Register your team <a href="https://forms.gle/gJEMGD4CEA2emhD18" target="_blank">here</a>πŸ‘ˆπŸ‘ˆ</h3>'
172
  html += "<table style='width:100%; border-collapse: collapse;'>"
173
 
174
- # Table headers
175
  html += "<tr>"
176
  for col in df.columns:
177
  html += f"<th style='border: 1px solid #ccc; padding: 6px;'>{display_names.get(col, col)}</th>"
178
  html += "</tr>"
179
 
180
- # Table rows
181
  for _, row in df.iterrows():
182
  html += "<tr>"
183
  for col in df.columns:
@@ -190,6 +194,7 @@ def filter_by_fields(selected_country, selected_city, selected_language):
190
  html += "</table>"
191
  return html
192
 
 
193
  # Delete discord
194
  def delete_by_discord(discord, code):
195
  if code != ADMIN_CODE:
@@ -254,9 +259,10 @@ def download_csv(code):
254
  return csv_path
255
 
256
 
257
- country_filter.change(fn=update_city_filter, inputs=[country_filter], outputs=[city_filter])
258
- for dropdown in [country_filter, city_filter, language_filter]:
259
- dropdown.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=[table_html])
 
260
 
261
 
262
  gr.Markdown("---\n### πŸ›‘οΈ Admin Panel (delete by Discord)")
 
129
 
130
  df = pd.DataFrame(data)
131
 
132
+ # Normalize Country & City
133
  df["Country"] = df["Country"].astype(str).str.strip().str.title()
134
  df["City"] = df["City"].astype(str).str.strip().str.title()
135
+
136
+ # Normalize Languages: always string, lowercase, comma-separated
137
  df["Languages"] = df["Languages"].apply(
138
  lambda x: ", ".join(x) if isinstance(x, list) else str(x)
139
+ ).str.strip().str.lower()
140
 
141
+ # Normalize filters
142
  if selected_country != "All":
143
+ selected_country = selected_country.strip().title()
144
+ df = df[df["Country"] == selected_country]
145
+
146
  if selected_city != "All":
147
+ selected_city = selected_city.strip().title()
148
+ df = df[df["City"] == selected_city]
149
+
150
  if selected_language != "All":
151
+ selected_language = selected_language.strip().lower()
152
+ df = df[df["Languages"].str.contains(selected_language, na=False)]
153
 
154
  if df.empty:
155
  return "<p>No participants match your filters.</p>"
156
 
157
+ # Hide address if present
158
  if "Address" in df.columns:
159
  df = df.drop(columns=["Address"])
160
 
 
161
  display_names = {
162
  "Discord": "Discord",
163
  "Name": "Name",
 
174
  "Project Idea": "Project Idea"
175
  }
176
 
177
+ html = '<h3 style="margin-top:20px;">πŸ” Find your matching Teammates & Register your team <a href="https://forms.gle/gJEMGD4CEA2emhD18" target="_blank">here</a></h3>'
178
  html += "<table style='width:100%; border-collapse: collapse;'>"
179
 
 
180
  html += "<tr>"
181
  for col in df.columns:
182
  html += f"<th style='border: 1px solid #ccc; padding: 6px;'>{display_names.get(col, col)}</th>"
183
  html += "</tr>"
184
 
 
185
  for _, row in df.iterrows():
186
  html += "<tr>"
187
  for col in df.columns:
 
194
  html += "</table>"
195
  return html
196
 
197
+
198
  # Delete discord
199
  def delete_by_discord(discord, code):
200
  if code != ADMIN_CODE:
 
259
  return csv_path
260
 
261
 
262
+ country_filter.change(fn=update_city_filter, inputs=[country_filter], outputs=[city_filter])
263
+ for dropdown in [country_filter, city_filter, language_filter]:
264
+ dropdown.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=[table_html])
265
+
266
 
267
 
268
  gr.Markdown("---\n### πŸ›‘οΈ Admin Panel (delete by Discord)")