Spaces:
Runtime error
Runtime error
Commit
·
8583d6e
1
Parent(s):
8f954b0
v1
Browse files
app.py
CHANGED
@@ -22,7 +22,6 @@ import torchaudio.transforms as T
|
|
22 |
n_fft = 1024
|
23 |
win_length = None
|
24 |
hop_length = 32
|
25 |
-
|
26 |
# Input tensor shape was ([1,16000])
|
27 |
class SnoreNet(nn.Module):
|
28 |
def __init__(self):
|
@@ -43,12 +42,9 @@ class SnoreNet(nn.Module):
|
|
43 |
output = self.fc2(output)
|
44 |
output = torch.abs(self.logs1(output))
|
45 |
return output
|
46 |
-
|
47 |
model = SnoreNet()
|
48 |
model.load_state_dict(torch.load('snoreNetv1.pt'))
|
49 |
model.eval()
|
50 |
-
|
51 |
-
|
52 |
# Audio parameters
|
53 |
def process_data(waveform_chunks):
|
54 |
snore = 0
|
@@ -64,7 +60,6 @@ def process_data(waveform_chunks):
|
|
64 |
else:
|
65 |
snore += 1
|
66 |
return snore, other
|
67 |
-
|
68 |
st.sidebar.markdown(
|
69 |
"""
|
70 |
<div align="justify">
|
@@ -77,7 +72,6 @@ st.sidebar.markdown(
|
|
77 |
unsafe_allow_html=True,
|
78 |
)
|
79 |
st.title('Real-Time Snore Detection App 😴')
|
80 |
-
|
81 |
uploaded_file = st.file_uploader("Upload Sample", type=["wav"])
|
82 |
if uploaded_file is not None:
|
83 |
st.write("Analsysing...")
|
@@ -87,34 +81,17 @@ if uploaded_file is not None:
|
|
87 |
num_chunks = len(audio_array) // chunk_size
|
88 |
waveform_chunks = np.array_split(audio_array[:num_chunks * chunk_size], num_chunks)
|
89 |
snore, other = process_data(waveform_chunks)
|
90 |
-
|
91 |
total = snore + other
|
92 |
snore_percentage = (snore / total) * 100
|
93 |
other_percentage = (other / total) * 100
|
94 |
-
|
95 |
-
|
96 |
-
percentages = [snore_percentage, other_percentage]
|
97 |
-
|
98 |
-
st.write(f'Snore Percentage: {snore_percentage}')
|
99 |
plt.figure(figsize=(8, 4))
|
100 |
-
plt.barh(categories, percentages, color=['#ff0033'
|
101 |
plt.xlabel('Percentage')
|
102 |
plt.title('Percentage of Snoring')
|
103 |
plt.xlim(0, 100)
|
104 |
-
|
105 |
for i, percentage in enumerate(percentages):
|
106 |
plt.text(percentage, i, f' {percentage:.2f}%', va='center')
|
107 |
st.write("DONE")
|
108 |
-
st.pyplot(plt)
|
109 |
-
|
110 |
-
|
111 |
-
# # PERCENTAGE OF SNORING PLOT
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
22 |
n_fft = 1024
|
23 |
win_length = None
|
24 |
hop_length = 32
|
|
|
25 |
# Input tensor shape was ([1,16000])
|
26 |
class SnoreNet(nn.Module):
|
27 |
def __init__(self):
|
|
|
42 |
output = self.fc2(output)
|
43 |
output = torch.abs(self.logs1(output))
|
44 |
return output
|
|
|
45 |
model = SnoreNet()
|
46 |
model.load_state_dict(torch.load('snoreNetv1.pt'))
|
47 |
model.eval()
|
|
|
|
|
48 |
# Audio parameters
|
49 |
def process_data(waveform_chunks):
|
50 |
snore = 0
|
|
|
60 |
else:
|
61 |
snore += 1
|
62 |
return snore, other
|
|
|
63 |
st.sidebar.markdown(
|
64 |
"""
|
65 |
<div align="justify">
|
|
|
72 |
unsafe_allow_html=True,
|
73 |
)
|
74 |
st.title('Real-Time Snore Detection App 😴')
|
|
|
75 |
uploaded_file = st.file_uploader("Upload Sample", type=["wav"])
|
76 |
if uploaded_file is not None:
|
77 |
st.write("Analsysing...")
|
|
|
81 |
num_chunks = len(audio_array) // chunk_size
|
82 |
waveform_chunks = np.array_split(audio_array[:num_chunks * chunk_size], num_chunks)
|
83 |
snore, other = process_data(waveform_chunks)
|
|
|
84 |
total = snore + other
|
85 |
snore_percentage = (snore / total) * 100
|
86 |
other_percentage = (other / total) * 100
|
87 |
+
categories = ["Snore"]
|
88 |
+
percentages = [snore_percentage]
|
|
|
|
|
|
|
89 |
plt.figure(figsize=(8, 4))
|
90 |
+
plt.barh(categories, percentages, color=['#ff0033'])
|
91 |
plt.xlabel('Percentage')
|
92 |
plt.title('Percentage of Snoring')
|
93 |
plt.xlim(0, 100)
|
|
|
94 |
for i, percentage in enumerate(percentages):
|
95 |
plt.text(percentage, i, f' {percentage:.2f}%', va='center')
|
96 |
st.write("DONE")
|
97 |
+
st.pyplot(plt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|