Spaces:
Build error
Build error
plots made better + plot per language
Browse files
app.py
CHANGED
|
@@ -1,6 +1,3 @@
|
|
| 1 |
-
from ctypes.wintypes import LANGID
|
| 2 |
-
from curses import meta
|
| 3 |
-
from email.policy import default
|
| 4 |
import pycountry
|
| 5 |
import os
|
| 6 |
import csv
|
|
@@ -182,12 +179,14 @@ def get_metadata_json(path):
|
|
| 182 |
|
| 183 |
|
| 184 |
def plot_bar(value,name,x_name,y_name,title):
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
|
|
|
|
|
|
| 191 |
|
| 192 |
def get_metadata_of_dataset():
|
| 193 |
repo.git_pull()
|
|
@@ -268,6 +267,10 @@ __Note:__ You should record all numbers shown till the end. It does not count i
|
|
| 268 |
"""
|
| 269 |
|
| 270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
# Interface design begins
|
| 272 |
block = gr.Blocks(css=BLOCK_CSS)
|
| 273 |
with block:
|
|
@@ -298,7 +301,7 @@ with block:
|
|
| 298 |
|
| 299 |
with gr.TabItem('Dashboard') as listen_tab:
|
| 300 |
|
| 301 |
-
gr.Markdown("Statistics on the recordings contributed. You can find
|
| 302 |
display_html = gr.HTML("""<div style="color: green">
|
| 303 |
<p> ⌛ Please wait. Loading dashboard... </p>
|
| 304 |
</div>
|
|
@@ -307,6 +310,10 @@ with block:
|
|
| 307 |
metadata_all = get_metadata_of_dataset()
|
| 308 |
|
| 309 |
def show_records():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
langs=[m['language_name'] for m in metadata_all]
|
| 311 |
all_genders = [m['gender'] for m in metadata_all
|
| 312 |
]
|
|
@@ -318,8 +325,7 @@ with block:
|
|
| 318 |
html = f"""<div class="infoPoint">
|
| 319 |
<h1> Hooray! We have collected {len(metadata_all)} samples!</h1>
|
| 320 |
"""
|
| 321 |
-
|
| 322 |
-
return html,plt_
|
| 323 |
|
| 324 |
|
| 325 |
|
|
@@ -343,17 +349,21 @@ with block:
|
|
| 343 |
plot_digits = gr.Plot(type="matplotlib")
|
| 344 |
plot_gender = gr.Plot(type="matplotlib")
|
| 345 |
|
|
|
|
|
|
|
|
|
|
| 346 |
def plot_metadata_for_language():
|
| 347 |
plt_digits = plot_bar(digits_count_for_language,digits_name_for_language,'Number of audio samples',"Digit",f"Distribution of audio samples over digits for {language.upper()} ")
|
| 348 |
-
plt_gender = plot_bar(gender_count_for_language,gender_name_for_language,'Number of audio samples',"Gender",f"Distribution of audio samples over
|
| 349 |
return plt_digits, plt_gender
|
| 350 |
|
| 351 |
-
|
| 352 |
-
|
|
|
|
| 353 |
|
| 354 |
|
| 355 |
#listen = gr.Button("Listen")
|
| 356 |
-
listen_tab.select(show_records,inputs=[],outputs=[display_html,plot])
|
| 357 |
|
| 358 |
|
| 359 |
# Have a list of the languages. lang
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import pycountry
|
| 2 |
import os
|
| 3 |
import csv
|
|
|
|
| 179 |
|
| 180 |
|
| 181 |
def plot_bar(value,name,x_name,y_name,title):
|
| 182 |
+
fig, ax = plt.subplots(figsize=(10,4),tight_layout=True)
|
| 183 |
+
|
| 184 |
+
ax.set(xlabel=x_name, ylabel=y_name,title=title)
|
| 185 |
+
|
| 186 |
+
ax.barh(name, value)
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
return ax.figure
|
| 190 |
|
| 191 |
def get_metadata_of_dataset():
|
| 192 |
repo.git_pull()
|
|
|
|
| 267 |
"""
|
| 268 |
|
| 269 |
|
| 270 |
+
|
| 271 |
+
PLOTS_FOR_GRADIO = []
|
| 272 |
+
FUNCTIONS_FOR_GRADIO = []
|
| 273 |
+
|
| 274 |
# Interface design begins
|
| 275 |
block = gr.Blocks(css=BLOCK_CSS)
|
| 276 |
with block:
|
|
|
|
| 301 |
|
| 302 |
with gr.TabItem('Dashboard') as listen_tab:
|
| 303 |
|
| 304 |
+
gr.Markdown("Statistics on the recordings contributed. You can find the dataset <a href='https://huggingface.co/datasets/chrisjay/crowd-speech-africa' target='blank'>here</a>.")
|
| 305 |
display_html = gr.HTML("""<div style="color: green">
|
| 306 |
<p> ⌛ Please wait. Loading dashboard... </p>
|
| 307 |
</div>
|
|
|
|
| 310 |
metadata_all = get_metadata_of_dataset()
|
| 311 |
|
| 312 |
def show_records():
|
| 313 |
+
global PLOTS_FOR_GRADIO
|
| 314 |
+
global FUNCTIONS_FOR_GRADIO
|
| 315 |
+
|
| 316 |
+
assert len(PLOTS_FOR_GRADIO) == len(FUNCTIONS_FOR_GRADIO), f"Function output and gradio plots must be the same length! \n Found: function => {len(FUNCTIONS_FOR_GRADIO)} and gradio plots => {len(PLOTS_FOR_GRADIO)}."
|
| 317 |
langs=[m['language_name'] for m in metadata_all]
|
| 318 |
all_genders = [m['gender'] for m in metadata_all
|
| 319 |
]
|
|
|
|
| 325 |
html = f"""<div class="infoPoint">
|
| 326 |
<h1> Hooray! We have collected {len(metadata_all)} samples!</h1>
|
| 327 |
"""
|
| 328 |
+
return [html,plt_]+FUNCTIONS_FOR_GRADIO
|
|
|
|
| 329 |
|
| 330 |
|
| 331 |
|
|
|
|
| 349 |
plot_digits = gr.Plot(type="matplotlib")
|
| 350 |
plot_gender = gr.Plot(type="matplotlib")
|
| 351 |
|
| 352 |
+
PLOTS_FOR_GRADIO.append(plot_digits)
|
| 353 |
+
PLOTS_FOR_GRADIO.append(plot_gender)
|
| 354 |
+
|
| 355 |
def plot_metadata_for_language():
|
| 356 |
plt_digits = plot_bar(digits_count_for_language,digits_name_for_language,'Number of audio samples',"Digit",f"Distribution of audio samples over digits for {language.upper()} ")
|
| 357 |
+
plt_gender = plot_bar(gender_count_for_language,gender_name_for_language,'Number of audio samples',"Gender",f"Distribution of audio samples over gender for {language.upper()}")
|
| 358 |
return plt_digits, plt_gender
|
| 359 |
|
| 360 |
+
output_digits,ouput_gender = plot_metadata_for_language()
|
| 361 |
+
FUNCTIONS_FOR_GRADIO.append(output_digits)
|
| 362 |
+
FUNCTIONS_FOR_GRADIO.append(ouput_gender)
|
| 363 |
|
| 364 |
|
| 365 |
#listen = gr.Button("Listen")
|
| 366 |
+
listen_tab.select(show_records,inputs=[],outputs=[display_html,plot]+PLOTS_FOR_GRADIO)
|
| 367 |
|
| 368 |
|
| 369 |
# Have a list of the languages. lang
|