Spaces:
Runtime error
Runtime error
AbdullaShafeeg
commited on
Commit
·
75b78d9
1
Parent(s):
63beaa0
update
Browse files
app.py
CHANGED
@@ -73,51 +73,46 @@ if wav_audio_data is not None:
|
|
73 |
with open("output.wav", 'wb') as wav_file:
|
74 |
wav_file.write(wav_make)
|
75 |
sr, waveform = wavfile.read('output.wav')
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
|
85 |
# PERCENTAGE OF SNORING PLOT
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
|
|
88 |
|
89 |
-
# waveform, sample_rate = torchaudio.load('test/0_10.wav')
|
90 |
-
# resampler = T.Resample(sample_rate, RESAMPLE_RATE, dtype=waveform.dtype)
|
91 |
-
# signal = resampler(waveform)
|
92 |
-
# signal = torch.mean(signal, dim=0, keepdim=True)
|
93 |
-
# ptl_model(signal)
|
94 |
-
|
95 |
-
# snore = 0
|
96 |
-
# other = 0
|
97 |
-
|
98 |
-
# for row in model:
|
99 |
-
# for element in row:
|
100 |
-
# if element > 0.5:
|
101 |
-
# snore += 1
|
102 |
-
# else:
|
103 |
-
# other += 1
|
104 |
-
|
105 |
-
# total = snore + other
|
106 |
-
# snore_percentage = (snore / total) * 100
|
107 |
-
# other_percentage = (other / total) * 100
|
108 |
-
|
109 |
-
# categories = ["Snore", "Other"]
|
110 |
-
# percentages = [snore_percentage, other_percentage]
|
111 |
-
|
112 |
-
# plt.figure(figsize=(8, 4))
|
113 |
-
# plt.barh(categories, percentages, color=['#ff0033', '#00ffee'])
|
114 |
-
# plt.xlabel('Percentage')
|
115 |
-
# plt.title('Percentage of "Snore" and "Other"')
|
116 |
-
# plt.xlim(0, 100)
|
117 |
-
|
118 |
-
# for i, percentage in enumerate(percentages):
|
119 |
-
# plt.text(percentage, i, f' {percentage:.2f}%', va='center')
|
120 |
-
|
121 |
-
# st.pyplot(plt)
|
122 |
|
123 |
|
|
|
73 |
with open("output.wav", 'wb') as wav_file:
|
74 |
wav_file.write(wav_make)
|
75 |
sr, waveform = wavfile.read('output.wav')
|
76 |
+
snore = 0
|
77 |
+
other = 0
|
78 |
+
s=0
|
79 |
+
n=16000
|
80 |
+
endReached = False
|
81 |
+
|
82 |
+
while(endReached==False):
|
83 |
+
input_tensor = torch.tensor(waveform[s:n]).unsqueeze(0).to(torch.float32)
|
84 |
+
result = model(input_tensor)
|
85 |
+
if np.abs(result[0][0]) > np.abs(result[0][1]):
|
86 |
+
other += 1
|
87 |
+
else:
|
88 |
+
snore += 1
|
89 |
+
s += 16000
|
90 |
+
n += 16000
|
91 |
+
if(n >= len(waveform)):
|
92 |
+
endReached = True
|
93 |
|
94 |
# PERCENTAGE OF SNORING PLOT
|
95 |
|
96 |
+
total = snore + other
|
97 |
+
snore_percentage = (snore / total) * 100
|
98 |
+
other_percentage = (other / total) * 100
|
99 |
+
|
100 |
+
categories = ["Snore", "Other"]
|
101 |
+
percentages = [snore_percentage, other_percentage]
|
102 |
+
|
103 |
+
plt.figure(figsize=(8, 4))
|
104 |
+
plt.barh(categories, percentages, color=['#ff0033', '#00ffee'])
|
105 |
+
plt.xlabel('Percentage')
|
106 |
+
plt.title('Percentage of Snoring')
|
107 |
+
plt.xlim(0, 100)
|
108 |
+
|
109 |
+
for i, percentage in enumerate(percentages):
|
110 |
+
plt.text(percentage, i, f' {percentage:.2f}%', va='center')
|
111 |
+
|
112 |
+
st.pyplot(plt)
|
113 |
+
|
114 |
|
115 |
+
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
|
118 |
|