maringetxway commited on
Commit
10c89d7
Β·
verified Β·
1 Parent(s): b103285

Upload 4 files

Browse files
Files changed (3) hide show
  1. app.py +278 -0
  2. requirements.txt +2 -0
  3. teamup_data.json +1 -0
app.py ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import pandas as pd
4
+ import os
5
+
6
+ DATA_FILE = os.path.join("data", "teamup_data.json")
7
+
8
+ ADMIN_CODE = os.getenv("ADMIN_CODE", "")
9
+
10
+
11
+ # Ensure data file exists
12
+ os.makedirs("data", exist_ok=True)
13
+ if not os.path.exists(DATA_FILE) or os.path.getsize(DATA_FILE) == 0:
14
+ with open(DATA_FILE, "w") as f:
15
+ json.dump([], f)
16
+
17
+ def submit_profile(name, discord, city, country, address, looking, onlinecheck, languages, laptop, robot, skills, describe3, experience, idea):
18
+ print("🟒 Submit button clicked.")
19
+ print(f"Incoming: {discord=}, {city=}, {country=}, {languages=}, {laptop=}, {robot=}")
20
+
21
+ if not discord or not city or not country or not laptop or not robot:
22
+ return "❌ Please fill in all required fields."
23
+ if not languages or not isinstance(languages, list) or len(languages) == 0:
24
+ return "❌ Please select at least one language."
25
+
26
+ # Ensure country is stored as a string (in case form allows lists)
27
+ if isinstance(country, list):
28
+ country = country[0] if country else ""
29
+
30
+ with open(DATA_FILE, "r") as f:
31
+ data = json.load(f)
32
+
33
+ for d in data:
34
+ if d["Discord"].lower() == discord.lower():
35
+ d.update({
36
+ "Name": name,
37
+ "City": city,
38
+ "Country": country,
39
+ "Address": address,
40
+ "Looking for Team": looking,
41
+ "Onlinecheck": onlinecheck,
42
+ "Languages": languages,
43
+ "Laptop": laptop,
44
+ "Robot": robot,
45
+ "Skills": skills,
46
+ "Describe3": describe3,
47
+ "Experience": experience,
48
+ "Project Idea": idea
49
+ })
50
+ break
51
+ else:
52
+ data.append({
53
+ "Name": name,
54
+ "Discord": discord,
55
+ "City": city,
56
+ "Country": country,
57
+ "Address": address,
58
+ "Looking for Team": looking,
59
+ "Onlinecheck": onlinecheck,
60
+ "Languages": languages,
61
+ "Laptop": laptop,
62
+ "Robot": robot,
63
+ "Skills": skills,
64
+ "Describe3": describe3,
65
+ "Experience": experience,
66
+ "Project Idea": idea
67
+ })
68
+
69
+ try:
70
+ with open(DATA_FILE, "w") as f:
71
+ json.dump(data, f, indent=2)
72
+ print(f"βœ… Successfully wrote {len(data)} profiles to {DATA_FILE}")
73
+ except Exception as e:
74
+ print(f"❌ Failed to write to {DATA_FILE}: {e}")
75
+ return "❌ Error saving your profile. Please try again."
76
+
77
+ return "βœ… Profile saved!"
78
+
79
+
80
+ def filter_by_fields(selected_country, selected_city, selected_language):
81
+ with open(DATA_FILE, "r") as f:
82
+ data = json.load(f)
83
+ df = pd.DataFrame(data)
84
+
85
+ # Convert list values to readable strings
86
+ df["Languages"] = df["Languages"].apply(lambda langs: ", ".join(langs) if isinstance(langs, list) else langs)
87
+
88
+ if df.empty or "Country" not in df.columns or "Languages" not in df.columns:
89
+ return "<p>No participants found.</p>"
90
+
91
+ if selected_country != "All":
92
+ df = df[df["Country"] == selected_country]
93
+
94
+ if selected_city != "All":
95
+ df = df[df["City"] == selected_city]
96
+
97
+ if selected_language != "All":
98
+ df = df[df["Languages"].apply(lambda langs: selected_language in langs)]
99
+
100
+
101
+ # Hide address
102
+ if "Address" in df.columns:
103
+ df = df.drop(columns=["Address"])
104
+
105
+ # Rename column headers for display only
106
+ display_names = {
107
+ "Discord": "Discord",
108
+ "Name": "Name",
109
+ "City": "City",
110
+ "Country": "Country",
111
+ "Looking for Team": "Looking for Team",
112
+ "Onlinecheck": "How?",
113
+ "Languages": "Languages",
114
+ "Laptop": "Laptop",
115
+ "Robot": "Robot",
116
+ "Skills": "Skills",
117
+ "Describe3": "Describe",
118
+ "Experience": "Experience",
119
+ "Project Idea": "Project Idea"
120
+ }
121
+
122
+ html = '<h3 style="margin-top:20px;">πŸ” Find your matching Teammates & Register your team <a href="https://forms.gle/gJEMGD4CEA2emhD18" target="_blank">here</a>πŸ‘ˆπŸ‘ˆ</h3>'
123
+ html += "<table style='width:100%; border-collapse: collapse;'>"
124
+
125
+ # Header row
126
+ html += "<tr>" + "".join(
127
+ f"<th style='border: 1px solid #ccc; padding: 6px;'>{display_names.get(col, col)}</th>"
128
+ for col in df.columns
129
+ ) + "</tr>"
130
+
131
+ # Data rows
132
+ for _, row in df.iterrows():
133
+ html += "<tr>"
134
+ for col in df.columns:
135
+ val = row[col]
136
+ if col == "Discord":
137
+ val = f"<a href='https://discord.com/users/{val}' target='_blank'>{val}</a>"
138
+ html += f"<td style='border: 1px solid #eee; padding: 6px;'>{val}</td>"
139
+ html += "</tr>"
140
+
141
+ html += "</table>"
142
+ return html
143
+
144
+
145
+
146
+
147
+ def update_dropdowns():
148
+ with open(DATA_FILE, "r") as f:
149
+ data = json.load(f)
150
+ if not data:
151
+ return ["All"], ["All"], ["All"]
152
+ df = pd.DataFrame(data)
153
+ if "Country" not in df.columns or "Languages" not in df.columns or "City" not in df.columns:
154
+ return ["All"], ["All"], ["All"]
155
+ country_choices = sorted(list(df["Country"].dropna().unique()))
156
+ city_choices = sorted(list(df["City"].dropna().unique()))
157
+ language_set = set()
158
+ for lang_list in df["Languages"].dropna():
159
+ language_set.update(lang_list)
160
+ return (
161
+ ["All"] + country_choices,
162
+ ["All"] + sorted(language_set),
163
+ ["All"] + city_choices
164
+ )
165
+
166
+
167
+
168
+ def delete_by_discord(discord, code):
169
+ if code != ADMIN_CODE:
170
+ return "❌ Invalid admin code."
171
+ with open(DATA_FILE, "r") as f:
172
+ data = json.load(f)
173
+ new_data = [d for d in data if d["Discord"].lower() != discord.lower()]
174
+ with open(DATA_FILE, "w") as f:
175
+ json.dump(new_data, f, indent=2)
176
+ return f"πŸ—‘οΈ Deleted user with Discord: {discord}"
177
+
178
+ with gr.Blocks() as demo:
179
+ gr.Markdown("# 🌍 LeRobot Worldwide Hackathon - Team-Up Dashboard")
180
+ gr.Markdown("Submit or update your profile. Required fields marked with *. Find matching teammates and contact them on Discord.")
181
+
182
+ with gr.Row():
183
+ with gr.Column():
184
+ name = gr.Text(label="Name")
185
+ discord = gr.Text(label="πŸ‘€ Discord Username *")
186
+ city = gr.Text(label="πŸ“ City *")
187
+ country = gr.Text(label="🌍 Country *")
188
+ address = gr.Text(label="Address (optional)")
189
+ looking = gr.Radio(["Yes", "No"], label="πŸ” Looking for a team?")
190
+ onlinecheck = gr.Radio(["Participate Online", "Join a Local Hackathon"], label="πŸš€ I will...")
191
+ languages = gr.CheckboxGroup(choices=["English", "French", "Spanish", "German", "Portuguese", "Chinese", "Arabic", "Hindi"], label="Languages Spoken *")
192
+ laptop = gr.Text(label="πŸ’» Laptop Setup *")
193
+ robot = gr.Text(label="Robot Setup *")
194
+ skills = gr.Text(label="🧠 Your Skills (comma separated)")
195
+ describe3 = gr.Text(label="πŸ€— 3 Words That Describe You")
196
+ experience = gr.Dropdown(choices=["Beginner", "Intermediate", "Advanced"], label="Experience Level", value="Beginner")
197
+ idea = gr.Textbox(label="Project Idea (optional)")
198
+ submit_btn = gr.Button("Submit or Update Profile βœ…")
199
+ status = gr.Textbox(label="", interactive=False)
200
+
201
+ with gr.Column():
202
+ gr.Markdown("🎯 Choose your preferences to find your teammates (country, city or language)")
203
+ country_filter = gr.Dropdown(label="Filter by Country", choices=["All"], value="All", allow_custom_value=False)
204
+ city_filter = gr.Dropdown(label="Filter by City", choices=["All"], value="All", allow_custom_value=False)
205
+ language_filter = gr.Dropdown(label="Filter by Language", choices=["All"], value="All", allow_custom_value=False)
206
+ table_html = gr.HTML(label="Matching Participants")
207
+
208
+ submit_btn.click(
209
+ submit_profile,
210
+ inputs=[name, discord, city, country, address, looking, onlinecheck, languages, laptop, robot, skills, describe3, experience, idea],
211
+ outputs=[status]
212
+ )
213
+
214
+
215
+
216
+ def update_dropdown_choices():
217
+ with open(DATA_FILE, "r") as f:
218
+ data = json.load(f)
219
+ df = pd.DataFrame(data)
220
+
221
+ country_choices = sorted(df["Country"].dropna().unique()) if "Country" in df else []
222
+ city_choices = sorted(df["City"].dropna().unique()) if "City" in df else []
223
+ language_set = set()
224
+ if "Languages" in df:
225
+ for lang_list in df["Languages"].dropna():
226
+ if isinstance(lang_list, list):
227
+ language_set.update(lang_list)
228
+ elif isinstance(lang_list, str):
229
+ language_set.update(lang_list.split(", "))
230
+ return (
231
+ gr.update(choices=["All"] + list(country_choices), value="All"),
232
+ gr.update(choices=["All"] + list(city_choices), value="All"),
233
+ gr.update(choices=["All"] + sorted(language_set), value="All")
234
+ )
235
+
236
+
237
+
238
+ def download_csv(code):
239
+ if code != ADMIN_CODE:
240
+ raise gr.Error("❌ Invalid admin code.")
241
+ with open(DATA_FILE, "r") as f:
242
+ data = json.load(f)
243
+ df = pd.DataFrame(data)
244
+ csv_path = os.path.join("data", "teamup_export.csv")
245
+ df.to_csv(csv_path, index=False)
246
+ return csv_path
247
+
248
+ with demo:
249
+ demo.load(
250
+ fn=lambda: filter_by_fields("All", "All", "All"),
251
+ inputs=[],
252
+ outputs=[table_html]
253
+ )
254
+
255
+ demo.load(fn=update_dropdown_choices, outputs=[country_filter, city_filter, language_filter])
256
+
257
+ country_filter.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=table_html)
258
+ city_filter.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=table_html)
259
+ language_filter.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=table_html)
260
+
261
+
262
+
263
+ gr.Markdown("---\n### πŸ›‘οΈ Admin Panel (delete by Discord)")
264
+ admin_discord = gr.Text(label="Discord Username")
265
+ admin_code = gr.Text(label="Admin Code", type="password")
266
+ del_btn = gr.Button("Delete Profile")
267
+ del_status = gr.Textbox(label="Status", interactive=False)
268
+ del_btn.click(delete_by_discord, inputs=[admin_discord, admin_code], outputs=del_status)
269
+
270
+ # πŸ” CSV Download Section (admin-only)
271
+ gr.Markdown("---\n### πŸ“₯ Admin Export CSV")
272
+ export_code = gr.Text(label="Admin Code", type="password")
273
+ download_btn = gr.Button("Generate and Download CSV")
274
+ download_file = gr.File(label="CSV Export", interactive=False)
275
+ download_btn.click(fn=download_csv, inputs=[export_code], outputs=[download_file])
276
+
277
+ demo.launch()
278
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ pandas
teamup_data.json ADDED
@@ -0,0 +1 @@
 
 
1
+ []