Spaces:
Sleeping
Sleeping
File size: 5,069 Bytes
b064a39 e8d658f a2c34b1 7c5a93e e8d658f 63b28b4 b064a39 e8d658f ea9b1ca 7c5a93e ea9b1ca a2c34b1 e8d658f 91a1fc2 7c5a93e e8d658f 63b28b4 b064a39 a2c34b1 e8d658f b2730cf e8d658f a2c34b1 b064a39 e8d658f b064a39 91a1fc2 63b28b4 e8d658f 63b28b4 b064a39 63b28b4 91a1fc2 7c5a93e 63b28b4 b064a39 63b28b4 91a1fc2 7c5a93e 63b28b4 b2730cf e8d658f b2730cf e8d658f b2730cf e8d658f b2730cf e8d658f b2730cf e8d658f a2c34b1 e8d658f a2c34b1 63b28b4 e8d658f a2c34b1 91a1fc2 e8d658f a2c34b1 e8d658f a2c34b1 63b28b4 91a1fc2 63b28b4 e8d658f a2c34b1 91a1fc2 63b28b4 91a1fc2 63b28b4 b064a39 91a1fc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
import gradio as gr
import pandas as pd
import requests
from pathlib import Path
from datetime import datetime
import logging
import os
logging.basicConfig(level=logging.INFO)
QUEUE_SPACE_URL = os.getenv(
'QUEUE_SPACE_URL',
'https://koellabs-ipa-transcription-en-queue.hf.space/api'
).rstrip('/')
def load_leaderboard_data():
try:
response = requests.get(f"{QUEUE_SPACE_URL}/leaderboard", timeout=10)
logging.info(f"Leaderboard request URL: {QUEUE_SPACE_URL}/leaderboard")
response.raise_for_status()
return pd.DataFrame(response.json())
except requests.RequestException as e:
logging.error(f"Error loading leaderboard: {e}")
try:
return pd.read_json(Path("fake_queue/leaderboard.json"))
except:
return pd.DataFrame()
def format_leaderboard_df(df):
if df.empty:
return df
display_df = pd.DataFrame({
"Model": df["model"],
"Average PER β¬οΈ": df["average_per"].apply(lambda x: f"{x:.4f}"),
"Average PWED β¬οΈ": df["average_pwed"].apply(lambda x: f"{x:.4f}"),
"GitHub": df["github_url"].apply(lambda x: f'<a href="{x}" target="_blank">Repository</a>' if x else "N/A"),
"Submission Date": pd.to_datetime(df["submission_date"]).dt.strftime("%Y-%m-%d")
})
return display_df.sort_values("Average PER β¬οΈ")
def create_html_table(df):
return df.to_html(escape=False, index=False, classes="styled-table")
def submit_evaluation(model_name, submission_name, github_url):
if not model_name or not submission_name:
return "β οΈ Please provide both model name and submission name."
request_data = {
"transcription_model": model_name,
"subset": "test",
"submission_name": submission_name,
"github_url": github_url if github_url else None
}
try:
response = requests.post(
f"{QUEUE_SPACE_URL}/evaluate",
json=request_data,
timeout=10
)
logging.info(f"Submit request URL: {QUEUE_SPACE_URL}/evaluate")
response.raise_for_status()
task_id = response.json()["task_id"]
return f"β
Evaluation submitted successfully! Task ID: {task_id}"
except requests.RequestException as e:
return f"β Error: {str(e)}"
def check_task_status(task_id):
if not task_id:
return "Please enter a task ID"
try:
response = requests.get(
f"{QUEUE_SPACE_URL}/tasks/{task_id}",
timeout=10
)
logging.info(f"Status check URL: {QUEUE_SPACE_URL}/tasks/{task_id}")
response.raise_for_status()
return response.json()
except requests.RequestException as e:
return f"Error checking status: {str(e)}"
with gr.Blocks(css="""
.styled-table {
width: 100%;
border-collapse: collapse;
margin: 25px 0;
font-size: 0.9em;
font-family: sans-serif;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
}
.styled-table thead tr {
background-color: #009879;
color: #ffffff;
text-align: left;
}
.styled-table th,
.styled-table td {
padding: 12px 15px;
}
.styled-table tbody tr {
border-bottom: 1px solid #dddddd;
}
""") as demo:
gr.Markdown("# π― Phonemic Transcription Model Evaluation Leaderboard")
with gr.Tabs():
with gr.TabItem("π Leaderboard"):
leaderboard_html = gr.HTML(create_html_table(format_leaderboard_df(load_leaderboard_data())))
refresh_btn = gr.Button("π Refresh")
refresh_btn.click(
lambda: gr.HTML.update(value=create_html_table(format_leaderboard_df(load_leaderboard_data()))),
outputs=leaderboard_html
)
with gr.TabItem("π Submit Model"):
model_name = gr.Textbox(label="Model Name", placeholder="facebook/wav2vec2-lv-60-espeak-cv-ft")
submission_name = gr.Textbox(label="Submission Name", placeholder="My Model v1.0")
github_url = gr.Textbox(label="GitHub URL (optional)", placeholder="https://github.com/username/repo")
submit_btn = gr.Button("Submit")
result = gr.Textbox(label="Submission Status")
submit_btn.click(
fn=submit_evaluation,
inputs=[model_name, submission_name, github_url],
outputs=result
)
with gr.TabItem("π Task Status"):
task_id = gr.Textbox(label="Task ID")
status_btn = gr.Button("Check Status")
status_output = gr.JSON(label="Status")
# Use a simple function wrapper to ensure direct HTTP request
def check_status_wrapper(task_id):
return check_task_status(task_id)
status_btn.click(
fn=check_status_wrapper,
inputs=task_id,
outputs=status_output
)
demo.launch() |