File size: 8,368 Bytes
10c89d7
 
 
 
ea2400d
 
10c89d7
4a79184
 
 
 
 
2b22ecd
4a79184
10c89d7
 
 
 
4a79184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea2400d
4a79184
ea2400d
4a79184
 
2b22ecd
4a79184
 
 
 
 
 
ea2400d
4a79184
10c89d7
 
 
4a79184
 
10c89d7
 
4a79184
 
 
 
10c89d7
 
 
 
4a79184
 
 
10c89d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a79184
 
 
10c89d7
4a79184
 
 
 
 
 
 
 
 
 
10c89d7
4a79184
 
10c89d7
4a79184
2b22ecd
 
 
10c89d7
4a79184
 
 
2b22ecd
4a79184
2b22ecd
 
4a79184
2b22ecd
4a79184
2b22ecd
4a79184
2b22ecd
 
4a79184
 
 
 
2b22ecd
4a79184
01b3760
 
 
 
 
 
 
 
021666f
01b3760
 
 
 
 
021666f
 
 
2b22ecd
 
4a79184
e2a5983
4a79184
10c89d7
 
 
 
 
 
4a79184
10c89d7
 
4a79184
10c89d7
 
4a79184
 
 
10c89d7
 
4a79184
10c89d7
 
 
4a79184
 
 
 
 
10c89d7
 
4a79184
10c89d7
 
4a79184
 
 
 
10c89d7
 
4a79184
 
 
10c89d7
 
4a79184
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
import gradio as gr
import json
import pandas as pd
import os
import shutil
import datetime

# Paths
DATA_DIR = "data"
DATA_FILE = os.path.join(DATA_DIR, "teamup_data.json")
BACKUP_DIR = os.path.join(DATA_DIR, "backup")
os.makedirs(DATA_DIR, exist_ok=True)

# Init data file
if not os.path.exists(DATA_FILE) or os.path.getsize(DATA_FILE) == 0:
    with open(DATA_FILE, "w") as f:
        json.dump([], f)

# Country list
ALL_COUNTRIES = sorted(list(set([
    "United States of America", "United Kingdom", "India", "France", "Germany", "Canada", "Australia", "Japan", "Brazil", "Mexico",
    # Add or reduce to most relevant countries only for dropdown
] + [  # Fallback: full list
    "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Argentina", "Armenia", "Austria", "Azerbaijan",
    "Bangladesh", "Belgium", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Bulgaria", "Cambodia",
    "Chile", "China", "Colombia", "Croatia", "Cuba", "Czech Republic", "Denmark", "Dominican Republic", "Ecuador",
    "Egypt", "Estonia", "Ethiopia", "Finland", "Greece", "Hungary", "Iceland", "Indonesia", "Iran", "Iraq", "Ireland",
    "Israel", "Italy", "Jordan", "Kenya", "Kuwait", "Latvia", "Lithuania", "Luxembourg", "Malaysia", "Malta", "Morocco",
    "Nepal", "Netherlands", "New Zealand", "Nigeria", "Norway", "Pakistan", "Peru", "Philippines", "Poland", "Portugal",
    "Qatar", "Romania", "Russia", "Saudi Arabia", "Serbia", "Singapore", "Slovakia", "Slovenia", "South Africa", "South Korea",
    "Spain", "Sri Lanka", "Sweden", "Switzerland", "Thailand", "Tunisia", "Turkey", "Ukraine", "United Arab Emirates", "Vietnam",
    "Zambia", "Zimbabwe"
])))

# Backup
def backup_data():
    os.makedirs(BACKUP_DIR, exist_ok=True)
    timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
    backup_file = os.path.join(BACKUP_DIR, f'teamup_data_backup_{timestamp}.json')
    shutil.copy(DATA_FILE, backup_file)

# Safe save
def atomic_save(data, path):
    tmp_path = path + ".tmp"
    with open(tmp_path, "w") as f:
        json.dump(data, f, indent=2)
    os.replace(tmp_path, path)

# Profile submission
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."

    if not languages or not isinstance(languages, list):
        return "❌ Please select at least one language."

    # Normalize input
    city = city.strip().title()
    country = country.strip().title()
    discord = discord.strip()

    with open(DATA_FILE, "r") as f:
        data = json.load(f)

    for entry in data:
        if entry["Discord"].lower() == discord.lower():
            entry.update({
                "Name": name,
                "City": city,
                "Country": country,
                "Address": address,
                "Looking for Team": looking,
                "Onlinecheck": onlinecheck,
                "Languages": languages,
                "Laptop": laptop,
                "Robot": robot,
                "Skills": skills,
                "Describe3": describe3,
                "Experience": experience,
                "Project Idea": idea
            })
            break
    else:
        data.append({
            "Name": name,
            "Discord": discord,
            "City": city,
            "Country": country,
            "Address": address,
            "Looking for Team": looking,
            "Onlinecheck": onlinecheck,
            "Languages": languages,
            "Laptop": laptop,
            "Robot": robot,
            "Skills": skills,
            "Describe3": describe3,
            "Experience": experience,
            "Project Idea": idea
        })

    try:
        atomic_save(data, DATA_FILE)
        backup_data()
        return "βœ… Profile saved!"
    except Exception as e:
        return f"❌ Failed to save: {e}"

# City dropdown update
def update_city_filter(country):
    with open(DATA_FILE, "r") as f:
        data = json.load(f)
    df = pd.DataFrame(data)

    if country != "All":
        df = df[df["Country"].str.title() == country.title()]

    cities = sorted(set(df["City"].dropna().unique()))
    return gr.update(choices=["All"] + cities, value="All")

# Filter participants
def filter_by_fields(selected_country, selected_city, selected_language):
    with open(DATA_FILE, "r") as f:
        data = json.load(f)

    df = pd.DataFrame(data)
    if df.empty:
        return "<p>No data available.</p>"

    df["Languages"] = df["Languages"].apply(lambda x: ", ".join(x) if isinstance(x, list) else str(x))

    if selected_country != "All":
        df = df[df["Country"].str.title() == selected_country.title()]
    if selected_city != "All":
        df = df[df["City"].str.title() == selected_city.title()]
    if selected_language != "All":
        df = df[df["Languages"].str.contains(selected_language)]

    if "Address" in df.columns:
        df.drop(columns=["Address"], inplace=True)

    if df.empty:
        return "<p>No participants match your filters.</p>"

    html = "<table style='width:100%; border-collapse: collapse;'>"
# Header row
html += "<tr>"
for col in df.columns:
    html += f"<th style='border: 1px solid #ccc; padding: 6px;'>{col}</th>"
html += "</tr>"

# Data rows
for _, row in df.iterrows():
    html += "<tr>"
    for col in df.columns:
        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>"


    return html

# Gradio Interface
with gr.Blocks(css=".gr-dropdown { max-height: 100px; overflow-y: auto; font-size: 12px; }") as demo:
    gr.Markdown("# 🌍 LeRobot Hackathon: Global Team-Up Dashboard")

    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)
            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=["English", "French", "Spanish", "German", "Portuguese", "Chinese", "Arabic", "Hindi"], 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("🎯 Find teammates by country, city, or language.")
            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", "English", "French", "Spanish", "German", "Portuguese", "Chinese", "Arabic", "Hindi"], value="All")
            table_html = gr.HTML()

    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=filter_by_fields,
        inputs=[country_filter, city_filter, language_filter],
        outputs=[table_html]
    )

    country_filter.change(fn=update_city_filter, inputs=[country_filter], outputs=[city_filter])
    for dropdown in [country_filter, city_filter, language_filter]:
        dropdown.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=[table_html])

demo.launch()