Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,9 @@ from leaderboard import (
|
|
15 |
ensure_elo_ratings_initialized
|
16 |
)
|
17 |
import sys
|
|
|
|
|
|
|
18 |
|
19 |
|
20 |
# Initialize logging for errors only
|
@@ -268,6 +271,85 @@ def continue_conversation(prompt, left_chat, right_chat, left_model, right_model
|
|
268 |
tie_count
|
269 |
)
|
270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
# Initialize Gradio Blocks
|
272 |
with gr.Blocks(css="""
|
273 |
#dice-button {
|
@@ -330,6 +412,11 @@ with gr.Blocks(css="""
|
|
330 |
with gr.Tab("ELO Leaderboard"):
|
331 |
elo_leaderboard = gr.HTML(label="ELO Leaderboard")
|
332 |
|
|
|
|
|
|
|
|
|
|
|
333 |
# Define interactions
|
334 |
submit_btn.click(
|
335 |
battle_arena,
|
@@ -370,6 +457,14 @@ with gr.Blocks(css="""
|
|
370 |
demo.load(get_leaderboard, outputs=leaderboard)
|
371 |
demo.load(get_elo_leaderboard, outputs=elo_leaderboard)
|
372 |
demo.load(get_leaderboard_chart, outputs=leaderboard_chart)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
373 |
|
374 |
if __name__ == "__main__":
|
375 |
# Initialize ELO ratings before launching the app
|
|
|
15 |
ensure_elo_ratings_initialized
|
16 |
)
|
17 |
import sys
|
18 |
+
from internal_stats import get_fun_stats
|
19 |
+
import threading
|
20 |
+
import time
|
21 |
|
22 |
|
23 |
# Initialize logging for errors only
|
|
|
271 |
tie_count
|
272 |
)
|
273 |
|
274 |
+
def get_fun_stats_html():
|
275 |
+
stats = get_fun_stats()
|
276 |
+
|
277 |
+
html = f"""
|
278 |
+
<style>
|
279 |
+
.fun-stats {{
|
280 |
+
font-family: Arial, sans-serif;
|
281 |
+
font-size: 18px;
|
282 |
+
line-height: 1.6;
|
283 |
+
max-width: 800px;
|
284 |
+
margin: 0 auto;
|
285 |
+
padding: 20px;
|
286 |
+
}}
|
287 |
+
.fun-stats h2 {{
|
288 |
+
font-size: 36px;
|
289 |
+
color: inherit;
|
290 |
+
text-align: center;
|
291 |
+
margin-bottom: 20px;
|
292 |
+
}}
|
293 |
+
.fun-stats h3 {{
|
294 |
+
font-size: 28px;
|
295 |
+
color: inherit;
|
296 |
+
margin-top: 30px;
|
297 |
+
margin-bottom: 15px;
|
298 |
+
border-bottom: 2px solid currentColor;
|
299 |
+
padding-bottom: 10px;
|
300 |
+
}}
|
301 |
+
.fun-stats ul {{
|
302 |
+
list-style-type: none;
|
303 |
+
padding-left: 0;
|
304 |
+
}}
|
305 |
+
.fun-stats li {{
|
306 |
+
margin-bottom: 15px;
|
307 |
+
padding: 15px;
|
308 |
+
border-radius: 5px;
|
309 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
310 |
+
}}
|
311 |
+
.fun-stats .timestamp {{
|
312 |
+
font-style: italic;
|
313 |
+
text-align: center;
|
314 |
+
margin-bottom: 20px;
|
315 |
+
}}
|
316 |
+
.fun-stats .highlight {{
|
317 |
+
font-weight: bold;
|
318 |
+
color: #e74c3c;
|
319 |
+
}}
|
320 |
+
</style>
|
321 |
+
<div class="fun-stats">
|
322 |
+
<h2>π Fun Arena Stats π</h2>
|
323 |
+
<p class="timestamp">Last updated: {stats['timestamp']}</p>
|
324 |
+
|
325 |
+
<h3>ποΈ Arena Overview</h3>
|
326 |
+
<p>Total Battles Fought: <span class="highlight">{stats['total_battles']}</span></p>
|
327 |
+
<p>Active Gladiators (Models): <span class="highlight">{stats['active_models']}</span></p>
|
328 |
+
|
329 |
+
<h3>π Hall of Fame</h3>
|
330 |
+
<p>π₯ Battle Veteran: <span class="highlight">{stats['most_battles']['model']}</span> ({stats['most_battles']['battles']} battles)</p>
|
331 |
+
<p>πΉ Sharpshooter: <span class="highlight">{stats['highest_win_rate']['model']}</span> (Win Rate: {stats['highest_win_rate']['win_rate']})</p>
|
332 |
+
<p>π Jack of All Trades: <span class="highlight">{stats['most_diverse_opponent']['model']}</span> (Faced {stats['most_diverse_opponent']['unique_opponents']} unique opponents)</p>
|
333 |
+
<p>π Underdog Champion: <span class="highlight">{stats['underdog_champion']['model']}</span> ({stats['underdog_champion']['size']} model with {stats['underdog_champion']['win_rate']} win rate)</p>
|
334 |
+
<p>βοΈ Mr. Consistent: <span class="highlight">{stats['most_consistent']['model']}</span> (Closest to 50% win rate, difference of {stats['most_consistent']['win_loss_difference']} wins/losses)</p>
|
335 |
+
|
336 |
+
|
337 |
+
<h3>π€Ό Epic Battles</h3>
|
338 |
+
<p>π€Ό Biggest Rivalry: <span class="highlight">{stats['biggest_rivalry']['model1']}</span> vs <span class="highlight">{stats['biggest_rivalry']['model2']}</span> ({stats['biggest_rivalry']['total_battles']} fierce battles!)</p>
|
339 |
+
<p>ποΈ David vs Goliath: <span class="highlight">{stats['david_vs_goliath']['david']}</span> (David) vs <span class="highlight">{stats['david_vs_goliath']['goliath']}</span> (Goliath)<br>
|
340 |
+
David won {stats['david_vs_goliath']['wins']} times despite being {stats['david_vs_goliath']['size_difference']} smaller!</p>
|
341 |
+
<p>π Comeback King: <span class="highlight">{stats['comeback_king']['model']}</span> (Overcame a {stats['comeback_king']['comeback_margin']}-battle deficit)</p>
|
342 |
+
<p>π Pyrrhic Victor: <span class="highlight">{stats['pyrrhic_victor']['model']}</span> (Lowest win rate among models with more wins than losses: {stats['pyrrhic_victor']['win_rate']})</p>
|
343 |
+
</div>
|
344 |
+
"""
|
345 |
+
|
346 |
+
return html
|
347 |
+
|
348 |
+
def update_fun_stats_periodically(interval):
|
349 |
+
while True:
|
350 |
+
time.sleep(interval)
|
351 |
+
fun_stats_html.update(value=get_fun_stats_html())
|
352 |
+
|
353 |
# Initialize Gradio Blocks
|
354 |
with gr.Blocks(css="""
|
355 |
#dice-button {
|
|
|
412 |
with gr.Tab("ELO Leaderboard"):
|
413 |
elo_leaderboard = gr.HTML(label="ELO Leaderboard")
|
414 |
|
415 |
+
# Add this new tab
|
416 |
+
with gr.Tab("Fun Stats"):
|
417 |
+
refresh_btn = gr.Button("Refresh Stats")
|
418 |
+
fun_stats_html = gr.HTML(label="Fun Arena Stats")
|
419 |
+
|
420 |
# Define interactions
|
421 |
submit_btn.click(
|
422 |
battle_arena,
|
|
|
457 |
demo.load(get_leaderboard, outputs=leaderboard)
|
458 |
demo.load(get_elo_leaderboard, outputs=elo_leaderboard)
|
459 |
demo.load(get_leaderboard_chart, outputs=leaderboard_chart)
|
460 |
+
demo.load(get_fun_stats_html, outputs=fun_stats_html)
|
461 |
+
|
462 |
+
# Add this event handler for the refresh button
|
463 |
+
refresh_btn.click(get_fun_stats_html, outputs=fun_stats_html)
|
464 |
+
|
465 |
+
# Start the background task to update stats every hour
|
466 |
+
update_thread = threading.Thread(target=update_fun_stats_periodically, args=(3600,), daemon=True)
|
467 |
+
update_thread.start()
|
468 |
|
469 |
if __name__ == "__main__":
|
470 |
# Initialize ELO ratings before launching the app
|