Spaces:
Runtime error
Runtime error
Commit
·
f8d385e
1
Parent(s):
5def33e
combine participant info
Browse files- app.py +233 -174
- leaderboard_personal.csv +54 -39
- requirements.txt +1 -0
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import os
|
2 |
import time
|
3 |
from collections import defaultdict
|
@@ -11,6 +12,20 @@ from fastapi import FastAPI
|
|
11 |
|
12 |
load_dotenv()
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
try:
|
15 |
client = rg.Argilla(
|
16 |
api_url=os.getenv("ARGILLA_API_URL", ""),
|
@@ -20,14 +35,7 @@ except Exception as e:
|
|
20 |
print(f"Error initializing Argilla client: {e}")
|
21 |
client = None
|
22 |
|
23 |
-
|
24 |
-
DATA_DIR = "data"
|
25 |
-
INCLUDE_CSV = os.path.join(DATA_DIR, "include.csv")
|
26 |
-
STEREOTYPES_CSV = os.path.join(DATA_DIR, "stereotypes.csv")
|
27 |
-
ARENA_JSON = os.path.join(DATA_DIR, "arena.json")
|
28 |
-
PARTICIPANTS_CSV = os.path.join(DATA_DIR, "participants.csv")
|
29 |
-
LEADERBOARD_PERSONAL_CSV = os.path.join(".", "leaderboard_personal.csv")
|
30 |
-
|
31 |
countries = {
|
32 |
"Argentina": {"iso": "ARG", "emoji": "🇦🇷"},
|
33 |
"Bolivia": {"iso": "BOL", "emoji": "🇧🇴"},
|
@@ -52,95 +60,104 @@ countries = {
|
|
52 |
}
|
53 |
|
54 |
|
|
|
55 |
def get_user_mapping():
|
56 |
-
"""
|
57 |
-
|
58 |
-
|
59 |
-
"""
|
60 |
-
email_to_discord = {}
|
61 |
-
hf_username_to_discord = {}
|
62 |
|
63 |
try:
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
83 |
except Exception as e:
|
84 |
print(f"Error loading {PARTICIPANTS_CSV}: {e}")
|
85 |
-
|
86 |
-
return email_to_discord, hf_username_to_discord
|
87 |
|
88 |
|
89 |
def get_discord_username(identifier):
|
90 |
-
"""
|
91 |
-
|
92 |
-
"""
|
93 |
-
email_to_discord, hf_username_to_discord = get_user_mapping()
|
94 |
|
95 |
-
# Try to find discord username by email first
|
96 |
if "@" in identifier:
|
97 |
-
|
98 |
-
if discord_username:
|
99 |
-
return discord_username
|
100 |
|
101 |
-
|
102 |
-
discord_username = hf_username_to_discord.get(identifier.lower())
|
103 |
-
if discord_username:
|
104 |
-
return discord_username
|
105 |
|
106 |
-
# Fallback: use identifier as username
|
107 |
-
return identifier.split("@")[0] if "@" in identifier else identifier
|
108 |
|
|
|
|
|
|
|
|
|
109 |
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
-
for country in countries.keys():
|
114 |
-
iso = countries[country]["iso"]
|
115 |
-
emoji = countries[country]["emoji"]
|
116 |
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
try:
|
120 |
-
print(f"Processing dataset: {dataset_name}")
|
121 |
dataset = client.datasets(dataset_name)
|
122 |
records = list(dataset.records(with_responses=True))
|
123 |
|
124 |
-
|
125 |
user_mapping = {}
|
126 |
|
127 |
for record in records:
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
user_id
|
133 |
-
dataset_contributions[user_id] += 1
|
134 |
|
135 |
if user_id not in user_mapping:
|
136 |
try:
|
137 |
user = client.users(id=user_id)
|
138 |
user_mapping[user_id] = user.username
|
139 |
-
except
|
140 |
-
print(f"Error getting username for {user_id}: {e}")
|
141 |
user_mapping[user_id] = f"User-{user_id[:8]}"
|
142 |
|
143 |
-
for user_id, count in
|
144 |
hf_username = user_mapping.get(user_id, f"User-{user_id[:8]}")
|
145 |
username = get_discord_username(hf_username)
|
146 |
data.append(
|
@@ -148,108 +165,118 @@ def get_blend_es_data():
|
|
148 |
)
|
149 |
|
150 |
except Exception as e:
|
151 |
-
print(f"Error processing
|
152 |
|
153 |
return data
|
154 |
|
155 |
|
156 |
def get_include_data():
|
157 |
-
data
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
username_column = "Nombre en Discord / username"
|
162 |
-
questions_column = "Total preguntas hackathon"
|
163 |
-
if (
|
164 |
-
username_column in include_df.columns
|
165 |
-
and questions_column in include_df.columns
|
166 |
-
):
|
167 |
-
discord_users = defaultdict(int)
|
168 |
-
for _, row in include_df.iterrows():
|
169 |
-
username = row[username_column][1:] # Remove the @ symbol
|
170 |
-
questions = row[questions_column]
|
171 |
-
if pd.notna(username) and pd.notna(questions):
|
172 |
-
discord_users[username.lower()] += int(questions)
|
173 |
-
|
174 |
-
for username, count in discord_users.items():
|
175 |
-
data.append(
|
176 |
-
{"source": "include", "username": username, "count": count}
|
177 |
-
)
|
178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
except Exception as e:
|
180 |
-
print(f"Error loading
|
181 |
-
|
182 |
-
return data
|
183 |
|
184 |
|
185 |
def get_estereotipos_data():
|
186 |
-
data
|
|
|
|
|
|
|
187 |
|
188 |
try:
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
|
|
|
|
|
|
|
|
204 |
except Exception as e:
|
205 |
-
print(f"Error loading
|
206 |
-
|
207 |
-
return data
|
208 |
|
209 |
|
210 |
def get_arena_data():
|
211 |
-
data
|
|
|
|
|
|
|
212 |
|
213 |
try:
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
mail_counts[mail.lower()] += 1
|
228 |
-
|
229 |
-
for mail, count in mail_counts.items():
|
230 |
-
username = get_discord_username(mail)
|
231 |
-
data.append({"source": "arena", "username": username, "count": count})
|
232 |
except Exception as e:
|
233 |
-
print(f"Error loading
|
234 |
-
|
235 |
-
return data
|
236 |
-
|
237 |
-
|
238 |
-
@lru_cache(maxsize=32)
|
239 |
-
def get_user_contributions_cached(cache_buster: int):
|
240 |
-
return consolidate_all_data()
|
241 |
|
242 |
|
243 |
def consolidate_all_data():
|
244 |
-
|
245 |
-
|
246 |
-
all_data
|
247 |
-
|
248 |
-
|
|
|
|
|
|
|
249 |
|
|
|
|
|
|
|
|
|
250 |
user_contributions = defaultdict(
|
251 |
lambda: {
|
252 |
"username": "",
|
|
|
|
|
|
|
|
|
253 |
"blend_es": 0,
|
254 |
"include": 0,
|
255 |
"estereotipos": 0,
|
@@ -261,11 +288,20 @@ def consolidate_all_data():
|
|
261 |
source = item["source"]
|
262 |
username = item["username"]
|
263 |
count = item["count"]
|
264 |
-
|
265 |
user_key = username.lower()
|
266 |
|
267 |
if not user_contributions[user_key]["username"]:
|
268 |
user_contributions[user_key]["username"] = username
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
|
270 |
if source == "blend-es":
|
271 |
user_contributions[user_key]["blend_es"] += count
|
@@ -276,55 +312,79 @@ def consolidate_all_data():
|
|
276 |
elif source == "arena":
|
277 |
user_contributions[user_key]["arena"] += count
|
278 |
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
app = FastAPI()
|
302 |
|
|
|
303 |
last_update_time = 0
|
304 |
cached_data = None
|
305 |
|
306 |
|
307 |
def create_leaderboard_ui():
|
|
|
308 |
global cached_data, last_update_time
|
309 |
current_time = time.time()
|
310 |
|
311 |
if cached_data is not None and current_time - last_update_time < 300:
|
312 |
df = cached_data
|
313 |
else:
|
314 |
-
|
315 |
-
df = get_user_contributions_cached(cache_buster)
|
316 |
cached_data = df
|
317 |
last_update_time = current_time
|
318 |
|
319 |
if not df.empty:
|
320 |
df = df.reset_index(drop=True)
|
321 |
df.index = df.index + 1
|
322 |
-
df = df.rename_axis("Rank")
|
323 |
-
df = df.reset_index()
|
324 |
|
325 |
df_html = df.to_html(classes="leaderboard-table", border=0, index=False)
|
326 |
|
327 |
-
|
328 |
<div style="margin: 20px 0;">
|
329 |
<p>Última Actualización: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(last_update_time))}</p>
|
330 |
<style>
|
@@ -390,22 +450,21 @@ def create_leaderboard_ui():
|
|
390 |
{df_html}
|
391 |
</div>
|
392 |
"""
|
393 |
-
return styled_html
|
394 |
|
395 |
|
396 |
def refresh_data():
|
|
|
397 |
global cached_data, last_update_time
|
398 |
cached_data = None
|
399 |
last_update_time = 0
|
400 |
return create_leaderboard_ui()
|
401 |
|
402 |
|
|
|
403 |
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
404 |
with gr.Column(scale=1):
|
405 |
-
gr.Markdown("
|
406 |
-
|
407 |
leaderboard_html = gr.HTML(create_leaderboard_ui)
|
408 |
-
|
409 |
refresh_btn = gr.Button("🔄 Actualizar Datos", variant="primary")
|
410 |
refresh_btn.click(fn=refresh_data, outputs=leaderboard_html)
|
411 |
|
|
|
1 |
+
import json
|
2 |
import os
|
3 |
import time
|
4 |
from collections import defaultdict
|
|
|
12 |
|
13 |
load_dotenv()
|
14 |
|
15 |
+
# Constants
|
16 |
+
DATA_DIR = "data"
|
17 |
+
PARTICIPANTS_CSV = os.path.join(DATA_DIR, "participants.csv")
|
18 |
+
LEADERBOARD_PERSONAL_CSV = "leaderboard_personal.csv"
|
19 |
+
|
20 |
+
# Column mappings for participants info
|
21 |
+
COLUMN_MAP = {
|
22 |
+
"gmail": "Dirección de correo electrónico",
|
23 |
+
"discord": "¿Cuál es tu nombre en Discord?",
|
24 |
+
"hf_username": "¿Cuál es tu nombre en el Hub de Hugging Face?",
|
25 |
+
"contact_email": "Email de contacto",
|
26 |
+
}
|
27 |
+
|
28 |
+
# Initialize Argilla client
|
29 |
try:
|
30 |
client = rg.Argilla(
|
31 |
api_url=os.getenv("ARGILLA_API_URL", ""),
|
|
|
35 |
print(f"Error initializing Argilla client: {e}")
|
36 |
client = None
|
37 |
|
38 |
+
# Countries data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
countries = {
|
40 |
"Argentina": {"iso": "ARG", "emoji": "🇦🇷"},
|
41 |
"Bolivia": {"iso": "BOL", "emoji": "🇧🇴"},
|
|
|
60 |
}
|
61 |
|
62 |
|
63 |
+
@lru_cache(maxsize=1)
|
64 |
def get_user_mapping():
|
65 |
+
"""Get cached mapping of emails and hf_usernames to discord usernames."""
|
66 |
+
if not os.path.exists(PARTICIPANTS_CSV):
|
67 |
+
return {}, {}
|
|
|
|
|
|
|
68 |
|
69 |
try:
|
70 |
+
df = pd.read_csv(PARTICIPANTS_CSV)
|
71 |
+
email_to_discord = {}
|
72 |
+
hf_to_discord = {}
|
73 |
+
|
74 |
+
for _, row in df.iterrows():
|
75 |
+
discord = row.get(COLUMN_MAP["discord"], "")
|
76 |
+
if pd.notna(discord) and discord != "NA":
|
77 |
+
discord_lower = discord.lower()
|
78 |
+
|
79 |
+
# Map email to discord
|
80 |
+
gmail = row.get(COLUMN_MAP["gmail"], "")
|
81 |
+
if pd.notna(gmail):
|
82 |
+
email_to_discord[gmail.lower()] = discord_lower
|
83 |
+
|
84 |
+
# Map hf_username to discord
|
85 |
+
hf_username = row.get(COLUMN_MAP["hf_username"], "")
|
86 |
+
if pd.notna(hf_username):
|
87 |
+
hf_to_discord[hf_username.lower()] = discord_lower
|
88 |
+
|
89 |
+
return email_to_discord, hf_to_discord
|
90 |
except Exception as e:
|
91 |
print(f"Error loading {PARTICIPANTS_CSV}: {e}")
|
92 |
+
return {}, {}
|
|
|
93 |
|
94 |
|
95 |
def get_discord_username(identifier):
|
96 |
+
"""Get discord username from email or hf_username."""
|
97 |
+
email_to_discord, hf_to_discord = get_user_mapping()
|
|
|
|
|
98 |
|
|
|
99 |
if "@" in identifier:
|
100 |
+
return email_to_discord.get(identifier.lower(), identifier.split("@")[0])
|
|
|
|
|
101 |
|
102 |
+
return hf_to_discord.get(identifier.lower(), identifier)
|
|
|
|
|
|
|
103 |
|
|
|
|
|
104 |
|
105 |
+
def get_participant_info():
|
106 |
+
"""Get participant information from CSV."""
|
107 |
+
if not os.path.exists(PARTICIPANTS_CSV):
|
108 |
+
return {}
|
109 |
|
110 |
+
try:
|
111 |
+
df = pd.read_csv(PARTICIPANTS_CSV)
|
112 |
+
participant_info = {}
|
113 |
+
|
114 |
+
for _, row in df.iterrows():
|
115 |
+
discord_username = row.get(COLUMN_MAP["discord"], "")
|
116 |
+
if pd.notna(discord_username) and discord_username != "NA":
|
117 |
+
participant_info[discord_username.lower()] = {
|
118 |
+
"gmail": row.get(COLUMN_MAP["gmail"], ""),
|
119 |
+
"discord_username": discord_username,
|
120 |
+
"hf_username": row.get(COLUMN_MAP["hf_username"], ""),
|
121 |
+
"email": row.get(COLUMN_MAP["contact_email"], ""),
|
122 |
+
}
|
123 |
+
|
124 |
+
return participant_info
|
125 |
+
except Exception as e:
|
126 |
+
print(f"Error loading participant info: {e}")
|
127 |
+
return {}
|
128 |
|
|
|
|
|
|
|
129 |
|
130 |
+
def get_blend_es_data():
|
131 |
+
"""Get blend-es data from Argilla."""
|
132 |
+
if not client:
|
133 |
+
return []
|
134 |
+
|
135 |
+
data = []
|
136 |
+
for country, info in countries.items():
|
137 |
+
dataset_name = f"{info['emoji']} {country} - {info['iso']} - Responder"
|
138 |
|
139 |
try:
|
|
|
140 |
dataset = client.datasets(dataset_name)
|
141 |
records = list(dataset.records(with_responses=True))
|
142 |
|
143 |
+
user_counts = defaultdict(int)
|
144 |
user_mapping = {}
|
145 |
|
146 |
for record in records:
|
147 |
+
if "answer_1" in record.responses:
|
148 |
+
for answer in record.responses["answer_1"]:
|
149 |
+
if answer.user_id:
|
150 |
+
user_id = answer.user_id
|
151 |
+
user_counts[user_id] += 1
|
|
|
152 |
|
153 |
if user_id not in user_mapping:
|
154 |
try:
|
155 |
user = client.users(id=user_id)
|
156 |
user_mapping[user_id] = user.username
|
157 |
+
except:
|
|
|
158 |
user_mapping[user_id] = f"User-{user_id[:8]}"
|
159 |
|
160 |
+
for user_id, count in user_counts.items():
|
161 |
hf_username = user_mapping.get(user_id, f"User-{user_id[:8]}")
|
162 |
username = get_discord_username(hf_username)
|
163 |
data.append(
|
|
|
165 |
)
|
166 |
|
167 |
except Exception as e:
|
168 |
+
print(f"Error processing {dataset_name}: {e}")
|
169 |
|
170 |
return data
|
171 |
|
172 |
|
173 |
def get_include_data():
|
174 |
+
"""Get include data from CSV."""
|
175 |
+
csv_path = os.path.join(DATA_DIR, "include.csv")
|
176 |
+
if not os.path.exists(csv_path):
|
177 |
+
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
+
try:
|
180 |
+
df = pd.read_csv(csv_path)
|
181 |
+
username_col = "Nombre en Discord / username"
|
182 |
+
questions_col = "Total preguntas hackathon"
|
183 |
+
|
184 |
+
if username_col not in df.columns or questions_col not in df.columns:
|
185 |
+
return []
|
186 |
+
|
187 |
+
user_counts = defaultdict(int)
|
188 |
+
for _, row in df.iterrows():
|
189 |
+
username = row[username_col][1:] if pd.notna(row[username_col]) else ""
|
190 |
+
questions = row[questions_col] if pd.notna(row[questions_col]) else 0
|
191 |
+
if username and questions:
|
192 |
+
user_counts[username.lower()] += int(questions)
|
193 |
+
|
194 |
+
return [
|
195 |
+
{"source": "include", "username": username, "count": count}
|
196 |
+
for username, count in user_counts.items()
|
197 |
+
]
|
198 |
except Exception as e:
|
199 |
+
print(f"Error loading include data: {e}")
|
200 |
+
return []
|
|
|
201 |
|
202 |
|
203 |
def get_estereotipos_data():
|
204 |
+
"""Get estereotipos data from CSV."""
|
205 |
+
csv_path = os.path.join(DATA_DIR, "stereotypes.csv")
|
206 |
+
if not os.path.exists(csv_path):
|
207 |
+
return []
|
208 |
|
209 |
try:
|
210 |
+
df = pd.read_csv(csv_path)
|
211 |
+
if "token_id" not in df.columns or "count" not in df.columns:
|
212 |
+
return []
|
213 |
+
|
214 |
+
user_counts = defaultdict(int)
|
215 |
+
for _, row in df.iterrows():
|
216 |
+
mail = row.get("token_id", "")
|
217 |
+
count = row.get("count", 0)
|
218 |
+
if pd.notna(mail) and pd.notna(count):
|
219 |
+
user_counts[mail.lower()] += int(count)
|
220 |
+
|
221 |
+
return [
|
222 |
+
{
|
223 |
+
"source": "include",
|
224 |
+
"username": get_discord_username(mail),
|
225 |
+
"count": count,
|
226 |
+
}
|
227 |
+
for mail, count in user_counts.items()
|
228 |
+
]
|
229 |
except Exception as e:
|
230 |
+
print(f"Error loading estereotipos data: {e}")
|
231 |
+
return []
|
|
|
232 |
|
233 |
|
234 |
def get_arena_data():
|
235 |
+
"""Get arena data from JSON."""
|
236 |
+
json_path = os.path.join(DATA_DIR, "arena.json")
|
237 |
+
if not os.path.exists(json_path):
|
238 |
+
return []
|
239 |
|
240 |
try:
|
241 |
+
with open(json_path, "r", encoding="utf-8") as f:
|
242 |
+
arena_data = json.load(f)
|
243 |
+
|
244 |
+
user_counts = defaultdict(int)
|
245 |
+
for conversations in arena_data.values():
|
246 |
+
for conversation in conversations:
|
247 |
+
if username := conversation.get("username"):
|
248 |
+
user_counts[username.lower()] += 1
|
249 |
+
|
250 |
+
return [
|
251 |
+
{"source": "arena", "username": get_discord_username(mail), "count": count}
|
252 |
+
for mail, count in user_counts.items()
|
253 |
+
]
|
|
|
|
|
|
|
|
|
|
|
254 |
except Exception as e:
|
255 |
+
print(f"Error loading arena data: {e}")
|
256 |
+
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
|
258 |
|
259 |
def consolidate_all_data():
|
260 |
+
"""Consolidate all data sources and create leaderboard."""
|
261 |
+
# Collect all data
|
262 |
+
all_data = (
|
263 |
+
get_blend_es_data()
|
264 |
+
+ get_include_data()
|
265 |
+
+ get_estereotipos_data()
|
266 |
+
+ get_arena_data()
|
267 |
+
)
|
268 |
|
269 |
+
# Get participant info
|
270 |
+
participant_info = get_participant_info()
|
271 |
+
|
272 |
+
# Aggregate user contributions
|
273 |
user_contributions = defaultdict(
|
274 |
lambda: {
|
275 |
"username": "",
|
276 |
+
"gmail": "",
|
277 |
+
"discord_username": "",
|
278 |
+
"hf_username": "",
|
279 |
+
"email": "",
|
280 |
"blend_es": 0,
|
281 |
"include": 0,
|
282 |
"estereotipos": 0,
|
|
|
288 |
source = item["source"]
|
289 |
username = item["username"]
|
290 |
count = item["count"]
|
|
|
291 |
user_key = username.lower()
|
292 |
|
293 |
if not user_contributions[user_key]["username"]:
|
294 |
user_contributions[user_key]["username"] = username
|
295 |
+
if username.lower() in participant_info:
|
296 |
+
info = participant_info[username.lower()]
|
297 |
+
user_contributions[user_key].update(
|
298 |
+
{
|
299 |
+
"gmail": info["gmail"],
|
300 |
+
"discord_username": info["discord_username"],
|
301 |
+
"hf_username": info["hf_username"],
|
302 |
+
"email": info["email"],
|
303 |
+
}
|
304 |
+
)
|
305 |
|
306 |
if source == "blend-es":
|
307 |
user_contributions[user_key]["blend_es"] += count
|
|
|
312 |
elif source == "arena":
|
313 |
user_contributions[user_key]["arena"] += count
|
314 |
|
315 |
+
# Create dataframes
|
316 |
+
full_rows = []
|
317 |
+
display_rows = []
|
318 |
+
|
319 |
+
for data in user_contributions.values():
|
320 |
+
# Full data for CSV
|
321 |
+
full_rows.append(
|
322 |
+
{
|
323 |
+
"Username": data["username"],
|
324 |
+
"Gmail": data["gmail"],
|
325 |
+
"Discord_Username": data["discord_username"],
|
326 |
+
"HF_Username": data["hf_username"],
|
327 |
+
"Email": data["email"],
|
328 |
+
"Arena": data["arena"],
|
329 |
+
"Blend-ES": data["blend_es"],
|
330 |
+
"Estereotipos": data["estereotipos"],
|
331 |
+
"INCLUDE": data["include"],
|
332 |
+
}
|
333 |
+
)
|
334 |
+
|
335 |
+
# Display data for UI (public)
|
336 |
+
display_rows.append(
|
337 |
+
{
|
338 |
+
"Username": data["username"],
|
339 |
+
"Arena": data["arena"],
|
340 |
+
"Blend-ES": data["blend_es"],
|
341 |
+
"Estereotipos": data["estereotipos"],
|
342 |
+
"INCLUDE": data["include"],
|
343 |
+
}
|
344 |
+
)
|
345 |
+
|
346 |
+
# Save full data to CSV
|
347 |
+
full_df = pd.DataFrame(full_rows)
|
348 |
+
if not full_df.empty:
|
349 |
+
full_df.sort_values("Arena", ascending=False, inplace=True)
|
350 |
+
full_df.to_csv(LEADERBOARD_PERSONAL_CSV, index=False, encoding="utf-8")
|
351 |
+
|
352 |
+
# Return display dataframe for UI
|
353 |
+
display_df = pd.DataFrame(display_rows)
|
354 |
+
if not display_df.empty:
|
355 |
+
display_df.sort_values("Arena", ascending=False, inplace=True)
|
356 |
+
|
357 |
+
return display_df
|
358 |
+
|
359 |
+
|
360 |
+
# FastAPI app
|
361 |
app = FastAPI()
|
362 |
|
363 |
+
# Global variables for caching
|
364 |
last_update_time = 0
|
365 |
cached_data = None
|
366 |
|
367 |
|
368 |
def create_leaderboard_ui():
|
369 |
+
"""Create the leaderboard UI with caching."""
|
370 |
global cached_data, last_update_time
|
371 |
current_time = time.time()
|
372 |
|
373 |
if cached_data is not None and current_time - last_update_time < 300:
|
374 |
df = cached_data
|
375 |
else:
|
376 |
+
df = consolidate_all_data()
|
|
|
377 |
cached_data = df
|
378 |
last_update_time = current_time
|
379 |
|
380 |
if not df.empty:
|
381 |
df = df.reset_index(drop=True)
|
382 |
df.index = df.index + 1
|
383 |
+
df = df.rename_axis("Rank").reset_index()
|
|
|
384 |
|
385 |
df_html = df.to_html(classes="leaderboard-table", border=0, index=False)
|
386 |
|
387 |
+
return f"""
|
388 |
<div style="margin: 20px 0;">
|
389 |
<p>Última Actualización: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(last_update_time))}</p>
|
390 |
<style>
|
|
|
450 |
{df_html}
|
451 |
</div>
|
452 |
"""
|
|
|
453 |
|
454 |
|
455 |
def refresh_data():
|
456 |
+
"""Refresh the leaderboard data."""
|
457 |
global cached_data, last_update_time
|
458 |
cached_data = None
|
459 |
last_update_time = 0
|
460 |
return create_leaderboard_ui()
|
461 |
|
462 |
|
463 |
+
# Gradio interface
|
464 |
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
465 |
with gr.Column(scale=1):
|
466 |
+
gr.Markdown("# 🏆 Leaderboard Personal Retos Hackathon 2025")
|
|
|
467 |
leaderboard_html = gr.HTML(create_leaderboard_ui)
|
|
|
468 |
refresh_btn = gr.Button("🔄 Actualizar Datos", variant="primary")
|
469 |
refresh_btn.click(fn=refresh_data, outputs=leaderboard_html)
|
470 |
|
leaderboard_personal.csv
CHANGED
@@ -1,39 +1,54 @@
|
|
1 |
-
Username,Arena,Blend-ES,Estereotipos,INCLUDE
|
2 |
-
roverico,140,0,
|
3 |
-
steminism,133,0,0,
|
4 |
-
andres_seba,120,0,
|
5 |
-
mcdaqc,118,0,0,
|
6 |
-
|
7 |
-
bea esparcia,80,0,126
|
8 |
-
angustias22,63,0,0,0
|
9 |
-
henry mantilla,58,0,0,0
|
10 |
-
fabianpp,50,0,0,
|
11 |
-
alvaro8gb,42,0,2
|
12 |
-
enpaiva93,40,0,
|
13 |
-
ghuerta170,35,0,0,
|
14 |
-
edmenciab,30,0,0,0
|
15 |
-
luceldasilva,23,0,0,0
|
16 |
-
adriszmar,22,0,
|
17 |
-
helenpy,19,0,0,0
|
18 |
-
danielcavilla,19,0,0,0
|
19 |
-
gonzalo_40146,8,0,0,0
|
20 |
-
gonzalo.fuentes
|
21 |
-
gfuentes2000
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
freddyalfonsoboulton,0,0,1
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Username,Gmail,Discord_Username,HF_Username,Email,Arena,Blend-ES,Estereotipos,INCLUDE
|
2 |
+
roverico,[email protected],roverico,rovi27,[email protected],140,0,0,304
|
3 |
+
steminism,[email protected],steminism,4nd,[email protected],133,0,0,577
|
4 |
+
andres_seba,[email protected],andres_seba,AndresSebad,[email protected],120,0,0,440
|
5 |
+
mcdaqc,[email protected],mcdaqc,daqc,[email protected],118,0,0,449
|
6 |
+
dreamripper1,[email protected],dreamripper1,JuanJCalderonG,[email protected],83,0,0,987
|
7 |
+
bea esparcia,[email protected],Bea Esparcia,BeaEsparcia,[email protected],80,0,0,126
|
8 |
+
angustias22,[email protected],angustias22,lauramm,[email protected],63,0,0,0
|
9 |
+
henry mantilla,[email protected],Henry Mantilla,HenryM,[email protected],58,0,0,0
|
10 |
+
fabianpp,[email protected],fabianpp,Factral,[email protected],50,0,0,372
|
11 |
+
alvaro8gb,[email protected],Alvaro8gb,Alvaro8gb,[email protected],42,0,0,2
|
12 |
+
enpaiva93,[email protected],enpaiva93,enpaiva,[email protected],40,0,0,505
|
13 |
+
ghuerta170,[email protected],ghuerta170,Gerard-1705,[email protected],35,0,0,353
|
14 |
+
edmenciab,[email protected],edmenciab,edmenciab ,[email protected],30,0,0,0
|
15 |
+
luceldasilva,[email protected],luceldasilva,luceldasilva,[email protected],23,0,0,0
|
16 |
+
adriszmar,[email protected],adriszmar,adriszmar,[email protected],22,0,0,247
|
17 |
+
helenpy,[email protected],helenpy,LATEiimas,[email protected],19,0,0,0
|
18 |
+
danielcavilla,[email protected],DanielCavilla,DanielCavilla,[email protected],19,0,0,0
|
19 |
+
gonzalo_40146,[email protected],gonzalo_40146,gonznm,[email protected],8,0,0,0
|
20 |
+
gonzalo.fuentes,,,,,1,0,0,0
|
21 |
+
gfuentes2000,,,,,1,0,0,0
|
22 |
+
valaery,[email protected],valaery,valaery,[email protected],0,0,0,1
|
23 |
+
clauvallory,,,,,0,0,0,5
|
24 |
+
lucase#5596,[email protected],Lucase#5596,Lucase,[email protected],0,0,0,3
|
25 |
+
daelsand,,,,,0,0,0,2
|
26 |
+
da.qc,,,,,0,0,0,2
|
27 |
+
guidoivetta ,,,,,0,0,0,393
|
28 |
+
jorge-neo,,,,,0,0,0,927
|
29 |
+
yee51,[email protected],Yee51,cleysi51,[email protected],0,0,0,1
|
30 |
+
freddyalfonsoboulton,,,,,0,0,0,1
|
31 |
+
mgomez8540,[email protected],mgomez8540,[email protected],[email protected],0,0,0,348
|
32 |
+
gpalomeque,[email protected],gpalomeque,GPalomeque,[email protected],0,0,0,120
|
33 |
+
conilinguist,constanzapjeldres@gmail.com,conilinguist,conijeldres,[email protected],0,0,0,300
|
34 |
+
arri98,,,,,0,0,0,598
|
35 |
+
dramos7,[email protected],Dramos7,DRamos,[email protected],0,0,0,5
|
36 |
+
maria isabel ll,[email protected],Maria Isabel LL,MariaIsabel,[email protected],0,0,0,12
|
37 |
+
jorgeav,[email protected],JorgeAV,JorgeAV,[email protected],0,0,0,13
|
38 |
+
jorge.vallego,,,,,0,0,0,14
|
39 |
+
oscarcumbicus,oskr2703@gmail.com,oscarcumbicus,oskrmiguel,[email protected],0,0,0,1280
|
40 |
+
pablo.ce,[email protected],pablo.ce,pabloce,[email protected],0,0,0,2830
|
41 |
+
rasel,,,,,0,0,0,300
|
42 |
+
reewos,[email protected],reewos,reewos,[email protected],0,0,0,608
|
43 |
+
bel21093_72376,,,,,0,0,0,300
|
44 |
+
godswrath97,[email protected],godswrath97,JorgeMTT97,[email protected],0,0,0,561
|
45 |
+
susanazhou,[email protected],susanazhou,susanazhou ,[email protected],0,0,0,560
|
46 |
+
henrymantilla,,,,,0,0,0,302
|
47 |
+
neovalleltd,,,,,0,0,0,122
|
48 |
+
amayuelas,,,,,0,0,0,2300
|
49 |
+
elena w.,[email protected],Elena W.,hyrka,[email protected],0,0,0,57
|
50 |
+
alebravo,[email protected],AleBravo,AleBravo,[email protected],0,0,0,30
|
51 |
+
jedzill4,[email protected],jedzill4,jedzill4,[email protected],0,0,0,27
|
52 |
+
gonznm,,,,,0,0,0,24
|
53 |
+
agumeister,[email protected],agumeister,agustinghent,[email protected],0,0,0,21
|
54 |
+
alexis_castillo,[email protected],alexis_castillo,AlexisCastillo,[email protected],0,0,0,68
|
requirements.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1 |
gradio ~= 4.44.0
|
2 |
argilla ~= 2.5.0
|
3 |
python-dotenv ~= 1.0.0
|
|
|
|
1 |
gradio ~= 4.44.0
|
2 |
argilla ~= 2.5.0
|
3 |
python-dotenv ~= 1.0.0
|
4 |
+
pandas ~= 2.0.0
|