File size: 10,606 Bytes
bde0d82
 
 
 
 
050478b
 
113448e
 
bde0d82
 
 
 
 
 
 
9dd4129
 
 
bde0d82
9dd4129
 
 
 
998d897
746ca27
 
 
 
bde0d82
 
 
 
 
 
 
 
 
 
4c66b5c
9dd4129
c98cd9c
bde0d82
 
 
c98cd9c
bde0d82
c98cd9c
bde0d82
 
 
 
 
 
 
 
 
4c66b5c
9dd4129
c98cd9c
bde0d82
 
 
d3830dd
bde0d82
c98cd9c
bde0d82
 
ce102fb
92c38d9
 
 
 
 
 
 
 
bdf6f17
9dd4129
c1627b4
bde0d82
 
 
 
643c246
 
 
1f0e123
6e00bf0
1f0e123
01a3a08
6e00bf0
c1627b4
2b50226
c1627b4
 
bde0d82
 
 
c1627b4
a3d372f
806a8cd
 
 
a3d372f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4b56c95
3b691bf
 
a3d372f
 
 
 
 
6e00bf0
a3d372f
6e00bf0
 
 
 
 
 
 
 
 
 
 
d991080
bde0d82
01a3a08
a3d372f
bde0d82
 
 
73a0a9a
c1627b4
bde0d82
c1627b4
 
bde0d82
c1627b4
bde0d82
 
 
c1627b4
 
 
 
 
 
bde0d82
73a0a9a
bde0d82
 
 
 
 
 
 
 
 
 
 
c141933
 
bde0d82
 
 
 
f16a559
 
 
c98cd9c
4c66b5c
f16a559
bde0d82
3348d6a
bde0d82
f16a559
 
db2b918
bde0d82
c98cd9c
bde0d82
 
 
e7771f9
6362ec6
 
 
6e00bf0
bde0d82
 
 
4c66b5c
bde0d82
 
 
6e00bf0
aa60a10
 
6362ec6
 
 
 
 
 
 
 
 
 
 
 
 
c1627b4
6362ec6
 
 
c1627b4
 
aa60a10
6362ec6
980e031
 
 
 
 
 
 
 
 
 
fb1e657
e7771f9
8dd353a
 
 
 
 
 
 
 
 
 
e7771f9
c1627b4
bde0d82
91c0b78
bde0d82
 
 
 
 
 
980e031
 
 
 
 
 
 
bde0d82
fb1e657
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
import gradio as gr
import json
import pandas as pd
import os

DATA_FILE = os.path.join("data", "teamup_data.json")

ADMIN_CODE = os.getenv("ADMIN_CODE", "")


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

def submit_profile(name, discord, city, country, address, looking, onlinecheck, languages, laptop, robot, skills, describe3, experience, idea):
    print("🟒 Submit button clicked.")
    print(f"Incoming: {discord=}, {city=}, {country=}, {languages=}, {laptop=}, {robot=}")

    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) or len(languages) == 0:
        return "❌ Please select at least one language."

    # Ensure country is stored as a string (in case form allows lists)
    if isinstance(country, list):
        country = country[0] if country else ""

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

    for d in data:
        if d["Discord"].lower() == discord.lower():
            d.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:
        with open(DATA_FILE, "w") as f:
            json.dump(data, f, indent=2)
        print(f"βœ… Successfully wrote {len(data)} profiles to {DATA_FILE}")
    except Exception as e:
        print(f"❌ Failed to write to {DATA_FILE}: {e}")
        return "❌ Error saving your profile. Please try again."

    return "βœ… Profile saved!"


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)

    # Convert list values to readable strings
    df["Languages"] = df["Languages"].apply(lambda langs: ", ".join(langs) if isinstance(langs, list) else langs)

    if df.empty or "Country" not in df.columns or "Languages" not in df.columns:
        return "<p>No participants found.</p>"

    if selected_country != "All":
        df = df[df["Country"] == selected_country]

    if selected_city != "All":
        df = df[df["City"] == selected_city]
    
    if selected_language != "All":
        df = df[df["Languages"].apply(lambda langs: selected_language in langs)]

    
    # Hide address
    if "Address" in df.columns:
        df = df.drop(columns=["Address"])

    # Rename column headers for display only
    display_names = {
        "Discord": "Discord",
        "Name": "Name",
        "City": "City",
        "Country": "Country",
        "Looking for Team": "Looking for Team",
        "Onlinecheck": "How?",
        "Languages": "Languages",
        "Laptop": "Laptop",
        "Robot": "Robot",
        "Skills": "Skills",
        "Describe3": "Describe",
        "Experience": "Experience",
        "Project Idea": "Project Idea"
    }

    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;'>"

    # Header row
    html += "<tr>" + "".join(
        f"<th style='border: 1px solid #ccc; padding: 6px;'>{display_names.get(col, col)}</th>"
        for col in df.columns
    ) + "</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>"

    html += "</table>"
    return html




