Spaces:
Sleeping
Sleeping
File size: 15,825 Bytes
10c89d7 715218e 10c89d7 ea2400d 36075c9 10c89d7 cdb68ce 36075c9 d2efda9 eabdf96 d2efda9 11dc894 33c75d0 11dc894 4a79184 11dc894 2a6ea32 36075c9 10c89d7 4a79184 715218e 11dc894 715218e 36075c9 11dc894 10c89d7 11dc894 53b15b0 11dc894 2b22ecd 11dc894 156531b 2b22ecd 11dc894 2b22ecd 11dc894 2b22ecd 11dc894 4a79184 11dc894 2b22ecd d23fcf4 d06f8eb 717a260 715218e 520d961 f6ed65a 715218e 11dc894 715218e 26bec7a 11dc894 2b22ecd 715218e 11dc894 715218e 156531b 78acf2b 11dc894 78acf2b 11dc894 d06f8eb ba78dd6 4ad726e ba78dd6 d06f8eb 11dc894 d06f8eb 94224bf d06f8eb 11dc894 f327544 11dc894 76d7fc4 23fad42 eabdf96 76d7fc4 23fad42 76d7fc4 23fad42 76d7fc4 11dc894 0ea8700 e3637a6 11dc894 0ea8700 11dc894 715218e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
import gradio as gr
import pandas as pd
import sqlite3
import os
import datetime
import shutil
DATA_DIR = "data"
os.makedirs(DATA_DIR, exist_ok=True)
DB_PATH = os.path.join(DATA_DIR, "teamup.db")
BACKUP_DIR = os.path.join(DATA_DIR, "backup")
os.makedirs(BACKUP_DIR, exist_ok=True)
ADMIN_CODE = os.getenv("ADMIN_CODE", "")
PAGE_SIZE = 12
LANGUAGES = ["English", "French", "Spanish", "German", "Portuguese", "Chinese", "Arabic", "Hindi"]
ALL_COUNTRIES = sorted(set([
"Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Australia", "Austria",
"Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bhutan",
"Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burundi",
"Cabo Verde", "Cambodia", "Cameroon", "Canada", "Central African Republic", "Chad", "Chile", "China", "Colombia",
"Comoros", "Congo (Congo-Brazzaville)", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic (Czechia)",
"Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt",
"El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Eswatini", "Ethiopia", "Fiji", "Finland",
"France", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Greece", "Grenada", "Guatemala", "Guinea", "Guinea-Bissau",
"Guyana", "Haiti", "Honduras", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy",
"Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon",
"Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Madagascar", "Malawi", "Malaysia", "Maldives",
"Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia",
"Montenegro", "Morocco", "Mozambique", "Myanmar (formerly Burma)", "Namibia", "Nauru", "Nepal", "Netherlands",
"New Zealand", "Nicaragua", "Niger", "Nigeria", "North Korea", "North Macedonia", "Norway", "Oman", "Pakistan",
"Palau", "Palestine State", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal",
"Qatar", "Romania", "Russia", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines",
"Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone",
"Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Korea", "South Sudan",
"Spain", "Sri Lanka", "Sudan", "Suriname", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania",
"Thailand", "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
"Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States of America", "Uruguay",
"Uzbekistan", "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Yemen", "Zambia", "Zimbabwe"
]))
def init_db():
with sqlite3.connect(DB_PATH) as conn:
conn.execute("""
CREATE TABLE IF NOT EXISTS teamup (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
discord TEXT UNIQUE,
city TEXT,
country TEXT,
address TEXT,
looking TEXT,
onlinecheck TEXT,
languages TEXT,
laptop TEXT,
robot TEXT,
skills TEXT,
describe3 TEXT,
experience TEXT,
idea TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
""")
init_db()
def backup_db():
timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
backup_file = os.path.join(BACKUP_DIR, f"teamup_backup_{timestamp}.db")
shutil.copy(DB_PATH, backup_file)
backups = sorted(os.listdir(BACKUP_DIR))
while len(backups) > 20:
os.remove(os.path.join(BACKUP_DIR, backups.pop(0)))
def submit_profile(name, discord, city, country, address, looking, onlinecheck, languages, laptop, robot, skills, describe3, experience, idea):
if not discord or not city or not country or not laptop or not robot:
return "β Please fill in all required fields."
lang_str = ", ".join(languages) if isinstance(languages, list) else languages
with sqlite3.connect(DB_PATH) as conn:
conn.execute("""
INSERT INTO teamup (discord, name, city, country, address, looking, onlinecheck, languages, laptop, robot, skills, describe3, experience, idea)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(discord) DO UPDATE SET
name=excluded.name,
city=excluded.city,
country=excluded.country,
address=excluded.address,
looking=excluded.looking,
onlinecheck=excluded.onlinecheck,
languages=excluded.languages,
laptop=excluded.laptop,
robot=excluded.robot,
skills=excluded.skills,
describe3=excluded.describe3,
experience=excluded.experience,
idea=excluded.idea
""", (discord, name, city.title(), country.title(), address, looking, onlinecheck, lang_str.lower(), laptop, robot, skills, describe3, experience, idea))
backup_db()
return "β
Profile saved!"
def filter_by_fields(selected_country, selected_city, selected_language, page):
try:
page = int(page)
except:
page = 1
offset = (page - 1) * PAGE_SIZE
query = "SELECT * FROM teamup"
filters = []
params = []
if selected_country != "All":
filters.append("country = ?")
params.append(selected_country.title())
if selected_city != "All":
filters.append("city = ?")
params.append(selected_city.title())
if selected_language != "All":
filters.append("languages LIKE ?")
params.append(f"%{selected_language.lower()}%")
if filters:
query += " WHERE " + " AND ".join(filters)
query += " ORDER BY created_at DESC LIMIT ? OFFSET ?"
params.extend([PAGE_SIZE, offset])
with sqlite3.connect(DB_PATH) as conn:
df = pd.read_sql_query(query, conn, params=params)
total_query = "SELECT COUNT(*) FROM teamup" + (" WHERE " + " AND ".join(filters) if filters else "")
total_count = pd.read_sql_query(total_query, conn, params=params[:-2] if filters else []).iloc[0, 0]
if df.empty:
return "<p>No participants match your filters.</p>", page, total_count
html = "<h3 style='margin-top:20px;'>π Find your matching Teammates & Register your team <a href='https://forms.gle/gJEMGD4CEA2emhD18' target='_blank'>here</a></h3>"
html += "<table style='width:100%; border-collapse: collapse;'><tr>"
headers = ["Discord", "Name", "City", "Country", "Looking", "How?", "Languages", "Laptop", "Robot", "Skills", "Description", "Experience", "Idea"]
for col in headers:
html += f"<th style='border:1px solid #ccc; padding:6px;'>{col}</th>"
html += "</tr>"
for _, row in df.iterrows():
html += "<tr>"
for col in ["discord", "name", "city", "country", "looking", "onlinecheck", "languages", "laptop", "robot", "skills", "describe3", "experience", "idea"]:
val = row[col]
if col == "discord":
val = f"<a href='https://discord.com/users/{val}' target='_blank'>{val}</a>"
html += f"<td style='border:1px solid #eee; padding:6px;'>{val}</td>"
html += "</tr>"
html += "</table>"
return html, page, total_count
def update_city_filter(country):
with sqlite3.connect(DB_PATH) as conn:
if country == "All":
result = conn.execute("SELECT DISTINCT city FROM teamup").fetchall()
else:
result = conn.execute("SELECT DISTINCT city FROM teamup WHERE country = ?", (country.title(),)).fetchall()
cities = [r[0].title() for r in result if r[0]]
return gr.update(choices=["All"] + sorted(cities), value="All")
def delete_by_discord(discord, code):
if code != ADMIN_CODE:
return "β Invalid admin code."
with sqlite3.connect(DB_PATH) as conn:
conn.execute("DELETE FROM teamup WHERE lower(discord) = ?", (discord.lower(),))
return f"ποΈ Deleted user with Discord: {discord}"
def download_csv(code):
if code != ADMIN_CODE:
raise gr.Error("β Invalid admin code.")
with sqlite3.connect(DB_PATH) as conn:
df = pd.read_sql_query("SELECT * FROM teamup", conn)
csv_path = os.path.join(DATA_DIR, "teamup_export.csv")
df.to_csv(csv_path, index=False)
return csv_path
def interface():
with gr.Blocks(css=".gr-dropdown { max-height: 100px; overflow-y: auto; font-size: 12px; }") as demo:
gr.Markdown("""
# π LeRobot Worldwide Hackathon - Team-Up Dashboard
Welcome to the Team-Up dashboard! Follow these steps:
1. **Submit or update** your profile to help others find and contact you via Discord. Required fields are marked with `*`.
2. **Use the filters** (country, city, language) to search for teammates from around the world.
""")
with gr.Row():
with gr.Column():
name = gr.Text(label="Name")
discord = gr.Text(label="π€ Discord Username *")
city = gr.Text(label="π City *")
country = gr.Dropdown(label="π Country *", choices=ALL_COUNTRIES, value="France")
address = gr.Text(label="Address (optional)")
looking = gr.Radio(["Yes", "No"], label="π Looking for a team?")
onlinecheck = gr.Radio(["Participate Online", "Join a Local Hackathon"], label="π I will...")
languages = gr.CheckboxGroup(choices=LANGUAGES, label="Languages Spoken *")
laptop = gr.Text(label="π» Laptop Setup *")
robot = gr.Text(label="π€ Robot Setup *")
skills = gr.Text(label="π§ Skills (comma separated)")
describe3 = gr.Text(label="3 Words That Describe You")
experience = gr.Dropdown(choices=["Beginner", "Intermediate", "Advanced"], label="Experience Level", value="Beginner")
idea = gr.Textbox(label="Project Idea (optional)")
submit_btn = gr.Button("Submit or Update β
")
status = gr.Textbox(label="", interactive=False)
with gr.Column():
gr.Markdown("""
π― **Use the filters below to find your ideal teammates:**
""")
country_filter = gr.Dropdown(label="Filter by Country", choices=["All"] + ALL_COUNTRIES, value="All")
city_filter = gr.Dropdown(label="Filter by City", choices=["All"], value="All")
language_filter = gr.Dropdown(label="Filter by Language", choices=["All"] + LANGUAGES, value="All")
page_state = gr.Number(value=1, visible=False)
table_html = gr.HTML(label="Matching Participants")
prev_btn = gr.Button("β¬
οΈ Previous Page")
next_btn = gr.Button("β‘οΈ Next Page")
submit_btn.click(submit_profile, inputs=[name, discord, city, country, address, looking, onlinecheck, languages, laptop, robot, skills, describe3, experience, idea], outputs=[status])
submit_btn.click(
fn=submit_profile,
inputs=[name, discord, city, country, address, looking, onlinecheck, languages, laptop, robot, skills, describe3, experience, idea],
outputs=[status]
).then(
fn=lambda: 1,
outputs=[page_state]
).then(
fn=filter_by_fields,
inputs=[country_filter, city_filter, language_filter, gr.State(1)],
outputs=[table_html, page_state, gr.Number(visible=False)]
)
country_filter.change(update_city_filter, inputs=[country_filter], outputs=[city_filter])
for dropdown in [country_filter, city_filter, language_filter]:
dropdown.change(lambda c, ci, l: (1,), inputs=[country_filter, city_filter, language_filter], outputs=[page_state])
dropdown.change(filter_by_fields, inputs=[country_filter, city_filter, language_filter, page_state], outputs=[table_html, page_state, gr.Number(visible=False)])
def get_total_pages(selected_country, selected_city, selected_language):
filters = []
params = []
if selected_country != "All":
filters.append("country = ?")
params.append(selected_country.title())
if selected_city != "All":
filters.append("city = ?")
params.append(selected_city.title())
if selected_language != "All":
filters.append("languages LIKE ?")
params.append(f"%{selected_language.lower()}%")
query = "SELECT COUNT(*) FROM teamup"
if filters:
query += " WHERE " + " AND ".join(filters)
with sqlite3.connect(DB_PATH) as conn:
total = pd.read_sql_query(query, conn, params=params).iloc[0, 0]
return max(1, (total - 1) // PAGE_SIZE + 1)
def get_filtered_page(c, ci, l, p):
return filter_by_fields(c, ci, l, p)
def on_filter_change(c, ci, l):
new_page = 1
return get_filtered_page(c, ci, l, new_page) # always restart on page 1
for dropdown in [country_filter, city_filter, language_filter]:
dropdown.change(
fn=on_filter_change,
inputs=[country_filter, city_filter, language_filter],
outputs=[table_html, page_state, gr.Number(visible=False)]
)
prev_btn.click(
fn=lambda p: max(p - 1, 1),
inputs=[page_state],
outputs=[page_state]
).then(
fn=get_filtered_page,
inputs=[country_filter, city_filter, language_filter, page_state],
outputs=[table_html, page_state, gr.Number(visible=False)]
)
next_btn.click(
fn=lambda p, c, ci, l: min(get_total_pages(c, ci, l), p + 1),
inputs=[page_state, country_filter, city_filter, language_filter],
outputs=[page_state]
).then(
fn=get_filtered_page,
inputs=[country_filter, city_filter, language_filter, page_state],
outputs=[table_html, page_state, gr.Number(visible=False)]
)
with gr.Accordion("π Admin Tools", open=False):
del_btn = gr.Button("Delete Profile")
admin_discord = gr.Text(label="Discord Username")
admin_code = gr.Text(label="Admin Code", type="password")
del_status = gr.Textbox(label="Status", interactive=False)
del_btn.click(
fn=delete_by_discord,
inputs=[admin_discord, admin_code],
outputs=[del_status]
).then(
fn=lambda: 1,
outputs=[page_state]
).then(
fn=filter_by_fields,
inputs=[country_filter, city_filter, language_filter, gr.State(1)],
outputs=[table_html, page_state, gr.Number(visible=False)]
)
export_code = gr.Text(label="Admin Code", type="password")
download_btn = gr.Button("Generate and Download CSV")
download_file = gr.File(label="CSV Export", interactive=False)
download_btn.click(download_csv, inputs=[export_code], outputs=[download_file])
return demo
demo = interface()
demo.launch()
|