arunasrivastava commited on
Commit
91a1fc2
·
1 Parent(s): 7c5a93e

two space compatability

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -8,7 +8,6 @@ import os
8
 
9
  logging.basicConfig(level=logging.INFO)
10
 
11
- # Update URL format for HuggingFace Spaces
12
  QUEUE_SPACE_URL = os.getenv(
13
  'QUEUE_SPACE_URL',
14
  'https://koellabs-ipa-transcription-en-queue.hf.space/api'
@@ -16,7 +15,7 @@ QUEUE_SPACE_URL = os.getenv(
16
 
17
  def load_leaderboard_data():
18
  try:
19
- response = requests.get(f"{QUEUE_SPACE_URL}/leaderboard")
20
  logging.info(f"Leaderboard request URL: {QUEUE_SPACE_URL}/leaderboard")
21
  response.raise_for_status()
22
  return pd.DataFrame(response.json())
@@ -41,6 +40,9 @@ def format_leaderboard_df(df):
41
 
42
  return display_df.sort_values("Average PER ⬇️")
43
 
 
 
 
44
  def submit_evaluation(model_name, submission_name, github_url):
45
  if not model_name or not submission_name:
46
  return "⚠️ Please provide both model name and submission name."
@@ -53,7 +55,11 @@ def submit_evaluation(model_name, submission_name, github_url):
53
  }
54
 
55
  try:
56
- response = requests.post(f"{QUEUE_SPACE_URL}/evaluate", json=request_data)
 
 
 
 
57
  logging.info(f"Submit request URL: {QUEUE_SPACE_URL}/evaluate")
58
  response.raise_for_status()
59
  task_id = response.json()["task_id"]
@@ -65,16 +71,16 @@ def check_task_status(task_id):
65
  if not task_id:
66
  return "Please enter a task ID"
67
  try:
68
- response = requests.get(f"{QUEUE_SPACE_URL}/tasks/{task_id}")
 
 
 
69
  logging.info(f"Status check URL: {QUEUE_SPACE_URL}/tasks/{task_id}")
70
  response.raise_for_status()
71
  return response.json()
72
  except requests.RequestException as e:
73
  return f"Error checking status: {str(e)}"
74
 
75
- def create_html_table(df):
76
- return df.to_html(escape=False, index=False, classes="styled-table")
77
-
78
  with gr.Blocks(css="""
79
  .styled-table {
80
  width: 100%;
@@ -104,7 +110,7 @@ with gr.Blocks(css="""
104
  leaderboard_html = gr.HTML(create_html_table(format_leaderboard_df(load_leaderboard_data())))
105
  refresh_btn = gr.Button("🔄 Refresh")
106
  refresh_btn.click(
107
- lambda: create_html_table(format_leaderboard_df(load_leaderboard_data())),
108
  outputs=leaderboard_html
109
  )
110
 
@@ -116,7 +122,7 @@ with gr.Blocks(css="""
116
  result = gr.Textbox(label="Submission Status")
117
 
118
  submit_btn.click(
119
- submit_evaluation,
120
  inputs=[model_name, submission_name, github_url],
121
  outputs=result
122
  )
@@ -126,11 +132,14 @@ with gr.Blocks(css="""
126
  status_btn = gr.Button("Check Status")
127
  status_output = gr.JSON(label="Status")
128
 
 
 
 
 
129
  status_btn.click(
130
- check_task_status,
131
  inputs=task_id,
132
  outputs=status_output
133
  )
134
 
135
- if __name__ == "__main__":
136
- demo.launch()
 
8
 
9
  logging.basicConfig(level=logging.INFO)
10
 
 
11
  QUEUE_SPACE_URL = os.getenv(
12
  'QUEUE_SPACE_URL',
13
  'https://koellabs-ipa-transcription-en-queue.hf.space/api'
 
15
 
16
  def load_leaderboard_data():
17
  try:
18
+ response = requests.get(f"{QUEUE_SPACE_URL}/leaderboard", timeout=10)
19
  logging.info(f"Leaderboard request URL: {QUEUE_SPACE_URL}/leaderboard")
20
  response.raise_for_status()
21
  return pd.DataFrame(response.json())
 
40
 
41
  return display_df.sort_values("Average PER ⬇️")
42
 
43
+ def create_html_table(df):
44
+ return df.to_html(escape=False, index=False, classes="styled-table")
45
+
46
  def submit_evaluation(model_name, submission_name, github_url):
47
  if not model_name or not submission_name:
48
  return "⚠️ Please provide both model name and submission name."
 
55
  }
56
 
57
  try:
58
+ response = requests.post(
59
+ f"{QUEUE_SPACE_URL}/evaluate",
60
+ json=request_data,
61
+ timeout=10
62
+ )
63
  logging.info(f"Submit request URL: {QUEUE_SPACE_URL}/evaluate")
64
  response.raise_for_status()
65
  task_id = response.json()["task_id"]
 
71
  if not task_id:
72
  return "Please enter a task ID"
73
  try:
74
+ response = requests.get(
75
+ f"{QUEUE_SPACE_URL}/tasks/{task_id}",
76
+ timeout=10
77
+ )
78
  logging.info(f"Status check URL: {QUEUE_SPACE_URL}/tasks/{task_id}")
79
  response.raise_for_status()
80
  return response.json()
81
  except requests.RequestException as e:
82
  return f"Error checking status: {str(e)}"
83
 
 
 
 
84
  with gr.Blocks(css="""
85
  .styled-table {
86
  width: 100%;
 
110
  leaderboard_html = gr.HTML(create_html_table(format_leaderboard_df(load_leaderboard_data())))
111
  refresh_btn = gr.Button("🔄 Refresh")
112
  refresh_btn.click(
113
+ lambda: gr.HTML.update(value=create_html_table(format_leaderboard_df(load_leaderboard_data()))),
114
  outputs=leaderboard_html
115
  )
116
 
 
122
  result = gr.Textbox(label="Submission Status")
123
 
124
  submit_btn.click(
125
+ fn=submit_evaluation,
126
  inputs=[model_name, submission_name, github_url],
127
  outputs=result
128
  )
 
132
  status_btn = gr.Button("Check Status")
133
  status_output = gr.JSON(label="Status")
134
 
135
+ # Use a simple function wrapper to ensure direct HTTP request
136
+ def check_status_wrapper(task_id):
137
+ return check_task_status(task_id)
138
+
139
  status_btn.click(
140
+ fn=check_status_wrapper,
141
  inputs=task_id,
142
  outputs=status_output
143
  )
144
 
145
+ demo.launch()