Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import spaces
|
|
| 5 |
import requests
|
| 6 |
import gradio as gr
|
| 7 |
from huggingface_hub import HfApi, list_models
|
| 8 |
-
from threading import Thread
|
| 9 |
|
| 10 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 11 |
|
|
@@ -73,8 +73,8 @@ SCHIZO_WORDS = [
|
|
| 73 |
MARKDOWN_SYMBOLS = ["#", "*", "_", "`", ">", "-", "+", "[", "]", "(", ")", "!", "\\", "|", "~", "<", ">", "=", ":"]
|
| 74 |
|
| 75 |
CACHE = {
|
| 76 |
-
"llm": {"html": None, "timestamp":
|
| 77 |
-
"all": {"html": None, "timestamp":
|
| 78 |
}
|
| 79 |
|
| 80 |
def count_schizo_words(text):
|
|
@@ -189,7 +189,58 @@ def create_leaderboard_html(leaderboard_data):
|
|
| 189 |
</div>
|
| 190 |
<script>
|
| 191 |
function sortTable(n, isNumeric = false) {
|
| 192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
}
|
| 194 |
</script>
|
| 195 |
"""
|
|
@@ -199,28 +250,31 @@ def background_cache_updater():
|
|
| 199 |
while True:
|
| 200 |
try:
|
| 201 |
for model_type in ["llm", "all"]:
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
|
|
|
| 205 |
except Exception as e:
|
| 206 |
print(f"Background update error: {e}")
|
| 207 |
time.sleep(600)
|
| 208 |
|
| 209 |
def load_leaderboard(model_type):
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
|
|
|
| 213 |
|
| 214 |
def trigger_refresh(model_type):
|
| 215 |
def refresh_task():
|
| 216 |
try:
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
|
|
|
| 220 |
except Exception as e:
|
| 221 |
print(f"Refresh error: {e}")
|
| 222 |
Thread(target=refresh_task, daemon=True).start()
|
| 223 |
-
return '<div class="loading">
|
| 224 |
|
| 225 |
@spaces.GPU()
|
| 226 |
def init_leaderboard():
|
|
@@ -237,10 +291,16 @@ with gr.Blocks(css=CSS, theme="soft") as demo:
|
|
| 237 |
value="llm",
|
| 238 |
label="Model Type Filter",
|
| 239 |
)
|
| 240 |
-
refresh_button = gr.Button("Refresh
|
| 241 |
|
| 242 |
leaderboard_html = gr.HTML(init_leaderboard())
|
| 243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
demo.load(
|
| 245 |
fn=load_leaderboard,
|
| 246 |
inputs=[model_type_dropdown],
|
|
|
|
| 5 |
import requests
|
| 6 |
import gradio as gr
|
| 7 |
from huggingface_hub import HfApi, list_models
|
| 8 |
+
from threading import Thread, Lock
|
| 9 |
|
| 10 |
HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
| 11 |
|
|
|
|
| 73 |
MARKDOWN_SYMBOLS = ["#", "*", "_", "`", ">", "-", "+", "[", "]", "(", ")", "!", "\\", "|", "~", "<", ">", "=", ":"]
|
| 74 |
|
| 75 |
CACHE = {
|
| 76 |
+
"llm": {"html": None, "timestamp": 0, "lock": Lock()},
|
| 77 |
+
"all": {"html": None, "timestamp": 0, "lock": Lock()}
|
| 78 |
}
|
| 79 |
|
| 80 |
def count_schizo_words(text):
|
|
|
|
| 189 |
</div>
|
| 190 |
<script>
|
| 191 |
function sortTable(n, isNumeric = false) {
|
| 192 |
+
var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
|
| 193 |
+
table = document.getElementById("leaderboard");
|
| 194 |
+
switching = true;
|
| 195 |
+
dir = "asc";
|
| 196 |
+
|
| 197 |
+
while (switching) {
|
| 198 |
+
switching = false;
|
| 199 |
+
rows = table.rows;
|
| 200 |
+
|
| 201 |
+
for (i = 1; i < (rows.length - 1); i++) {
|
| 202 |
+
shouldSwitch = false;
|
| 203 |
+
x = rows[i].getElementsByTagName("TD")[n];
|
| 204 |
+
y = rows[i + 1].getElementsByTagName("TD")[n];
|
| 205 |
+
|
| 206 |
+
if (dir == "asc") {
|
| 207 |
+
if (isNumeric) {
|
| 208 |
+
if (parseFloat(x.innerHTML) > parseFloat(y.innerHTML)) {
|
| 209 |
+
shouldSwitch = true;
|
| 210 |
+
break;
|
| 211 |
+
}
|
| 212 |
+
} else {
|
| 213 |
+
if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
|
| 214 |
+
shouldSwitch = true;
|
| 215 |
+
break;
|
| 216 |
+
}
|
| 217 |
+
}
|
| 218 |
+
} else if (dir == "desc") {
|
| 219 |
+
if (isNumeric) {
|
| 220 |
+
if (parseFloat(x.innerHTML) < parseFloat(y.innerHTML)) {
|
| 221 |
+
shouldSwitch = true;
|
| 222 |
+
break;
|
| 223 |
+
}
|
| 224 |
+
} else {
|
| 225 |
+
if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
|
| 226 |
+
shouldSwitch = true;
|
| 227 |
+
break;
|
| 228 |
+
}
|
| 229 |
+
}
|
| 230 |
+
}
|
| 231 |
+
}
|
| 232 |
+
|
| 233 |
+
if (shouldSwitch) {
|
| 234 |
+
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
|
| 235 |
+
switching = true;
|
| 236 |
+
switchcount++;
|
| 237 |
+
} else {
|
| 238 |
+
if (switchcount == 0 && dir == "asc") {
|
| 239 |
+
dir = "desc";
|
| 240 |
+
switching = true;
|
| 241 |
+
}
|
| 242 |
+
}
|
| 243 |
+
}
|
| 244 |
}
|
| 245 |
</script>
|
| 246 |
"""
|
|
|
|
| 250 |
while True:
|
| 251 |
try:
|
| 252 |
for model_type in ["llm", "all"]:
|
| 253 |
+
with CACHE[model_type]["lock"]:
|
| 254 |
+
leaderboard_data = generate_leaderboard_data(model_type)
|
| 255 |
+
CACHE[model_type]["html"] = create_leaderboard_html(leaderboard_data)
|
| 256 |
+
CACHE[model_type]["timestamp"] = time.time()
|
| 257 |
except Exception as e:
|
| 258 |
print(f"Background update error: {e}")
|
| 259 |
time.sleep(600)
|
| 260 |
|
| 261 |
def load_leaderboard(model_type):
|
| 262 |
+
with CACHE[model_type]["lock"]:
|
| 263 |
+
if CACHE[model_type]["html"]:
|
| 264 |
+
return CACHE[model_type]["html"]
|
| 265 |
+
return f'<div class="loading">{model_type.upper()} leaderboard loading...</div>'
|
| 266 |
|
| 267 |
def trigger_refresh(model_type):
|
| 268 |
def refresh_task():
|
| 269 |
try:
|
| 270 |
+
with CACHE[model_type]["lock"]:
|
| 271 |
+
leaderboard_data = generate_leaderboard_data(model_type)
|
| 272 |
+
CACHE[model_type]["html"] = create_leaderboard_html(leaderboard_data)
|
| 273 |
+
CACHE[model_type]["timestamp"] = time.time()
|
| 274 |
except Exception as e:
|
| 275 |
print(f"Refresh error: {e}")
|
| 276 |
Thread(target=refresh_task, daemon=True).start()
|
| 277 |
+
return f'<div class="loading">{model_type.upper()} refresh started...</div>'
|
| 278 |
|
| 279 |
@spaces.GPU()
|
| 280 |
def init_leaderboard():
|
|
|
|
| 291 |
value="llm",
|
| 292 |
label="Model Type Filter",
|
| 293 |
)
|
| 294 |
+
refresh_button = gr.Button("Force Refresh Current View")
|
| 295 |
|
| 296 |
leaderboard_html = gr.HTML(init_leaderboard())
|
| 297 |
|
| 298 |
+
model_type_dropdown.change(
|
| 299 |
+
fn=load_leaderboard,
|
| 300 |
+
inputs=[model_type_dropdown],
|
| 301 |
+
outputs=[leaderboard_html]
|
| 302 |
+
)
|
| 303 |
+
|
| 304 |
demo.load(
|
| 305 |
fn=load_leaderboard,
|
| 306 |
inputs=[model_type_dropdown],
|