szz1 commited on
Commit
773114d
·
verified ·
1 Parent(s): 92648cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -10
app.py CHANGED
@@ -2,21 +2,41 @@ import gradio as gr
2
  import pandas as pd
3
  import requests
4
  import io
 
5
 
6
- # google sheets CSV URL
7
  CSV_URL = "https://docs.google.com/spreadsheets/d/e/2PACX-1vSDnQu-3AayffhorlrMi-w_RO3grUbd04-zav0L6ctYjbO7lx0Wr0BCFJo1_cS6H9r3ozcEh4Q7D9h3/pub?output=csv"
8
-
9
  # fetch data from google sheets
10
  def fetch_leaderboard_data():
11
  try:
12
  response = requests.get(CSV_URL)
13
  response.raise_for_status()
14
  data = pd.read_csv(io.StringIO(response.text))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  return data
 
16
  except Exception as e:
17
  print(f"Error fetching data: {e}")
18
  return pd.DataFrame({"Error": ["Unable to fetch data"]})
19
 
 
20
  # title for the leaderboard
21
  title = """
22
  <center>
@@ -25,20 +45,28 @@ title = """
25
  </center>
26
  """
27
 
 
 
 
 
28
  # gradio app
29
  def create_gradio_app():
30
  with gr.Blocks(theme="gradio/soft") as app:
31
- # gr.HTML(title)
32
- leaderboard = gr.DataFrame(
33
- value=fetch_leaderboard_data(),
34
- interactive=False,
35
- label="Leaderboard",
36
- )
37
- refresh_button = gr.Button("Refresh Leaderboard")
 
 
 
 
38
  refresh_button.click(lambda: fetch_leaderboard_data(), outputs=leaderboard)
39
  return app
40
 
41
- # launch Gradio app
42
  def run_gradio_app():
43
  app = create_gradio_app()
44
  app.launch(server_name="0.0.0.0", server_port=7860, share=True)
 
2
  import pandas as pd
3
  import requests
4
  import io
5
+ from datetime import datetime
6
 
7
+ # csv file
8
  CSV_URL = "https://docs.google.com/spreadsheets/d/e/2PACX-1vSDnQu-3AayffhorlrMi-w_RO3grUbd04-zav0L6ctYjbO7lx0Wr0BCFJo1_cS6H9r3ozcEh4Q7D9h3/pub?output=csv"
 
9
  # fetch data from google sheets
10
  def fetch_leaderboard_data():
11
  try:
12
  response = requests.get(CSV_URL)
13
  response.raise_for_status()
14
  data = pd.read_csv(io.StringIO(response.text))
15
+
16
+ # Normalize column names (lowercase & strip spaces)
17
+ data.columns = data.columns.str.strip().str.lower()
18
+
19
+ # Ensure "Rank" is treated as a number for sorting
20
+ if 'rank' in data.columns:
21
+ data['rank'] = pd.to_numeric(data['rank'], errors='coerce')
22
+
23
+ # Handle date parsing (optional)
24
+ if 'date and time' in data.columns:
25
+ data['date and time'] = pd.to_datetime(data['date and time'], errors='coerce')
26
+
27
+ # Sort by rank (ascending order)
28
+ data = data.sort_values(by='rank', ascending=True)
29
+
30
+ # Capitalize column names before returning
31
+ data.columns = data.columns.str.title()
32
+
33
  return data
34
+
35
  except Exception as e:
36
  print(f"Error fetching data: {e}")
37
  return pd.DataFrame({"Error": ["Unable to fetch data"]})
38
 
39
+
40
  # title for the leaderboard
41
  title = """
42
  <center>
 
45
  </center>
46
  """
47
 
48
+ description = """
49
+ <p><b>Important:</b> The leaderboard only shows results from registered teams. Only the last submission from each team in the previous day will be evaluated.</p>
50
+ """
51
+
52
  # gradio app
53
  def create_gradio_app():
54
  with gr.Blocks(theme="gradio/soft") as app:
55
+ # gr.HTML(title)
56
+ gr.HTML(description)
57
+
58
+ with gr.Column():
59
+ refresh_button = gr.Button("Refresh Leaderboard")
60
+ leaderboard = gr.DataFrame(
61
+ value=fetch_leaderboard_data(),
62
+ interactive=False,
63
+ label="Leaderboard",
64
+ )
65
+
66
  refresh_button.click(lambda: fetch_leaderboard_data(), outputs=leaderboard)
67
  return app
68
 
69
+ # launch gradio app
70
  def run_gradio_app():
71
  app = create_gradio_app()
72
  app.launch(server_name="0.0.0.0", server_port=7860, share=True)