remove statistics
Browse files- app.py +12 -22
- ui_helpers.py +0 -34
app.py
CHANGED
|
@@ -9,11 +9,11 @@ import os
|
|
| 9 |
import datetime
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
from storage import upload_file_to_bucket
|
| 12 |
-
from db import add_vote, get_all_votes,
|
| 13 |
from ocr_models import process_model_ocr, initialize_gemini, initialize_mistral, initialize_openai
|
| 14 |
from ui_helpers import (
|
| 15 |
get_model_display_name, select_random_models, format_votes_table,
|
| 16 |
-
|
| 17 |
)
|
| 18 |
|
| 19 |
# Load environment variables
|
|
@@ -202,16 +202,12 @@ def load_vote_data():
|
|
| 202 |
votes = get_all_votes()
|
| 203 |
votes_table_html = format_votes_table(votes)
|
| 204 |
|
| 205 |
-
|
| 206 |
-
stats = get_vote_statistics()
|
| 207 |
-
stats_html = format_statistics(stats)
|
| 208 |
-
|
| 209 |
-
return votes_table_html, stats_html
|
| 210 |
|
| 211 |
except Exception as e:
|
| 212 |
logger.error(f"Error loading vote data: {e}")
|
| 213 |
error_html = f"<p style='color: red;'>Error loading data: {e}</p>"
|
| 214 |
-
return error_html
|
| 215 |
|
| 216 |
def load_elo_leaderboard():
|
| 217 |
"""Load and format ELO leaderboard data."""
|
|
@@ -334,23 +330,17 @@ with gr.Blocks(title="OCR Comparison", css="""
|
|
| 334 |
|
| 335 |
# Data Tab
|
| 336 |
with gr.Tab("📊 Data", id=1):
|
| 337 |
-
gr.Markdown("# 📊 Vote Data
|
| 338 |
-
gr.Markdown("View all votes
|
| 339 |
|
| 340 |
with gr.Row():
|
| 341 |
refresh_btn = gr.Button("🔄 Refresh Data", variant="secondary")
|
| 342 |
|
| 343 |
with gr.Row():
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
)
|
| 349 |
-
with gr.Column(scale=1):
|
| 350 |
-
stats_display = gr.HTML(
|
| 351 |
-
value="<p>Loading statistics...</p>",
|
| 352 |
-
label="📈 Vote Statistics"
|
| 353 |
-
)
|
| 354 |
|
| 355 |
# Leaderboard Tab
|
| 356 |
with gr.Tab("🏆 Leaderboard", id=2):
|
|
@@ -514,7 +504,7 @@ with gr.Blocks(title="OCR Comparison", css="""
|
|
| 514 |
refresh_btn.click(
|
| 515 |
load_vote_data,
|
| 516 |
inputs=None,
|
| 517 |
-
outputs=[votes_table
|
| 518 |
)
|
| 519 |
|
| 520 |
# Refresh leaderboard button
|
|
@@ -528,7 +518,7 @@ with gr.Blocks(title="OCR Comparison", css="""
|
|
| 528 |
demo.load(fn=get_default_username, inputs=None, outputs=username_display)
|
| 529 |
|
| 530 |
# Load vote data when app starts
|
| 531 |
-
demo.load(fn=load_vote_data, inputs=None, outputs=[votes_table
|
| 532 |
|
| 533 |
# Load leaderboard when app starts
|
| 534 |
demo.load(fn=load_elo_leaderboard, inputs=None, outputs=[leaderboard_display])
|
|
|
|
| 9 |
import datetime
|
| 10 |
from dotenv import load_dotenv
|
| 11 |
from storage import upload_file_to_bucket
|
| 12 |
+
from db import add_vote, get_all_votes, calculate_elo_ratings_from_votes
|
| 13 |
from ocr_models import process_model_ocr, initialize_gemini, initialize_mistral, initialize_openai
|
| 14 |
from ui_helpers import (
|
| 15 |
get_model_display_name, select_random_models, format_votes_table,
|
| 16 |
+
format_elo_leaderboard
|
| 17 |
)
|
| 18 |
|
| 19 |
# Load environment variables
|
|
|
|
| 202 |
votes = get_all_votes()
|
| 203 |
votes_table_html = format_votes_table(votes)
|
| 204 |
|
| 205 |
+
return votes_table_html
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
except Exception as e:
|
| 208 |
logger.error(f"Error loading vote data: {e}")
|
| 209 |
error_html = f"<p style='color: red;'>Error loading data: {e}</p>"
|
| 210 |
+
return error_html
|
| 211 |
|
| 212 |
def load_elo_leaderboard():
|
| 213 |
"""Load and format ELO leaderboard data."""
|
|
|
|
| 330 |
|
| 331 |
# Data Tab
|
| 332 |
with gr.Tab("📊 Data", id=1):
|
| 333 |
+
gr.Markdown("# 📊 Vote Data")
|
| 334 |
+
gr.Markdown("View all votes from the OCR Arena")
|
| 335 |
|
| 336 |
with gr.Row():
|
| 337 |
refresh_btn = gr.Button("🔄 Refresh Data", variant="secondary")
|
| 338 |
|
| 339 |
with gr.Row():
|
| 340 |
+
votes_table = gr.HTML(
|
| 341 |
+
value="<p>Loading vote data...</p>",
|
| 342 |
+
label="📋 All Votes (Latest First)"
|
| 343 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
|
| 345 |
# Leaderboard Tab
|
| 346 |
with gr.Tab("🏆 Leaderboard", id=2):
|
|
|
|
| 504 |
refresh_btn.click(
|
| 505 |
load_vote_data,
|
| 506 |
inputs=None,
|
| 507 |
+
outputs=[votes_table]
|
| 508 |
)
|
| 509 |
|
| 510 |
# Refresh leaderboard button
|
|
|
|
| 518 |
demo.load(fn=get_default_username, inputs=None, outputs=username_display)
|
| 519 |
|
| 520 |
# Load vote data when app starts
|
| 521 |
+
demo.load(fn=load_vote_data, inputs=None, outputs=[votes_table])
|
| 522 |
|
| 523 |
# Load leaderboard when app starts
|
| 524 |
demo.load(fn=load_elo_leaderboard, inputs=None, outputs=[leaderboard_display])
|
ui_helpers.py
CHANGED
|
@@ -127,41 +127,7 @@ def format_votes_table(votes: List[Dict[str, Any]]) -> str:
|
|
| 127 |
|
| 128 |
return html
|
| 129 |
|
| 130 |
-
def format_statistics(stats: Dict[str, Any]) -> str:
|
| 131 |
-
"""Format statistics data into HTML."""
|
| 132 |
-
if not stats:
|
| 133 |
-
return "<p>No statistics available.</p>"
|
| 134 |
-
|
| 135 |
-
total_votes = stats.get('total_votes', 0)
|
| 136 |
-
gemini_votes = stats.get('gemini_votes', 0)
|
| 137 |
-
mistral_votes = stats.get('mistral_votes', 0)
|
| 138 |
-
openai_votes = stats.get('openai_votes', 0)
|
| 139 |
-
gemini_percentage = stats.get('gemini_percentage', 0)
|
| 140 |
-
mistral_percentage = stats.get('mistral_percentage', 0)
|
| 141 |
-
openai_percentage = stats.get('openai_percentage', 0)
|
| 142 |
-
|
| 143 |
-
html = f"""
|
| 144 |
-
<div style="padding: 15px; background-color: #f8f9fa; border-radius: 8px;">
|
| 145 |
-
<h3>Overall Statistics</h3>
|
| 146 |
-
<p><strong>Total Votes:</strong> {total_votes}</p>
|
| 147 |
-
|
| 148 |
-
<h4>Gemini Votes</h4>
|
| 149 |
-
<p><strong>Count:</strong> {gemini_votes} ({gemini_percentage:.1f}%)</p>
|
| 150 |
-
|
| 151 |
-
<h4>Mistral Votes</h4>
|
| 152 |
-
<p><strong>Count:</strong> {mistral_votes} ({mistral_percentage:.1f}%)</p>
|
| 153 |
-
|
| 154 |
-
<h4>OpenAI Votes</h4>
|
| 155 |
-
<p><strong>Count:</strong> {openai_votes} ({openai_percentage:.1f}%)</p>
|
| 156 |
-
|
| 157 |
-
<div style="margin-top: 20px; padding: 10px; background-color: #e9ecef; border-radius: 5px;">
|
| 158 |
-
<h4>Current Winner</h4>
|
| 159 |
-
{f'<p style="color: green; font-weight: bold;">Gemini is leading!</p>' if gemini_votes > max(mistral_votes, openai_votes) else f'<p style="color: blue; font-weight: bold;">Mistral is leading!</p>' if mistral_votes > max(gemini_votes, openai_votes) else f'<p style="color: purple; font-weight: bold;">OpenAI is leading!</p>' if openai_votes > max(gemini_votes, mistral_votes) else '<p style="color: gray; font-weight: bold;">It is a tie!</p>'}
|
| 160 |
-
</div>
|
| 161 |
-
</div>
|
| 162 |
-
"""
|
| 163 |
|
| 164 |
-
return html
|
| 165 |
|
| 166 |
def format_elo_leaderboard(elo_ratings: Dict[str, float], vote_counts: Dict[str, int] = None) -> str:
|
| 167 |
"""Format ELO ratings into a leaderboard HTML table."""
|
|
|
|
| 127 |
|
| 128 |
return html
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
|
|
|
| 131 |
|
| 132 |
def format_elo_leaderboard(elo_ratings: Dict[str, float], vote_counts: Dict[str, int] = None) -> str:
|
| 133 |
"""Format ELO ratings into a leaderboard HTML table."""
|