Update app.py
Browse files
app.py
CHANGED
@@ -1,196 +1,197 @@
|
|
1 |
-
from utils import (
|
2 |
-
update_leaderboard_multilingual,
|
3 |
-
update_leaderboard_one_vs_all,
|
4 |
-
handle_evaluation,
|
5 |
-
process_results_file,
|
6 |
-
create_html_image,
|
7 |
-
)
|
8 |
-
|
9 |
-
import
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
gr.
|
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 |
-
gr.Markdown(""
|
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 |
-
gr.Markdown("
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
gr.
|
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 |
-
df_eval.
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
gr.Markdown("
|
141 |
-
gr.Markdown("###
|
142 |
-
gr.Markdown(
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
|
|
|
1 |
+
from utils import (
|
2 |
+
update_leaderboard_multilingual,
|
3 |
+
update_leaderboard_one_vs_all,
|
4 |
+
handle_evaluation,
|
5 |
+
process_results_file,
|
6 |
+
create_html_image,
|
7 |
+
)
|
8 |
+
|
9 |
+
import os
|
10 |
+
import gradio as gr
|
11 |
+
|
12 |
+
from constants import *
|
13 |
+
|
14 |
+
if __name__ == "__main__":
|
15 |
+
|
16 |
+
with gr.Blocks() as app:
|
17 |
+
|
18 |
+
base_path = os.path.dirname(__file__)
|
19 |
+
local_image_path = os.path.join(base_path, 'open_arabic_lid_arena.png')
|
20 |
+
|
21 |
+
gr.HTML(create_html_image(local_image_path))
|
22 |
+
gr.Markdown("# 🏅 Open Arabic Dialect Identification Leaderboard")
|
23 |
+
|
24 |
+
# Multi-dialects leaderboard
|
25 |
+
with gr.Tab("Multi-dialects model leaderboard"):
|
26 |
+
gr.Markdown("""
|
27 |
+
Complete leaderboard across multiple arabic dialects.
|
28 |
+
Compare the performance of different models across various metrics such as FNR, FPR, and other clasical metrics.
|
29 |
+
"""
|
30 |
+
)
|
31 |
+
|
32 |
+
with gr.Row():
|
33 |
+
with gr.Column(scale=1):
|
34 |
+
gr.Markdown("### Select country to display")
|
35 |
+
country_selector = gr.Dropdown(
|
36 |
+
choices=supported_dialects,
|
37 |
+
value='Morocco', # Default to Morocco of course
|
38 |
+
label="Country"
|
39 |
+
)
|
40 |
+
|
41 |
+
with gr.Column(scale=2):
|
42 |
+
gr.Markdown("### Select metrics to display")
|
43 |
+
metric_checkboxes = gr.CheckboxGroup(
|
44 |
+
choices=metrics,
|
45 |
+
value=default_metrics,
|
46 |
+
label="Metrics"
|
47 |
+
)
|
48 |
+
|
49 |
+
with gr.Row():
|
50 |
+
leaderboard_table = gr.DataFrame(
|
51 |
+
interactive=False
|
52 |
+
)
|
53 |
+
|
54 |
+
gr.Markdown("</br>")
|
55 |
+
|
56 |
+
gr.Markdown("## Contribute to the Leaderboard")
|
57 |
+
gr.Markdown("""
|
58 |
+
We welcome contributions from the community!
|
59 |
+
If you have a model that you would like to see on the leaderboard, please use the 'Evaluate a model' or 'Upload your results' tabs to submit your model's performance.
|
60 |
+
Let's work together to improve Arabic dialect identification! 🚀
|
61 |
+
""")
|
62 |
+
|
63 |
+
# Dialect confusion leaderboard
|
64 |
+
with gr.Tab("Dialect confusion leaderboard"): # use to be "One-vs-All leaderboard"
|
65 |
+
|
66 |
+
gr.Markdown("""
|
67 |
+
Detailed analysis of how well models distinguish specific dialects from others.
|
68 |
+
For each target dialect, see how often models incorrectly classify other dialects as the target.
|
69 |
+
Lower `false_positive_rate` indicate better ability to identify the true dialect by
|
70 |
+
showing **how often it misclassifies other dialects as the target dialect**.
|
71 |
+
"""
|
72 |
+
)
|
73 |
+
|
74 |
+
with gr.Row():
|
75 |
+
with gr.Column(scale=1):
|
76 |
+
gr.Markdown("### Select your target language")
|
77 |
+
target_language_selector = gr.Dropdown(
|
78 |
+
choices=languages_to_display_one_vs_all,
|
79 |
+
value='Morocco', # Default to Morocco of course
|
80 |
+
label="Target Language"
|
81 |
+
)
|
82 |
+
|
83 |
+
with gr.Column(scale=2):
|
84 |
+
gr.Markdown("### Select languages to compare to")
|
85 |
+
languages_checkboxes = gr.CheckboxGroup(
|
86 |
+
choices=languages_to_display_one_vs_all,
|
87 |
+
value=default_languages,
|
88 |
+
label="Languages"
|
89 |
+
)
|
90 |
+
|
91 |
+
with gr.Row():
|
92 |
+
binary_leaderboard_table = gr.DataFrame(
|
93 |
+
interactive=False
|
94 |
+
)
|
95 |
+
|
96 |
+
|
97 |
+
with gr.Tab("Evaluate a model"):
|
98 |
+
gr.Markdown("Suggest a model to evaluate 🤗 (Supports only **Fasttext** models as SfayaLID, GlotLID, OpenLID, etc.)")
|
99 |
+
gr.Markdown("For other models, you are welcome to **submit your results** through the upload section.")
|
100 |
+
|
101 |
+
model_path = gr.Textbox(label="Model Path", placeholder='path/to/model')
|
102 |
+
model_path_bin = gr.Textbox(label=".bin filename", placeholder='model.bin')
|
103 |
+
gr.Markdown("### **⚠️ To ensure correct results, tick this when the model's labels are the iso_codes**")
|
104 |
+
use_mapping = gr.Checkbox(label="Does not map to country", value=True) # Initially enabled
|
105 |
+
eval_button = gr.Button("Evaluate", value=False) # Initially disabled
|
106 |
+
|
107 |
+
# Status message area
|
108 |
+
status_message = gr.Markdown(value="")
|
109 |
+
def update_status_message():
|
110 |
+
return "### **⚠️Evaluating... Please wait...**"
|
111 |
+
|
112 |
+
eval_button.click(update_status_message, outputs=[status_message])
|
113 |
+
|
114 |
+
eval_button.click(handle_evaluation, inputs=[model_path, model_path_bin, use_mapping], outputs=[leaderboard_table, status_message])
|
115 |
+
|
116 |
+
with gr.Tab("Upload your results"):
|
117 |
+
|
118 |
+
# Define a code block to display
|
119 |
+
code_snippet = """
|
120 |
+
```python
|
121 |
+
|
122 |
+
# Load your model
|
123 |
+
model = ... # Load your model here
|
124 |
+
|
125 |
+
# Load evaluation benchmark
|
126 |
+
eval_dataset = load_dataset("atlasia/Arabic-LID-Leaderboard", split='test').to_pandas() # do not change this line :)
|
127 |
+
|
128 |
+
# Predict labels using your model
|
129 |
+
eval_dataset['preds'] = eval_dataset['text'].apply(lambda text: predict_label(text, model)) # predict_label is a function that you need to define for your model
|
130 |
+
|
131 |
+
# now drop the columns that are not needed, i.e. 'text', 'metadata' and 'dataset_source'
|
132 |
+
df_eval = df_eval.drop(columns=['text', 'metadata', 'dataset_source'])
|
133 |
+
df_eval.to_csv('your_model_name.csv')
|
134 |
+
|
135 |
+
# submit your results: 'your_model_name.csv' to the leaderboard
|
136 |
+
|
137 |
+
```
|
138 |
+
"""
|
139 |
+
|
140 |
+
gr.Markdown("## Upload your results to the leaderboard 🚀")
|
141 |
+
gr.Markdown("### Submission guidelines: Run the test dataset on your model and save the results in a CSV file. Bellow a code snippet to help you with that.")
|
142 |
+
gr.Markdown("### Nota Bene: The One-vs-All leaderboard evaluation is currently unavailable with the csv upload but will be implemented soon. Stay tuned!")
|
143 |
+
gr.Markdown(code_snippet)
|
144 |
+
|
145 |
+
uploaded_model_name = gr.Textbox(label="Model name", placeholder='Your model/team name')
|
146 |
+
file = gr.File(label="Upload your results")
|
147 |
+
upload_button = gr.Button("Upload")
|
148 |
+
|
149 |
+
# Status message area
|
150 |
+
status_message = gr.Markdown(value="")
|
151 |
+
def update_status_message():
|
152 |
+
return "### **⚠️Evaluating... Please wait...**"
|
153 |
+
|
154 |
+
upload_button.click(update_status_message, outputs=[status_message])
|
155 |
+
|
156 |
+
upload_button.click(process_results_file, inputs=[file, uploaded_model_name], outputs=[leaderboard_table, status_message])
|
157 |
+
|
158 |
+
# Update multilangual table when any input changes
|
159 |
+
country_selector.change(
|
160 |
+
update_leaderboard_multilingual,
|
161 |
+
inputs=[country_selector, metric_checkboxes],
|
162 |
+
outputs=leaderboard_table
|
163 |
+
)
|
164 |
+
|
165 |
+
metric_checkboxes.change(
|
166 |
+
update_leaderboard_multilingual,
|
167 |
+
inputs=[country_selector, metric_checkboxes],
|
168 |
+
outputs=leaderboard_table
|
169 |
+
)
|
170 |
+
|
171 |
+
# Update binary table when any input changes
|
172 |
+
target_language_selector.change(
|
173 |
+
update_leaderboard_one_vs_all,
|
174 |
+
inputs=[target_language_selector, languages_checkboxes],
|
175 |
+
outputs=[binary_leaderboard_table, languages_checkboxes]
|
176 |
+
)
|
177 |
+
|
178 |
+
languages_checkboxes.change(
|
179 |
+
update_leaderboard_one_vs_all,
|
180 |
+
inputs=[target_language_selector, languages_checkboxes],
|
181 |
+
outputs=[binary_leaderboard_table, languages_checkboxes]
|
182 |
+
)
|
183 |
+
|
184 |
+
# Define load event to run at startup
|
185 |
+
app.load(
|
186 |
+
update_leaderboard_one_vs_all,
|
187 |
+
inputs=[target_language_selector, languages_checkboxes],
|
188 |
+
outputs=[binary_leaderboard_table, languages_checkboxes]
|
189 |
+
)
|
190 |
+
|
191 |
+
app.load(
|
192 |
+
update_leaderboard_multilingual,
|
193 |
+
inputs=[country_selector, metric_checkboxes],
|
194 |
+
outputs=leaderboard_table
|
195 |
+
)
|
196 |
+
|
197 |
+
app.launch(allowed_paths=[base_path])
|