def update_dropdowns():
    with open(DATA_FILE, "r") as f:
        data = json.load(f)
    if not data:
        return ["All"], ["All"], ["All"]
    df = pd.DataFrame(data)
    if "Country" not in df.columns or "Languages" not in df.columns or "City" not in df.columns:
        return ["All"], ["All"], ["All"]
    country_choices = sorted(list(df["Country"].dropna().unique()))
    city_choices = sorted(list(df["City"].dropna().unique()))
    language_set = set()
    for lang_list in df["Languages"].dropna():
        language_set.update(lang_list)
    return (
        ["All"] + country_choices,
        ["All"] + sorted(language_set),
        ["All"] + city_choices
    )



def delete_by_discord(discord, code):
    if code != ADMIN_CODE:
        return "❌ Invalid admin code."
    with open(DATA_FILE, "r") as f:
        data = json.load(f)
    new_data = [d for d in data if d["Discord"].lower() != discord.lower()]
    with open(DATA_FILE, "w") as f:
        json.dump(new_data, f, indent=2)
    return f"πŸ—‘οΈ Deleted user with Discord: {discord}"

with gr.Blocks() as demo:
    gr.Markdown("# 🌍 LeRobot Worldwide Hackathon - Team-Up Dashboard")
    gr.Markdown("Submit or update your profile. Required fields marked with *. Find matching teammates and contact them on Discord.")

    with gr.Row():
        with gr.Column():
            name = gr.Text(label="Name")
            discord = gr.Text(label="πŸ‘€ Discord Username *")
            city = gr.Text(label="πŸ“ City *")
            country = gr.Text(label="🌍 Country *")
            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="🧠 Your 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 Profile βœ…")
            status = gr.Textbox(label="", interactive=False)

        with gr.Column():
            gr.Markdown("🎯 Choose your preferences to find your teammates (country, city or language)")
            country_filter = gr.Dropdown(label="Filter by Country", choices=["All"], value="All", allow_custom_value=False)
            city_filter = gr.Dropdown(label="Filter by City", choices=["All"], value="All", allow_custom_value=False)
            language_filter = gr.Dropdown(label="Filter by Language", choices=["All"], value="All", allow_custom_value=False)
            table_html = gr.HTML(label="Matching Participants")

    submit_btn.click(
        submit_profile,
        inputs=[name, discord, city, country, address, looking, onlinecheck, languages, laptop, robot, skills, describe3, experience, idea],
        outputs=[status]
    )



def update_dropdown_choices():
    with open(DATA_FILE, "r") as f:
        data = json.load(f)
    df = pd.DataFrame(data)

    country_choices = sorted(df["Country"].dropna().unique()) if "Country" in df else []
    city_choices = sorted(df["City"].dropna().unique()) if "City" in df else []
    language_set = set()
    if "Languages" in df:
        for lang_list in df["Languages"].dropna():
            if isinstance(lang_list, list):
                language_set.update(lang_list)
            elif isinstance(lang_list, str):
                language_set.update(lang_list.split(", "))
    return (
        gr.update(choices=["All"] + list(country_choices), value="All"),
        gr.update(choices=["All"] + list(city_choices), value="All"),
        gr.update(choices=["All"] + sorted(language_set), value="All")
    )



def download_csv(code):
    if code != ADMIN_CODE:
        raise gr.Error("❌ Invalid admin code.")
    with open(DATA_FILE, "r") as f:
        data = json.load(f)
    df = pd.DataFrame(data)
    csv_path = os.path.join("data", "teamup_export.csv")
    df.to_csv(csv_path, index=False)
    return csv_path

with demo:
    demo.load(
        fn=lambda: filter_by_fields("All", "All", "All"),
        inputs=[],
        outputs=[table_html]
    )
    
    demo.load(fn=update_dropdown_choices, outputs=[country_filter, city_filter, language_filter])

    country_filter.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=table_html)
    city_filter.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=table_html)
    language_filter.change(fn=filter_by_fields, inputs=[country_filter, city_filter, language_filter], outputs=table_html)



    gr.Markdown("---\n### πŸ›‘οΈ Admin Panel (delete by Discord)")
    admin_discord = gr.Text(label="Discord Username")
    admin_code = gr.Text(label="Admin Code", type="password")
    del_btn = gr.Button("Delete Profile")
    del_status = gr.Textbox(label="Status", interactive=False)
    del_btn.click(delete_by_discord, inputs=[admin_discord, admin_code], outputs=del_status)

    # πŸ” CSV Download Section (admin-only)
    gr.Markdown("---\n### πŸ“₯ Admin Export CSV")
    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(fn=download_csv, inputs=[export_code], outputs=[download_file])

demo.launch()