Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import numpy as np
|
|
| 4 |
import librosa
|
| 5 |
from torchmetrics.functional.audio.nisqa import non_intrusive_speech_quality_assessment as tm_nisqa
|
| 6 |
import spaces
|
|
|
|
| 7 |
|
| 8 |
SR = 16000
|
| 9 |
|
|
@@ -52,15 +53,18 @@ def predict_nisqa(audio):
|
|
| 52 |
("Loudness", loudness, label_dim(loudness), explain_dim("Loudness")),
|
| 53 |
]
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
with gr.Blocks(title="NISQA Speech Quality (MOS) Demo") as demo:
|
| 66 |
gr.Markdown(
|
|
@@ -71,27 +75,19 @@ with gr.Blocks(title="NISQA Speech Quality (MOS) Demo") as demo:
|
|
| 71 |
**Dimensions:** higher = fewer issues in that aspect.
|
| 72 |
"""
|
| 73 |
)
|
| 74 |
-
audio = gr.Audio(sources=["
|
| 75 |
btn = gr.Button("Predict")
|
| 76 |
|
| 77 |
-
out_table = gr.Dataframe(
|
| 78 |
|
| 79 |
bars = gr.BarPlot(
|
| 80 |
x="Metric", y="Score",
|
| 81 |
y_lim=(0, 5),
|
| 82 |
-
|
| 83 |
-
width=0.6,
|
| 84 |
interactive=False,
|
| 85 |
-
label="Scores (0–5, higher = better)"
|
| 86 |
)
|
| 87 |
|
| 88 |
-
|
| 89 |
-
import pandas as pd
|
| 90 |
-
df = pd.DataFrame({"Metric": list(bars_dict.keys()), "Score": list(bars_dict.values())})
|
| 91 |
-
return table_dict, df
|
| 92 |
-
|
| 93 |
-
btn.click(fn=predict_nisqa, inputs=audio, outputs=[out_table, bars], postprocess=False)\
|
| 94 |
-
.then(fn=_bars_to_df, inputs=[out_table, bars], outputs=[out_table, bars])
|
| 95 |
|
| 96 |
if __name__ == "__main__":
|
| 97 |
demo.launch()
|
|
|
|
| 4 |
import librosa
|
| 5 |
from torchmetrics.functional.audio.nisqa import non_intrusive_speech_quality_assessment as tm_nisqa
|
| 6 |
import spaces
|
| 7 |
+
import pandas as pd
|
| 8 |
|
| 9 |
SR = 16000
|
| 10 |
|
|
|
|
| 53 |
("Loudness", loudness, label_dim(loudness), explain_dim("Loudness")),
|
| 54 |
]
|
| 55 |
|
| 56 |
+
df_table = pd.DataFrame(
|
| 57 |
+
{
|
| 58 |
+
"Metric": [m[0] for m in metrics],
|
| 59 |
+
"Score": [round(float(m[1]), 3) for m in metrics],
|
| 60 |
+
"Label": [m[2] for m in metrics],
|
| 61 |
+
"Notes": [m[3] for m in metrics],
|
| 62 |
+
}
|
| 63 |
+
)
|
| 64 |
+
df_bars = pd.DataFrame(
|
| 65 |
+
{"Metric": [m[0] for m in metrics], "Score": [float(m[1]) for m in metrics]}
|
| 66 |
+
)
|
| 67 |
+
return df_table, df_bars
|
| 68 |
|
| 69 |
with gr.Blocks(title="NISQA Speech Quality (MOS) Demo") as demo:
|
| 70 |
gr.Markdown(
|
|
|
|
| 75 |
**Dimensions:** higher = fewer issues in that aspect.
|
| 76 |
"""
|
| 77 |
)
|
| 78 |
+
audio = gr.Audio(sources=["upload", "microphone"], type="filepath", label="Input audio")
|
| 79 |
btn = gr.Button("Predict")
|
| 80 |
|
| 81 |
+
out_table = gr.Dataframe(interactive=False, label="Results")
|
| 82 |
|
| 83 |
bars = gr.BarPlot(
|
| 84 |
x="Metric", y="Score",
|
| 85 |
y_lim=(0, 5),
|
| 86 |
+
label="Scores (0–5, higher = better)",
|
|
|
|
| 87 |
interactive=False,
|
|
|
|
| 88 |
)
|
| 89 |
|
| 90 |
+
btn.click(fn=predict_nisqa, inputs=audio, outputs=[out_table, bars])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
if __name__ == "__main__":
|
| 93 |
demo.launch()
|