Abhishek Thakur
commited on
Commit
·
09d288e
1
Parent(s):
34121ca
further ui improvements
Browse files- competitions/app.py +23 -5
- competitions/templates/index.html +50 -5
- competitions/text.py +2 -2
competitions/app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import threading
|
| 3 |
|
|
|
|
| 4 |
from fastapi import FastAPI, File, Form, Request, UploadFile
|
| 5 |
from fastapi.responses import HTMLResponse, JSONResponse
|
| 6 |
from fastapi.staticfiles import StaticFiles
|
|
@@ -12,6 +13,7 @@ from competitions.info import CompetitionInfo
|
|
| 12 |
from competitions.leaderboard import Leaderboard
|
| 13 |
from competitions.runner import JobRunner
|
| 14 |
from competitions.submissions import Submissions
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
|
@@ -74,6 +76,14 @@ async def get_dataset_info(request: Request):
|
|
| 74 |
return resp
|
| 75 |
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
@app.get("/leaderboard/{lb}", response_class=JSONResponse)
|
| 78 |
async def get_leaderboard(request: Request, lb: str):
|
| 79 |
leaderboard = Leaderboard(
|
|
@@ -99,12 +109,20 @@ async def my_submissions(request: Request, user: User):
|
|
| 99 |
competition_type=COMP_INFO.competition_type,
|
| 100 |
)
|
| 101 |
success_subs, failed_subs = sub.my_submissions(user.user_token)
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
if len(
|
| 105 |
-
|
| 106 |
failed_subs = ""
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
return resp
|
| 109 |
|
| 110 |
|
|
|
|
| 1 |
import os
|
| 2 |
import threading
|
| 3 |
|
| 4 |
+
import pandas as pd
|
| 5 |
from fastapi import FastAPI, File, Form, Request, UploadFile
|
| 6 |
from fastapi.responses import HTMLResponse, JSONResponse
|
| 7 |
from fastapi.staticfiles import StaticFiles
|
|
|
|
| 13 |
from competitions.leaderboard import Leaderboard
|
| 14 |
from competitions.runner import JobRunner
|
| 15 |
from competitions.submissions import Submissions
|
| 16 |
+
from competitions.text import SUBMISSION_SELECTION_TEXT, SUBMISSION_TEXT
|
| 17 |
|
| 18 |
|
| 19 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
|
|
|
| 76 |
return resp
|
| 77 |
|
| 78 |
|
| 79 |
+
@app.get("/submission_info", response_class=JSONResponse)
|
| 80 |
+
async def get_submission_info(request: Request):
|
| 81 |
+
info = COMP_INFO.submission_desc
|
| 82 |
+
# info = markdown.markdown(info)
|
| 83 |
+
resp = {"response": info}
|
| 84 |
+
return resp
|
| 85 |
+
|
| 86 |
+
|
| 87 |
@app.get("/leaderboard/{lb}", response_class=JSONResponse)
|
| 88 |
async def get_leaderboard(request: Request, lb: str):
|
| 89 |
leaderboard = Leaderboard(
|
|
|
|
| 109 |
competition_type=COMP_INFO.competition_type,
|
| 110 |
)
|
| 111 |
success_subs, failed_subs = sub.my_submissions(user.user_token)
|
| 112 |
+
subs = pd.concat([success_subs, failed_subs], axis=0)
|
| 113 |
+
subs = subs.to_markdown(index=False)
|
| 114 |
+
if len(subs.strip()) == 0:
|
| 115 |
+
subs = "You have not made any submissions yet."
|
| 116 |
failed_subs = ""
|
| 117 |
+
submission_text = SUBMISSION_TEXT.format(COMP_INFO.submission_limit)
|
| 118 |
+
submission_selection_text = SUBMISSION_SELECTION_TEXT.format(COMP_INFO.selection_limit)
|
| 119 |
+
|
| 120 |
+
resp = {
|
| 121 |
+
"response": {
|
| 122 |
+
"submissions": subs,
|
| 123 |
+
"submission_text": submission_text + submission_selection_text,
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
return resp
|
| 127 |
|
| 128 |
|
competitions/templates/index.html
CHANGED
|
@@ -115,13 +115,31 @@
|
|
| 115 |
})
|
| 116 |
.then(data => {
|
| 117 |
const contentDiv = document.getElementById('content');
|
| 118 |
-
contentDiv.innerHTML = marked.parse(data.response.
|
| 119 |
})
|
| 120 |
.catch(error => {
|
| 121 |
console.error('There was a problem with the fetch operation:', error);
|
| 122 |
});
|
| 123 |
}
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
// Find the 'Home' link in the sidebar
|
| 126 |
const homeLink = document.getElementById('home');
|
| 127 |
const datasetLink = document.getElementById('dataset');
|
|
@@ -129,6 +147,7 @@
|
|
| 129 |
const privateLBLink = document.getElementById('private_lb');
|
| 130 |
const newSubmission = document.getElementById('new_submission');
|
| 131 |
const mySubmissions = document.getElementById('my_submissions');
|
|
|
|
| 132 |
|
| 133 |
// Add a click event listener to the 'Home' link
|
| 134 |
homeLink.addEventListener('click', function (event) {
|
|
@@ -159,6 +178,10 @@
|
|
| 159 |
event.preventDefault(); // Prevent the default link behavior
|
| 160 |
fetchAndDisplaySubmissions(); // Fetch and display info on click
|
| 161 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
// Fetch and display info when the page loads
|
| 164 |
fetchAndDisplayCompetitionInfo();
|
|
@@ -251,6 +274,11 @@
|
|
| 251 |
</svg>
|
| 252 |
</button>
|
| 253 |
<ul id="submissions-dropdown" class="hidden py-2 space-y-2">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
<li>
|
| 255 |
<a href="#" id="my_submissions"
|
| 256 |
class="flex items-center w-full p-2 text-gray-900 transition duration-75 rounded-lg pl-11 group hover:bg-gray-100 dark:text-white dark:hover:bg-gray-700">My
|
|
@@ -284,14 +312,21 @@
|
|
| 284 |
</ul>
|
| 285 |
</div>
|
| 286 |
</aside>
|
| 287 |
-
<div class="p-
|
| 288 |
-
<img src={{logo}} alt="Competition logo" class="mx-auto
|
|
|
|
| 289 |
<article class="prose max-w-5xl" id="content">
|
| 290 |
</article>
|
| 291 |
</div>
|
| 292 |
<div id="submission-modal" tabindex="-1"
|
| 293 |
class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
<div class="form-container max-w-5xl mx-auto mt-3 p-6 shadow-2xl bg-white">
|
|
|
|
| 295 |
<form action="#" method="post" class="gap-2" enctype="multipart/form-data">
|
| 296 |
{% if competition_type == 'generic' %}
|
| 297 |
<div class="form-group">
|
|
@@ -328,6 +363,9 @@
|
|
| 328 |
class="cancel text-white bg-red-600 hover:bg-red-100 focus:ring-4 focus:outline-none focus:ring-red-200 rounded-lg border border-red-200 text-sm font-medium px-5 py-2.5 hover:text-red-900 focus:z-10">Cancel</button>
|
| 329 |
</div>
|
| 330 |
</form>
|
|
|
|
|
|
|
|
|
|
| 331 |
</div>
|
| 332 |
</div>
|
| 333 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/2.2.1/flowbite.min.js"></script>
|
|
@@ -337,6 +375,10 @@
|
|
| 337 |
document.addEventListener('DOMContentLoaded', function () {
|
| 338 |
document.querySelector('.confirm').addEventListener('click', function (event) {
|
| 339 |
event.preventDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
|
| 341 |
var formData = new FormData();
|
| 342 |
var competitionType = '{{ competition_type }}';
|
|
@@ -369,11 +411,14 @@
|
|
| 369 |
})
|
| 370 |
.then(response => response.json())
|
| 371 |
.then(data => {
|
| 372 |
-
|
| 373 |
-
|
|
|
|
| 374 |
})
|
| 375 |
.catch((error) => {
|
| 376 |
console.error('Error:', error);
|
|
|
|
|
|
|
| 377 |
});
|
| 378 |
});
|
| 379 |
});
|
|
|
|
| 115 |
})
|
| 116 |
.then(data => {
|
| 117 |
const contentDiv = document.getElementById('content');
|
| 118 |
+
contentDiv.innerHTML = marked.parse(data.response.submission_text) + marked.parse(data.response.submissions);
|
| 119 |
})
|
| 120 |
.catch(error => {
|
| 121 |
console.error('There was a problem with the fetch operation:', error);
|
| 122 |
});
|
| 123 |
}
|
| 124 |
|
| 125 |
+
function fetchAndDisplaySubmissionInfo() {
|
| 126 |
+
fetch('/submission_info')
|
| 127 |
+
.then(response => {
|
| 128 |
+
if (!response.ok) {
|
| 129 |
+
throw new Error('Network response was not ok');
|
| 130 |
+
}
|
| 131 |
+
return response.json(); // Parse the JSON response
|
| 132 |
+
})
|
| 133 |
+
.then(data => {
|
| 134 |
+
// Populate the 'content' div with the HTML from the response
|
| 135 |
+
const contentDiv = document.getElementById('content');
|
| 136 |
+
contentDiv.innerHTML = marked.parse(data.response);
|
| 137 |
+
})
|
| 138 |
+
.catch(error => {
|
| 139 |
+
console.error('There has been a problem with your fetch operation:', error);
|
| 140 |
+
});
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
// Find the 'Home' link in the sidebar
|
| 144 |
const homeLink = document.getElementById('home');
|
| 145 |
const datasetLink = document.getElementById('dataset');
|
|
|
|
| 147 |
const privateLBLink = document.getElementById('private_lb');
|
| 148 |
const newSubmission = document.getElementById('new_submission');
|
| 149 |
const mySubmissions = document.getElementById('my_submissions');
|
| 150 |
+
const submissionInfo = document.getElementById('submission_info');
|
| 151 |
|
| 152 |
// Add a click event listener to the 'Home' link
|
| 153 |
homeLink.addEventListener('click', function (event) {
|
|
|
|
| 178 |
event.preventDefault(); // Prevent the default link behavior
|
| 179 |
fetchAndDisplaySubmissions(); // Fetch and display info on click
|
| 180 |
});
|
| 181 |
+
submissionInfo.addEventListener('click', function (event) {
|
| 182 |
+
event.preventDefault(); // Prevent the default link behavior
|
| 183 |
+
fetchAndDisplaySubmissionInfo(); // Fetch and display info on click
|
| 184 |
+
});
|
| 185 |
|
| 186 |
// Fetch and display info when the page loads
|
| 187 |
fetchAndDisplayCompetitionInfo();
|
|
|
|
| 274 |
</svg>
|
| 275 |
</button>
|
| 276 |
<ul id="submissions-dropdown" class="hidden py-2 space-y-2">
|
| 277 |
+
<li>
|
| 278 |
+
<a href="#" id="submission_info"
|
| 279 |
+
class="flex items-center w-full p-2 text-gray-900 transition duration-75 rounded-lg pl-11 group hover:bg-gray-100 dark:text-white dark:hover:bg-gray-700">Submission
|
| 280 |
+
information</a>
|
| 281 |
+
</li>
|
| 282 |
<li>
|
| 283 |
<a href="#" id="my_submissions"
|
| 284 |
class="flex items-center w-full p-2 text-gray-900 transition duration-75 rounded-lg pl-11 group hover:bg-gray-100 dark:text-white dark:hover:bg-gray-700">My
|
|
|
|
| 312 |
</ul>
|
| 313 |
</div>
|
| 314 |
</aside>
|
| 315 |
+
<div class="p-1 sm:ml-64">
|
| 316 |
+
<img src={{logo}} alt="Competition logo" class="mx-auto">
|
| 317 |
+
<hr class="mt-3 mb-2">
|
| 318 |
<article class="prose max-w-5xl" id="content">
|
| 319 |
</article>
|
| 320 |
</div>
|
| 321 |
<div id="submission-modal" tabindex="-1"
|
| 322 |
class="hidden overflow-y-auto overflow-x-hidden fixed top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full">
|
| 323 |
+
<div id="loadingSpinner" role="status"
|
| 324 |
+
class="hidden absolute -translate-x-1/2 -translate-y-1/2 top-2/4 left-1/2">
|
| 325 |
+
<div class="animate-spin rounded-full h-32 w-32 border-b-2 border-gray-900"></div>
|
| 326 |
+
<span class="sr-only">Loading...</span>
|
| 327 |
+
</div>
|
| 328 |
<div class="form-container max-w-5xl mx-auto mt-3 p-6 shadow-2xl bg-white">
|
| 329 |
+
<p class="text-lg font-medium text-gray-900">New Submission</p>
|
| 330 |
<form action="#" method="post" class="gap-2" enctype="multipart/form-data">
|
| 331 |
{% if competition_type == 'generic' %}
|
| 332 |
<div class="form-group">
|
|
|
|
| 363 |
class="cancel text-white bg-red-600 hover:bg-red-100 focus:ring-4 focus:outline-none focus:ring-red-200 rounded-lg border border-red-200 text-sm font-medium px-5 py-2.5 hover:text-red-900 focus:z-10">Cancel</button>
|
| 364 |
</div>
|
| 365 |
</form>
|
| 366 |
+
<hr class="mt-3">
|
| 367 |
+
<div id="error-message" style="color: red;"></div>
|
| 368 |
+
<div id="success-message" style="color: green;"></div>
|
| 369 |
</div>
|
| 370 |
</div>
|
| 371 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/2.2.1/flowbite.min.js"></script>
|
|
|
|
| 375 |
document.addEventListener('DOMContentLoaded', function () {
|
| 376 |
document.querySelector('.confirm').addEventListener('click', function (event) {
|
| 377 |
event.preventDefault();
|
| 378 |
+
document.getElementById('error-message').textContent = '';
|
| 379 |
+
document.getElementById('success-message').textContent = '';
|
| 380 |
+
const loadingSpinner = document.getElementById('loadingSpinner');
|
| 381 |
+
loadingSpinner.classList.remove('hidden');
|
| 382 |
|
| 383 |
var formData = new FormData();
|
| 384 |
var competitionType = '{{ competition_type }}';
|
|
|
|
| 411 |
})
|
| 412 |
.then(response => response.json())
|
| 413 |
.then(data => {
|
| 414 |
+
loadingSpinner.classList.add('hidden');
|
| 415 |
+
document.getElementById('success-message').textContent = data.response;
|
| 416 |
+
|
| 417 |
})
|
| 418 |
.catch((error) => {
|
| 419 |
console.error('Error:', error);
|
| 420 |
+
loadingSpinner.classList.add('hidden');
|
| 421 |
+
document.getElementById('error-message').textContent = error;
|
| 422 |
});
|
| 423 |
});
|
| 424 |
});
|
competitions/text.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
SUBMISSION_TEXT = """
|
| 2 |
The test data has been divided into public and private splits.
|
| 3 |
Your score on the public split will be shown on the leaderboard.
|
| 4 |
Your final score will be based on your private split performance.
|
|
@@ -9,7 +9,7 @@ You can find your Hugging Face token [here](https://huggingface.co/settings/toke
|
|
| 9 |
SUBMISSION_ERROR = """Submission is not in a proper format.
|
| 10 |
Please check evaluation instructions for more details."""
|
| 11 |
|
| 12 |
-
SUBMISSION_SELECTION_TEXT = """
|
| 13 |
|
| 14 |
NO_SUBMISSIONS = """You have not made any submissions yet."""
|
| 15 |
|
|
|
|
| 1 |
+
SUBMISSION_TEXT = """### My Submissions\n\nYou can make upto {} submissions per day.
|
| 2 |
The test data has been divided into public and private splits.
|
| 3 |
Your score on the public split will be shown on the leaderboard.
|
| 4 |
Your final score will be based on your private split performance.
|
|
|
|
| 9 |
SUBMISSION_ERROR = """Submission is not in a proper format.
|
| 10 |
Please check evaluation instructions for more details."""
|
| 11 |
|
| 12 |
+
SUBMISSION_SELECTION_TEXT = """\n\nYou can select upto {} submissions for private leaderboard."""
|
| 13 |
|
| 14 |
NO_SUBMISSIONS = """You have not made any submissions yet."""
|
| 15 |
|