Abhishek Thakur
commited on
Commit
·
c50a91b
1
Parent(s):
12de094
add admin icon
Browse files- .gitignore +1 -0
- competitions/app.py +83 -0
- competitions/info.py +37 -1
- competitions/templates/index.html +261 -2
.gitignore
CHANGED
|
@@ -4,6 +4,7 @@
|
|
| 4 |
.vim/
|
| 5 |
flagged/
|
| 6 |
*.csv
|
|
|
|
| 7 |
*.db
|
| 8 |
install.txt
|
| 9 |
uninstall.txt
|
|
|
|
| 4 |
.vim/
|
| 5 |
flagged/
|
| 6 |
*.csv
|
| 7 |
+
*.json
|
| 8 |
*.db
|
| 9 |
install.txt
|
| 10 |
uninstall.txt
|
competitions/app.py
CHANGED
|
@@ -353,3 +353,86 @@ def update_team_name(
|
|
| 353 |
return {"success": True, "error": ""}
|
| 354 |
except Exception as e:
|
| 355 |
return {"success": False, "error": str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
return {"success": True, "error": ""}
|
| 354 |
except Exception as e:
|
| 355 |
return {"success": False, "error": str(e)}
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
@app.post("/admin/comp_info", response_class=JSONResponse)
|
| 359 |
+
async def admin_comp_info(request: Request, user_token: str = Depends(utils.user_authentication)):
|
| 360 |
+
comp_org = COMPETITION_ID.split("/")[0]
|
| 361 |
+
user_is_admin = utils.is_user_admin(user_token, comp_org)
|
| 362 |
+
if not user_is_admin:
|
| 363 |
+
return {"response": "You are not an admin."}, 403
|
| 364 |
+
|
| 365 |
+
competition_info = CompetitionInfo(competition_id=COMPETITION_ID, autotrain_token=HF_TOKEN)
|
| 366 |
+
|
| 367 |
+
markdowns = {
|
| 368 |
+
"competition_desc": competition_info.competition_desc,
|
| 369 |
+
"rules": competition_info.rules,
|
| 370 |
+
"submission_desc": competition_info.submission_desc,
|
| 371 |
+
"dataset_desc": competition_info.dataset_desc,
|
| 372 |
+
}
|
| 373 |
+
if markdowns["rules"] is None:
|
| 374 |
+
markdowns["rules"] = "No rules available."
|
| 375 |
+
|
| 376 |
+
config = {
|
| 377 |
+
"SUBMISSION_LIMIT": competition_info.submission_limit,
|
| 378 |
+
"SELECTION_LIMIT": competition_info.selection_limit,
|
| 379 |
+
"END_DATE": competition_info.end_date.strftime("%Y-%m-%d"),
|
| 380 |
+
"EVAL_HIGHER_IS_BETTER": competition_info.eval_higher_is_better,
|
| 381 |
+
"SUBMISSION_COLUMNS": competition_info.submission_columns_raw,
|
| 382 |
+
"SUBMISSION_ID_COLUMN": competition_info.submission_id_col,
|
| 383 |
+
"LOGO": competition_info.logo_url,
|
| 384 |
+
"COMPETITION_TYPE": competition_info.competition_type,
|
| 385 |
+
"EVAL_METRIC": competition_info.metric,
|
| 386 |
+
"SUBMISSION_ROWS": competition_info.submission_rows,
|
| 387 |
+
"TIME_LIMIT": competition_info.time_limit,
|
| 388 |
+
"DATASET": competition_info.dataset,
|
| 389 |
+
"SUBMISSION_FILENAMES": competition_info.submission_filenames,
|
| 390 |
+
"SCORING_METRIC": competition_info.scoring_metric,
|
| 391 |
+
"HARDWARE": competition_info.hardware,
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
return {"response": {"config": config, "markdowns": markdowns}}
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
@app.post("/admin/update_comp_info", response_class=JSONResponse)
|
| 398 |
+
async def update_comp_info(request: Request, user_token: str = Depends(utils.user_authentication)):
|
| 399 |
+
comp_org = COMPETITION_ID.split("/")[0]
|
| 400 |
+
user_is_admin = utils.is_user_admin(user_token, comp_org)
|
| 401 |
+
if not user_is_admin:
|
| 402 |
+
return {"response": "You are not an admin."}, 403
|
| 403 |
+
|
| 404 |
+
competition_info = CompetitionInfo(competition_id=COMPETITION_ID, autotrain_token=HF_TOKEN)
|
| 405 |
+
|
| 406 |
+
data = await request.json()
|
| 407 |
+
config = data["config"]
|
| 408 |
+
markdowns = data["markdowns"]
|
| 409 |
+
|
| 410 |
+
valid_keys = [
|
| 411 |
+
"SUBMISSION_LIMIT",
|
| 412 |
+
"SELECTION_LIMIT",
|
| 413 |
+
"END_DATE",
|
| 414 |
+
"EVAL_HIGHER_IS_BETTER",
|
| 415 |
+
"SUBMISSION_COLUMNS",
|
| 416 |
+
"SUBMISSION_ID_COLUMN",
|
| 417 |
+
"LOGO",
|
| 418 |
+
"COMPETITION_TYPE",
|
| 419 |
+
"EVAL_METRIC",
|
| 420 |
+
"SUBMISSION_ROWS",
|
| 421 |
+
"TIME_LIMIT",
|
| 422 |
+
"DATASET",
|
| 423 |
+
"SUBMISSION_FILENAMES",
|
| 424 |
+
"SCORING_METRIC",
|
| 425 |
+
"HARDWARE",
|
| 426 |
+
]
|
| 427 |
+
|
| 428 |
+
for key in config:
|
| 429 |
+
if key not in valid_keys:
|
| 430 |
+
return {"success": False, "error": f"Invalid key: {key}"}
|
| 431 |
+
|
| 432 |
+
try:
|
| 433 |
+
competition_info.update_competition_info(config, markdowns, HF_TOKEN)
|
| 434 |
+
except Exception as e:
|
| 435 |
+
logger.error(e)
|
| 436 |
+
return {"success": False}, 500
|
| 437 |
+
|
| 438 |
+
return {"success": True}
|
competitions/info.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
|
|
| 1 |
import json
|
| 2 |
from dataclasses import dataclass
|
| 3 |
from datetime import datetime
|
| 4 |
|
| 5 |
-
from huggingface_hub import hf_hub_download
|
| 6 |
|
| 7 |
|
| 8 |
@dataclass
|
|
@@ -96,6 +97,10 @@ class CompetitionInfo:
|
|
| 96 |
def submission_columns(self):
|
| 97 |
return self.config["SUBMISSION_COLUMNS"].split(",")
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
@property
|
| 100 |
def submission_description(self):
|
| 101 |
return self.submission_desc
|
|
@@ -159,3 +164,34 @@ class CompetitionInfo:
|
|
| 159 |
@property
|
| 160 |
def rules(self):
|
| 161 |
return self.rules_md
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
import json
|
| 3 |
from dataclasses import dataclass
|
| 4 |
from datetime import datetime
|
| 5 |
|
| 6 |
+
from huggingface_hub import HfApi, hf_hub_download
|
| 7 |
|
| 8 |
|
| 9 |
@dataclass
|
|
|
|
| 97 |
def submission_columns(self):
|
| 98 |
return self.config["SUBMISSION_COLUMNS"].split(",")
|
| 99 |
|
| 100 |
+
@property
|
| 101 |
+
def submission_columns_raw(self):
|
| 102 |
+
return self.config["SUBMISSION_COLUMNS"]
|
| 103 |
+
|
| 104 |
@property
|
| 105 |
def submission_description(self):
|
| 106 |
return self.submission_desc
|
|
|
|
| 164 |
@property
|
| 165 |
def rules(self):
|
| 166 |
return self.rules_md
|
| 167 |
+
|
| 168 |
+
def _save_md(self, md, filename, api):
|
| 169 |
+
md = io.BytesIO(md.encode())
|
| 170 |
+
api.upload_file(
|
| 171 |
+
path_or_fileobj=md,
|
| 172 |
+
path_in_repo=filename,
|
| 173 |
+
repo_id=self.competition_id,
|
| 174 |
+
repo_type="dataset",
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
def update_competition_info(self, config, markdowns, token):
|
| 178 |
+
api = HfApi(token=token)
|
| 179 |
+
conf_json = json.dumps(config, indent=4)
|
| 180 |
+
conf_json_bytes = conf_json.encode("utf-8")
|
| 181 |
+
conf_json_buffer = io.BytesIO(conf_json_bytes)
|
| 182 |
+
api.upload_file(
|
| 183 |
+
path_or_fileobj=conf_json_buffer,
|
| 184 |
+
path_in_repo="conf.json",
|
| 185 |
+
repo_id=self.competition_id,
|
| 186 |
+
repo_type="dataset",
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
competition_desc = markdowns["competition_desc"]
|
| 190 |
+
dataset_desc = markdowns["dataset_desc"]
|
| 191 |
+
submission_desc = markdowns["submission_desc"]
|
| 192 |
+
rules_md = markdowns["rules"]
|
| 193 |
+
|
| 194 |
+
self._save_md(competition_desc, "COMPETITION_DESC.md", api)
|
| 195 |
+
self._save_md(dataset_desc, "DATASET_DESC.md", api)
|
| 196 |
+
self._save_md(submission_desc, "SUBMISSION_DESC.md", api)
|
| 197 |
+
self._save_md(rules_md, "RULES.md", api)
|
competitions/templates/index.html
CHANGED
|
@@ -22,6 +22,17 @@
|
|
| 22 |
modal.classList.add('hidden');
|
| 23 |
}
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
function fetchAndDisplayCompetitionInfo() {
|
| 26 |
const articleLoadingSpinner = document.getElementById('articleLoadingSpinner');
|
| 27 |
articleLoadingSpinner.classList.remove('hidden');
|
|
@@ -37,6 +48,7 @@
|
|
| 37 |
const contentDiv = document.getElementById('content');
|
| 38 |
contentDiv.style.display = 'block';
|
| 39 |
contentDiv.innerHTML = marked.parse(data.response);
|
|
|
|
| 40 |
articleLoadingSpinner.classList.add('hidden');
|
| 41 |
})
|
| 42 |
.catch(error => {
|
|
@@ -59,6 +71,7 @@
|
|
| 59 |
// Populate the 'content' div with the HTML from the response
|
| 60 |
const contentDiv = document.getElementById('content');
|
| 61 |
contentDiv.innerHTML = marked.parse(data.response);
|
|
|
|
| 62 |
articleLoadingSpinner.classList.add('hidden');
|
| 63 |
})
|
| 64 |
.catch(error => {
|
|
@@ -187,6 +200,7 @@
|
|
| 187 |
// Populate the 'content' div with the HTML from the response
|
| 188 |
const contentDiv = document.getElementById('content');
|
| 189 |
contentDiv.innerHTML = marked.parse(data.response);
|
|
|
|
| 190 |
articleLoadingSpinner.classList.add('hidden');
|
| 191 |
})
|
| 192 |
.catch(error => {
|
|
@@ -246,6 +260,7 @@
|
|
| 246 |
// Populate the 'content' div with the HTML from the response
|
| 247 |
const contentDiv = document.getElementById('content');
|
| 248 |
contentDiv.innerHTML = marked.parse(data.response);
|
|
|
|
| 249 |
articleLoadingSpinner.classList.add('hidden');
|
| 250 |
})
|
| 251 |
.catch(error => {
|
|
@@ -378,9 +393,9 @@
|
|
| 378 |
class="flex items-center p-2 text-gray-900 rounded-lg hover:bg-gray-100 group">
|
| 379 |
<svg class="flex-shrink-0 w-5 h-5 text-gray-500 transition duration-75 group-hover:text-gray-900"
|
| 380 |
aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor"
|
| 381 |
-
viewBox="0 0
|
| 382 |
<path
|
| 383 |
-
d="
|
| 384 |
</svg>
|
| 385 |
<span class="flex-1 ms-3 whitespace-nowrap">Rules</span>
|
| 386 |
</a>
|
|
@@ -454,6 +469,18 @@
|
|
| 454 |
</li>
|
| 455 |
</ul>
|
| 456 |
</li>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
<li id="loginButton" style="display: none;">
|
| 458 |
<a href="/login/huggingface"
|
| 459 |
class="flex justify-center items-center bg-blue-400 hover:bg-blue-600 text-white text-center font-bold py-2 px-4 rounded transition duration-200 ease-in-out">
|
|
@@ -544,9 +571,219 @@
|
|
| 544 |
<div id="success-message" style="color: green;"></div>
|
| 545 |
</div>
|
| 546 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 547 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/2.2.1/flowbite.min.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
</body>
|
| 549 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
<script>
|
| 551 |
document.addEventListener('DOMContentLoaded', function () {
|
| 552 |
document.querySelector('.confirm').addEventListener('click', function (event) {
|
|
@@ -689,4 +926,26 @@
|
|
| 689 |
}
|
| 690 |
</script>
|
| 691 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 692 |
</html>
|
|
|
|
| 22 |
modal.classList.add('hidden');
|
| 23 |
}
|
| 24 |
|
| 25 |
+
function addTargetBlankToLinks() {
|
| 26 |
+
const content = document.getElementById('content');
|
| 27 |
+
const links = content.getElementsByTagName('a');
|
| 28 |
+
|
| 29 |
+
for (let i = 0; i < links.length; i++) {
|
| 30 |
+
if (!links[i].hasAttribute('target')) {
|
| 31 |
+
links[i].setAttribute('target', '_blank');
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
function fetchAndDisplayCompetitionInfo() {
|
| 37 |
const articleLoadingSpinner = document.getElementById('articleLoadingSpinner');
|
| 38 |
articleLoadingSpinner.classList.remove('hidden');
|
|
|
|
| 48 |
const contentDiv = document.getElementById('content');
|
| 49 |
contentDiv.style.display = 'block';
|
| 50 |
contentDiv.innerHTML = marked.parse(data.response);
|
| 51 |
+
addTargetBlankToLinks();
|
| 52 |
articleLoadingSpinner.classList.add('hidden');
|
| 53 |
})
|
| 54 |
.catch(error => {
|
|
|
|
| 71 |
// Populate the 'content' div with the HTML from the response
|
| 72 |
const contentDiv = document.getElementById('content');
|
| 73 |
contentDiv.innerHTML = marked.parse(data.response);
|
| 74 |
+
addTargetBlankToLinks();
|
| 75 |
articleLoadingSpinner.classList.add('hidden');
|
| 76 |
})
|
| 77 |
.catch(error => {
|
|
|
|
| 200 |
// Populate the 'content' div with the HTML from the response
|
| 201 |
const contentDiv = document.getElementById('content');
|
| 202 |
contentDiv.innerHTML = marked.parse(data.response);
|
| 203 |
+
addTargetBlankToLinks();
|
| 204 |
articleLoadingSpinner.classList.add('hidden');
|
| 205 |
})
|
| 206 |
.catch(error => {
|
|
|
|
| 260 |
// Populate the 'content' div with the HTML from the response
|
| 261 |
const contentDiv = document.getElementById('content');
|
| 262 |
contentDiv.innerHTML = marked.parse(data.response);
|
| 263 |
+
addTargetBlankToLinks();
|
| 264 |
articleLoadingSpinner.classList.add('hidden');
|
| 265 |
})
|
| 266 |
.catch(error => {
|
|
|
|
| 393 |
class="flex items-center p-2 text-gray-900 rounded-lg hover:bg-gray-100 group">
|
| 394 |
<svg class="flex-shrink-0 w-5 h-5 text-gray-500 transition duration-75 group-hover:text-gray-900"
|
| 395 |
aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor"
|
| 396 |
+
viewBox="0 0 24 24">
|
| 397 |
<path
|
| 398 |
+
d="M3 0h18v2H3V0zm0 4h18v2H3V4zm0 4h18v2H3V8zm0 4h18v2H3v-2zm0 4h18v2H3v-2zm0 4h18v2H3v-2z" />
|
| 399 |
</svg>
|
| 400 |
<span class="flex-1 ms-3 whitespace-nowrap">Rules</span>
|
| 401 |
</a>
|
|
|
|
| 469 |
</li>
|
| 470 |
</ul>
|
| 471 |
</li>
|
| 472 |
+
<li>
|
| 473 |
+
<a href="#" id="admin"
|
| 474 |
+
class="flex items-center p-2 text-gray-900 rounded-lg hover:bg-gray-100 group">
|
| 475 |
+
<svg class="flex-shrink-0 w-5 h-5 text-gray-500 transition duration-75 group-hover:text-gray-900"
|
| 476 |
+
aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor"
|
| 477 |
+
viewBox="0 0 24 24">
|
| 478 |
+
<path
|
| 479 |
+
d="M12 15.5c-1.93 0-3.5-1.57-3.5-3.5s1.57-3.5 3.5-3.5 3.5 1.57 3.5 3.5-1.57 3.5-3.5 3.5zm7.43-3.5c.04-.33.07-.66.07-1s-.03-.67-.07-1l2.11-1.65c.19-.15.23-.42.12-.63l-2-3.46c-.11-.21-.35-.3-.57-.24l-2.49 1c-.52-.4-1.08-.73-1.69-.98l-.38-2.65C14.57 2.18 14.3 2 14 2h-4c-.3 0-.57.18-.64.45L8.98 5.1c-.61.25-1.17.58-1.69.98l-2.49-1c-.22-.06-.46.03-.57.24l-2 3.46c-.11.21-.07.48.12.63l2.11 1.65c-.04.33-.07.66-.07 1s.03.67.07 1L2.46 14.1c-.19.15-.23.42-.12.63l2 3.46c.11.21.35.3.57.24l2.49-1c.52.4 1.08.73 1.69.98l.38 2.65c.07.27.34.45.64.45h4c.3 0 .57-.18.64-.45l.38-2.65c.61-.25 1.17-.58 1.69-.98l2.49 1c.22.06.46-.03.57-.24l2-3.46c.11-.21.07-.48-.12-.63l-2.11-1.65zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z" />
|
| 480 |
+
</svg>
|
| 481 |
+
<span class="flex-1 ms-3 whitespace-nowrap">Admin</span>
|
| 482 |
+
</a>
|
| 483 |
+
</li>
|
| 484 |
<li id="loginButton" style="display: none;">
|
| 485 |
<a href="/login/huggingface"
|
| 486 |
class="flex justify-center items-center bg-blue-400 hover:bg-blue-600 text-white text-center font-bold py-2 px-4 rounded transition duration-200 ease-in-out">
|
|
|
|
| 571 |
<div id="success-message" style="color: green;"></div>
|
| 572 |
</div>
|
| 573 |
</div>
|
| 574 |
+
<div id="admin-modal" tabindex="-1"
|
| 575 |
+
class="hidden fixed inset-0 z-40 flex items-center justify-center w-full h-full bg-black bg-opacity-50">
|
| 576 |
+
<div id="adminLoadingSpinner" role="status"
|
| 577 |
+
class="hidden fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50">
|
| 578 |
+
<div class="animate-spin rounded-full h-32 w-32 border-b-2 border-gray-900"></div>
|
| 579 |
+
<span class="sr-only">Loading...</span>
|
| 580 |
+
</div>
|
| 581 |
+
<div class="relative w-full max-w-5xl p-4">
|
| 582 |
+
<div class="relative bg-white rounded-lg shadow-2xl">
|
| 583 |
+
<button type="button"
|
| 584 |
+
class="absolute top-3 right-3 text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 inline-flex justify-center items-center"
|
| 585 |
+
data-modal-hide="admin-modal">
|
| 586 |
+
<svg class="w-4 h-4" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none"
|
| 587 |
+
viewBox="0 0 14 14">
|
| 588 |
+
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
|
| 589 |
+
d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6" />
|
| 590 |
+
</svg>
|
| 591 |
+
<span class="sr-only">Close</span>
|
| 592 |
+
</button>
|
| 593 |
+
<div class="p-6 md:p-8 text-center">
|
| 594 |
+
<h3 class="mb-5 text-lg font-medium text-gray-900">Admin</h3>
|
| 595 |
+
<div class="tabs">
|
| 596 |
+
<ul class="flex border-b">
|
| 597 |
+
<li class="mr-1">
|
| 598 |
+
<a class="tab bg-white inline-block py-2 px-4 text-blue-500 hover:text-blue-800 font-semibold"
|
| 599 |
+
href="#config">Config</a>
|
| 600 |
+
</li>
|
| 601 |
+
<li class="mr-1">
|
| 602 |
+
<a class="tab bg-white inline-block py-2 px-4 text-blue-500 hover:text-blue-800 font-semibold"
|
| 603 |
+
href="#competition-desc">Competition Desc</a>
|
| 604 |
+
</li>
|
| 605 |
+
<li class="mr-1">
|
| 606 |
+
<a class="tab bg-white inline-block py-2 px-4 text-blue-500 hover:text-blue-800 font-semibold"
|
| 607 |
+
href="#dataset-desc">Dataset Desc</a>
|
| 608 |
+
</li>
|
| 609 |
+
<li class="mr-1">
|
| 610 |
+
<a class="tab bg-white inline-block py-2 px-4 text-blue-500 hover:text-blue-800 font-semibold"
|
| 611 |
+
href="#submission-desc">Submission Desc</a>
|
| 612 |
+
</li>
|
| 613 |
+
<li class="mr-1">
|
| 614 |
+
<a class="tab bg-white inline-block py-2 px-4 text-blue-500 hover:text-blue-800 font-semibold"
|
| 615 |
+
href="#rules-desc">Rules</a>
|
| 616 |
+
</li>
|
| 617 |
+
</ul>
|
| 618 |
+
</div>
|
| 619 |
+
<div id="tab-contents"
|
| 620 |
+
class="text-xs font-normal text-left overflow-y-auto max-h-[calc(100vh-400px)] border-t border-gray-200 pt-4">
|
| 621 |
+
<div id="config">
|
| 622 |
+
<textarea id="config-textarea" class="w-full h-64 p-2 border rounded">Loading..</textarea>
|
| 623 |
+
<p class="text-xs text-gray-500">Note: The config should be a valid JSON object. To learn
|
| 624 |
+
details about entries, click <a
|
| 625 |
+
href="https://huggingface.co/docs/competitions/competition_repo#confjson"
|
| 626 |
+
target="_blank">here</a>.
|
| 627 |
+
</p>
|
| 628 |
+
</div>
|
| 629 |
+
<div id="competition-desc" class="hidden">
|
| 630 |
+
<textarea id="competition-desc-textarea"
|
| 631 |
+
class="w-full h-64 p-2 border rounded">Loading..</textarea>
|
| 632 |
+
</div>
|
| 633 |
+
<div id="dataset-desc" class="hidden">
|
| 634 |
+
<textarea id="dataset-desc-textarea"
|
| 635 |
+
class="w-full h-64 p-2 border rounded">Loading..</textarea>
|
| 636 |
+
</div>
|
| 637 |
+
<div id="submission-desc" class="hidden">
|
| 638 |
+
<textarea id="submission-desc-textarea"
|
| 639 |
+
class="w-full h-64 p-2 border rounded">Loading..</textarea>
|
| 640 |
+
</div>
|
| 641 |
+
<div id="rules-desc" class="hidden">
|
| 642 |
+
<textarea id="rules-desc-textarea"
|
| 643 |
+
class="w-full h-64 p-2 border rounded">Loading..</textarea>
|
| 644 |
+
</div>
|
| 645 |
+
</div>
|
| 646 |
+
<button id="save-button" class="mt-4 px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-700">
|
| 647 |
+
Save
|
| 648 |
+
</button>
|
| 649 |
+
</div>
|
| 650 |
+
</div>
|
| 651 |
+
</div>
|
| 652 |
+
</div>
|
| 653 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/2.2.1/flowbite.min.js"></script>
|
| 654 |
+
<script>
|
| 655 |
+
document.addEventListener("DOMContentLoaded", function () {
|
| 656 |
+
const content = document.getElementById('content');
|
| 657 |
+
const links = content.getElementsByTagName('a');
|
| 658 |
+
|
| 659 |
+
for (let i = 0; i < links.length; i++) {
|
| 660 |
+
if (!links[i].hasAttribute('target')) {
|
| 661 |
+
links[i].setAttribute('target', '_blank');
|
| 662 |
+
}
|
| 663 |
+
}
|
| 664 |
+
});
|
| 665 |
+
</script>
|
| 666 |
</body>
|
| 667 |
|
| 668 |
+
<script>
|
| 669 |
+
document.addEventListener("DOMContentLoaded", function () {
|
| 670 |
+
document.querySelectorAll('.tabs a').forEach(tab => {
|
| 671 |
+
tab.addEventListener('click', event => {
|
| 672 |
+
event.preventDefault();
|
| 673 |
+
document.querySelectorAll('.tabs a').forEach(t => t.classList.remove('active'));
|
| 674 |
+
tab.classList.add('active');
|
| 675 |
+
|
| 676 |
+
document.querySelectorAll('#tab-contents > div').forEach(content => content.classList.add('hidden'));
|
| 677 |
+
const selectedTab = document.querySelector(tab.getAttribute('href'));
|
| 678 |
+
selectedTab.classList.remove('hidden');
|
| 679 |
+
});
|
| 680 |
+
});
|
| 681 |
+
|
| 682 |
+
async function fetchAdminCompInfo() {
|
| 683 |
+
const adminLoadingSpinner = document.getElementById('adminLoadingSpinner');
|
| 684 |
+
adminLoadingSpinner.classList.remove('hidden');
|
| 685 |
+
try {
|
| 686 |
+
const response = await fetch("/admin/comp_info", {
|
| 687 |
+
method: "POST",
|
| 688 |
+
headers: {
|
| 689 |
+
"Content-Type": "application/json"
|
| 690 |
+
}
|
| 691 |
+
});
|
| 692 |
+
const data = await response.json();
|
| 693 |
+
if (response.ok) {
|
| 694 |
+
populateAdminModal(data.response);
|
| 695 |
+
} else {
|
| 696 |
+
alert(data.response || "Failed to fetch competition info");
|
| 697 |
+
}
|
| 698 |
+
} catch (error) {
|
| 699 |
+
console.error("Error fetching admin competition info:", error);
|
| 700 |
+
alert("An error occurred while fetching competition info.");
|
| 701 |
+
} finally {
|
| 702 |
+
adminLoadingSpinner.classList.add('hidden');
|
| 703 |
+
}
|
| 704 |
+
}
|
| 705 |
+
|
| 706 |
+
function populateAdminModal(data) {
|
| 707 |
+
document.getElementById("config-textarea").value = JSON.stringify(data.config, null, 2);
|
| 708 |
+
document.getElementById("competition-desc-textarea").value = data.markdowns["competition_desc"] || "";
|
| 709 |
+
document.getElementById("dataset-desc-textarea").value = data.markdowns["dataset_desc"] || "";
|
| 710 |
+
document.getElementById("submission-desc-textarea").value = data.markdowns["submission_desc"] || "";
|
| 711 |
+
document.getElementById("rules-desc-textarea").value = data.markdowns["rules"] || "No rules available.";
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
document.querySelectorAll(".tab").forEach(tab => {
|
| 715 |
+
tab.addEventListener("click", function (event) {
|
| 716 |
+
event.preventDefault();
|
| 717 |
+
const targetId = this.getAttribute("href").substring(1);
|
| 718 |
+
|
| 719 |
+
document.querySelectorAll("#tab-contents > div").forEach(content => {
|
| 720 |
+
content.classList.add("hidden");
|
| 721 |
+
});
|
| 722 |
+
document.getElementById(targetId).classList.remove("hidden");
|
| 723 |
+
|
| 724 |
+
document.querySelectorAll(".tab").forEach(t => {
|
| 725 |
+
t.classList.remove("text-blue-800");
|
| 726 |
+
t.classList.add("text-blue-500");
|
| 727 |
+
});
|
| 728 |
+
this.classList.remove("text-blue-500");
|
| 729 |
+
this.classList.add("text-blue-800");
|
| 730 |
+
});
|
| 731 |
+
});
|
| 732 |
+
|
| 733 |
+
document.getElementById("admin").addEventListener("click", function () {
|
| 734 |
+
document.getElementById("admin-modal").classList.remove("hidden");
|
| 735 |
+
fetchAdminCompInfo();
|
| 736 |
+
});
|
| 737 |
+
|
| 738 |
+
document.querySelector("[data-modal-hide='admin-modal']").addEventListener("click", function () {
|
| 739 |
+
document.getElementById("admin-modal").classList.add("hidden");
|
| 740 |
+
});
|
| 741 |
+
|
| 742 |
+
document.getElementById("save-button").addEventListener("click", async function () {
|
| 743 |
+
const adminLoadingSpinner = document.getElementById('adminLoadingSpinner');
|
| 744 |
+
adminLoadingSpinner.classList.remove('hidden');
|
| 745 |
+
|
| 746 |
+
const config = document.getElementById("config-textarea").value;
|
| 747 |
+
const competitionDesc = document.getElementById("competition-desc-textarea").value;
|
| 748 |
+
const datasetDesc = document.getElementById("dataset-desc-textarea").value;
|
| 749 |
+
const submissionDesc = document.getElementById("submission-desc-textarea").value;
|
| 750 |
+
const rulesDesc = document.getElementById("rules-desc-textarea").value;
|
| 751 |
+
|
| 752 |
+
const data = {
|
| 753 |
+
config: JSON.parse(config),
|
| 754 |
+
markdowns: {
|
| 755 |
+
competition_desc: competitionDesc,
|
| 756 |
+
dataset_desc: datasetDesc,
|
| 757 |
+
submission_desc: submissionDesc,
|
| 758 |
+
rules: rulesDesc
|
| 759 |
+
}
|
| 760 |
+
};
|
| 761 |
+
|
| 762 |
+
try {
|
| 763 |
+
const response = await fetch("/admin/update_comp_info", {
|
| 764 |
+
method: "POST",
|
| 765 |
+
headers: {
|
| 766 |
+
"Content-Type": "application/json"
|
| 767 |
+
},
|
| 768 |
+
body: JSON.stringify(data)
|
| 769 |
+
});
|
| 770 |
+
const result = await response.json();
|
| 771 |
+
if (response.ok) {
|
| 772 |
+
alert(result.response || "Successfully updated competition info");
|
| 773 |
+
} else {
|
| 774 |
+
alert(result.response || "Failed to update competition info");
|
| 775 |
+
}
|
| 776 |
+
} catch (error) {
|
| 777 |
+
console.error("Error updating competition info:", error);
|
| 778 |
+
alert("An error occurred while updating competition info.");
|
| 779 |
+
} finally {
|
| 780 |
+
adminLoadingSpinner.classList.add('hidden');
|
| 781 |
+
}
|
| 782 |
+
});
|
| 783 |
+
|
| 784 |
+
});
|
| 785 |
+
</script>
|
| 786 |
+
|
| 787 |
<script>
|
| 788 |
document.addEventListener('DOMContentLoaded', function () {
|
| 789 |
document.querySelector('.confirm').addEventListener('click', function (event) {
|
|
|
|
| 926 |
}
|
| 927 |
</script>
|
| 928 |
|
| 929 |
+
<script>
|
| 930 |
+
function showAdminModal() {
|
| 931 |
+
const modal = document.getElementById('admin-modal');
|
| 932 |
+
modal.classList.add('flex');
|
| 933 |
+
modal.classList.remove('hidden');
|
| 934 |
+
}
|
| 935 |
+
|
| 936 |
+
function hideAdminModal() {
|
| 937 |
+
const modal = document.getElementById('admin-modal');
|
| 938 |
+
modal.classList.remove('flex');
|
| 939 |
+
modal.classList.add('hidden');
|
| 940 |
+
}
|
| 941 |
+
|
| 942 |
+
document.querySelector('#admin').addEventListener('click', function () {
|
| 943 |
+
showAdminModal();
|
| 944 |
+
});
|
| 945 |
+
|
| 946 |
+
document.querySelector('[data-modal-hide="admin-modal"]').addEventListener('click', function () {
|
| 947 |
+
hideAdminModal();
|
| 948 |
+
});
|
| 949 |
+
</script>
|
| 950 |
+
|
| 951 |
</html>
|