emwebaze commited on
Commit
35080ea
·
verified ·
1 Parent(s): c7301b2

Initial upload app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -0
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import json
4
+
5
+ def process_df(df):
6
+ # Set the current date and time
7
+ df['date'] = pd.Timestamp.now().strftime('%Y-%m-%d %H:%M')
8
+
9
+ # Create clickable links in the "Model" column
10
+ df['Model'] = df.apply(lambda x: f'<a href="{x["Link"]}" target="_blank">{x["Model"]}</a>', axis=1)
11
+
12
+ # Drop the "Link" column
13
+ df = df.drop(['Link'], axis=1)
14
+
15
+ # Convert columns to float
16
+ cols = df.columns.drop(['Model', 'date'])
17
+ df[cols] = df[cols].astype(float)
18
+
19
+ # Highlight the minimum values in the columns
20
+ styled_df = df.style.highlight_min(color='lightgreen', axis=0, subset=cols)
21
+
22
+ return styled_df
23
+
24
+ def get_eval(jsonfile):
25
+ global leaderboard_df
26
+
27
+ # Load JSON data
28
+ data = json.load(open(jsonfile))
29
+
30
+ # Convert JSON data to DataFrame
31
+ df = pd.DataFrame.from_dict(data, orient='columns')
32
+
33
+ # Concatenate with the existing leaderboard
34
+ leaderboard_df = pd.concat([leaderboard_df, df], ignore_index=True)
35
+
36
+ # Process the dataframe
37
+ df = process_df(leaderboard_df)
38
+
39
+ return df
40
+
41
+ def refresh_leaderboard():
42
+ global leaderboard_df
43
+ if len(leaderboard_df) == 0:
44
+ return leaderboard_df
45
+ else:
46
+ return process_df(leaderboard_df)
47
+
48
+ # Initialize an empty dataframe for the leaderboard
49
+ columns = ['Model', 'date', 'ucfd_eng', 'ucfd_lug',
50
+ 'sema_eng', 'sema_lug', 'trac_fm_lug']
51
+ leaderboard_df = pd.DataFrame(columns=columns)
52
+
53
+ # Create Gradio interface
54
+ block = gr.Blocks()
55
+
56
+ with block:
57
+ gr.Markdown("## Leaderboard for Sunbird AI ASR")
58
+
59
+ with gr.Row():
60
+ input_json = gr.UploadButton("Upload a JSON file", file_count="single", scale=0)
61
+
62
+ with gr.Tabs():
63
+ with gr.TabItem("ASR Leaderboard"):
64
+ with gr.Row():
65
+ data = gr.DataFrame(datatype="markdown")
66
+
67
+ input_json.upload(get_eval, inputs=input_json, outputs=data)
68
+
69
+ # Running the function on page load in addition to when the button is clicked
70
+ block.load(refresh_leaderboard, inputs=None, outputs=data)
71
+
72
+ block.launch(share=True)