Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import pandas as pd
|
|
| 3 |
import collections
|
| 4 |
import scipy.signal
|
| 5 |
import numpy as np
|
|
|
|
| 6 |
from functools import partial
|
| 7 |
from openwakeword.model import Model
|
| 8 |
|
|
@@ -43,28 +44,32 @@ def process_audio(audio, state=collections.defaultdict(partial(collections.deque
|
|
| 43 |
# Average last few frames for smoother display
|
| 44 |
scores.append(np.mean(list(state[key])))
|
| 45 |
|
| 46 |
-
# Create dataframe for bar plot
|
| 47 |
-
df = pd.DataFrame({
|
| 48 |
-
"Model": model_names,
|
| 49 |
-
"Score": scores
|
| 50 |
-
})
|
| 51 |
-
|
| 52 |
# Sort by score for better visibility
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
-
plot = gr.BarPlot(
|
| 57 |
-
value=df,
|
| 58 |
-
x="Model",
|
| 59 |
-
y="Score",
|
| 60 |
-
y_lim=[0, 1],
|
| 61 |
-
width=700,
|
| 62 |
-
height=400,
|
| 63 |
-
x_title="",
|
| 64 |
-
y_title="Detection Score"
|
| 65 |
-
)
|
| 66 |
|
| 67 |
-
return
|
| 68 |
|
| 69 |
# Create Gradio interface and launch
|
| 70 |
desc = """This is a demo of the pre-trained models included in the latest release
|
|
@@ -94,7 +99,7 @@ gr_int = gr.Interface(
|
|
| 94 |
"state"
|
| 95 |
],
|
| 96 |
outputs=[
|
| 97 |
-
gr.
|
| 98 |
"state"
|
| 99 |
],
|
| 100 |
live=True
|
|
|
|
| 3 |
import collections
|
| 4 |
import scipy.signal
|
| 5 |
import numpy as np
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
from functools import partial
|
| 8 |
from openwakeword.model import Model
|
| 9 |
|
|
|
|
| 44 |
# Average last few frames for smoother display
|
| 45 |
scores.append(np.mean(list(state[key])))
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
# Sort by score for better visibility
|
| 48 |
+
sorted_indices = np.argsort(scores)[::-1]
|
| 49 |
+
model_names = [model_names[i] for i in sorted_indices]
|
| 50 |
+
scores = [scores[i] for i in sorted_indices]
|
| 51 |
+
|
| 52 |
+
# Create matplotlib figure
|
| 53 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 54 |
+
|
| 55 |
+
# Create horizontal bar chart for better label readability
|
| 56 |
+
bars = ax.barh(model_names, scores, color='#4A90E2')
|
| 57 |
+
|
| 58 |
+
# Customize appearance
|
| 59 |
+
ax.set_xlim(0, 1)
|
| 60 |
+
ax.set_xlabel('Detection Score', fontsize=12)
|
| 61 |
+
ax.set_title('Real-time Wake Word Detection', fontsize=14, fontweight='bold')
|
| 62 |
+
ax.grid(axis='x', alpha=0.3)
|
| 63 |
+
|
| 64 |
+
# Add score labels on bars
|
| 65 |
+
for i, (bar, score) in enumerate(zip(bars, scores)):
|
| 66 |
+
if score > 0.05:
|
| 67 |
+
ax.text(score + 0.02, i, f'{score:.3f}',
|
| 68 |
+
va='center', fontsize=9)
|
| 69 |
|
| 70 |
+
plt.tight_layout()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
+
return fig, state
|
| 73 |
|
| 74 |
# Create Gradio interface and launch
|
| 75 |
desc = """This is a demo of the pre-trained models included in the latest release
|
|
|
|
| 99 |
"state"
|
| 100 |
],
|
| 101 |
outputs=[
|
| 102 |
+
gr.Plot(show_label=False),
|
| 103 |
"state"
|
| 104 |
],
|
| 105 |
live=True
|