Spaces:
Running
Running
Commit
Β·
63b28b4
1
Parent(s):
1cff442
adding compatability for two spaces
Browse files
app.py
CHANGED
|
@@ -5,23 +5,24 @@ from pathlib import Path
|
|
| 5 |
from datetime import datetime, timezone
|
| 6 |
import time
|
| 7 |
import logging
|
|
|
|
| 8 |
|
| 9 |
logging.basicConfig(level=logging.INFO)
|
| 10 |
-
|
| 11 |
LAST_UPDATED = "Dec 4th 2024"
|
| 12 |
|
| 13 |
-
def load_static_leaderboard():
|
| 14 |
-
# read fake_queue/leaderboard.json
|
| 15 |
-
return pd.read_json(Path("fake_queue/leaderboard.json"))
|
| 16 |
-
|
| 17 |
def load_leaderboard_data():
|
| 18 |
try:
|
| 19 |
-
response = requests.get(f"{
|
| 20 |
response.raise_for_status()
|
| 21 |
return pd.DataFrame(response.json())
|
| 22 |
except requests.RequestException as e:
|
| 23 |
logging.error(f"Error loading leaderboard: {e}")
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
def format_leaderboard_df(df):
|
| 27 |
if df.empty:
|
|
@@ -37,34 +38,34 @@ def format_leaderboard_df(df):
|
|
| 37 |
|
| 38 |
return display_df.sort_values("Average PER β¬οΈ")
|
| 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 |
def create_html_table(df):
|
| 70 |
return df.to_html(escape=False, index=False, classes="styled-table")
|
|
@@ -95,10 +96,10 @@ with gr.Blocks(css="""
|
|
| 95 |
|
| 96 |
with gr.Tabs():
|
| 97 |
with gr.TabItem("π Leaderboard"):
|
| 98 |
-
leaderboard_html = gr.HTML(create_html_table(format_leaderboard_df(
|
| 99 |
refresh_btn = gr.Button("π Refresh")
|
| 100 |
refresh_btn.click(
|
| 101 |
-
lambda: create_html_table(format_leaderboard_df(
|
| 102 |
outputs=leaderboard_html
|
| 103 |
)
|
| 104 |
|
|
@@ -109,22 +110,22 @@ with gr.Blocks(css="""
|
|
| 109 |
submit_btn = gr.Button("Submit")
|
| 110 |
result = gr.Textbox(label="Submission Status")
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
|
| 118 |
with gr.TabItem("π Task Status"):
|
| 119 |
task_id = gr.Textbox(label="Task ID")
|
| 120 |
status_btn = gr.Button("Check Status")
|
| 121 |
status_output = gr.JSON(label="Status")
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
|
| 129 |
if __name__ == "__main__":
|
| 130 |
demo.launch()
|
|
|
|
| 5 |
from datetime import datetime, timezone
|
| 6 |
import time
|
| 7 |
import logging
|
| 8 |
+
import os
|
| 9 |
|
| 10 |
logging.basicConfig(level=logging.INFO)
|
| 11 |
+
QUEUE_SPACE_URL = os.getenv('QUEUE_SPACE_URL', 'https://huggingface.co/spaces/KoelLabs/IPA-Transcription-EN-Queue').rstrip('/')
|
| 12 |
LAST_UPDATED = "Dec 4th 2024"
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
def load_leaderboard_data():
|
| 15 |
try:
|
| 16 |
+
response = requests.get(f"{QUEUE_SPACE_URL}/api/leaderboard")
|
| 17 |
response.raise_for_status()
|
| 18 |
return pd.DataFrame(response.json())
|
| 19 |
except requests.RequestException as e:
|
| 20 |
logging.error(f"Error loading leaderboard: {e}")
|
| 21 |
+
# Fallback to static leaderboard if available
|
| 22 |
+
try:
|
| 23 |
+
return pd.read_json(Path("fake_queue/leaderboard.json"))
|
| 24 |
+
except:
|
| 25 |
+
return pd.DataFrame()
|
| 26 |
|
| 27 |
def format_leaderboard_df(df):
|
| 28 |
if df.empty:
|
|
|
|
| 38 |
|
| 39 |
return display_df.sort_values("Average PER β¬οΈ")
|
| 40 |
|
| 41 |
+
def submit_evaluation(model_name, submission_name, github_url):
|
| 42 |
+
if not model_name or not submission_name:
|
| 43 |
+
return "β οΈ Please provide both model name and submission name."
|
| 44 |
|
| 45 |
+
request_data = {
|
| 46 |
+
"transcription_model": model_name,
|
| 47 |
+
"subset": "test",
|
| 48 |
+
"submission_name": submission_name,
|
| 49 |
+
"github_url": github_url if github_url else None
|
| 50 |
+
}
|
| 51 |
|
| 52 |
+
try:
|
| 53 |
+
response = requests.post(f"{QUEUE_SPACE_URL}/api/evaluate", json=request_data)
|
| 54 |
+
response.raise_for_status()
|
| 55 |
+
task_id = response.json()["task_id"]
|
| 56 |
+
return f"β
Evaluation submitted successfully! Task ID: {task_id}"
|
| 57 |
+
except requests.RequestException as e:
|
| 58 |
+
return f"β Error: {str(e)}"
|
| 59 |
|
| 60 |
+
def check_task_status(task_id):
|
| 61 |
+
if not task_id:
|
| 62 |
+
return "Please enter a task ID"
|
| 63 |
+
try:
|
| 64 |
+
response = requests.get(f"{QUEUE_SPACE_URL}/api/tasks/{task_id}")
|
| 65 |
+
response.raise_for_status()
|
| 66 |
+
return response.json()
|
| 67 |
+
except requests.RequestException as e:
|
| 68 |
+
return f"Error checking status: {str(e)}"
|
| 69 |
|
| 70 |
def create_html_table(df):
|
| 71 |
return df.to_html(escape=False, index=False, classes="styled-table")
|
|
|
|
| 96 |
|
| 97 |
with gr.Tabs():
|
| 98 |
with gr.TabItem("π Leaderboard"):
|
| 99 |
+
leaderboard_html = gr.HTML(create_html_table(format_leaderboard_df(load_leaderboard_data())))
|
| 100 |
refresh_btn = gr.Button("π Refresh")
|
| 101 |
refresh_btn.click(
|
| 102 |
+
lambda: create_html_table(format_leaderboard_df(load_leaderboard_data())),
|
| 103 |
outputs=leaderboard_html
|
| 104 |
)
|
| 105 |
|
|
|
|
| 110 |
submit_btn = gr.Button("Submit")
|
| 111 |
result = gr.Textbox(label="Submission Status")
|
| 112 |
|
| 113 |
+
submit_btn.click(
|
| 114 |
+
submit_evaluation,
|
| 115 |
+
inputs=[model_name, submission_name, github_url],
|
| 116 |
+
outputs=result
|
| 117 |
+
)
|
| 118 |
|
| 119 |
with gr.TabItem("π Task Status"):
|
| 120 |
task_id = gr.Textbox(label="Task ID")
|
| 121 |
status_btn = gr.Button("Check Status")
|
| 122 |
status_output = gr.JSON(label="Status")
|
| 123 |
|
| 124 |
+
status_btn.click(
|
| 125 |
+
check_task_status,
|
| 126 |
+
inputs=task_id,
|
| 127 |
+
outputs=status_output
|
| 128 |
+
)
|
| 129 |
|
| 130 |
if __name__ == "__main__":
|
| 131 |
demo.launch()
|