Spaces:
Runtime error
Runtime error
Commit
·
b75a31b
1
Parent(s):
6f7d7a7
important bug fixed
Browse files
app.py
CHANGED
@@ -28,15 +28,11 @@ model = load_model()
|
|
28 |
def process_data(waveform_chunks):
|
29 |
snore = 0
|
30 |
other = 0
|
31 |
-
st.write("Reached stage 4")
|
32 |
for chunk in waveform_chunks:
|
33 |
-
|
34 |
-
|
35 |
-
st.write("Reached stage 6")
|
36 |
-
st.write(input_tensor.shape)
|
37 |
result = model(input_tensor)
|
38 |
-
|
39 |
-
st.write(result)
|
40 |
if np.abs(result[0][0]) > np.abs(result[0][1]):
|
41 |
other += 1
|
42 |
else:
|
@@ -59,18 +55,11 @@ st.title('Real-Time Snore Detection App 😴')
|
|
59 |
uploaded_file = st.file_uploader("Upload Sample", type=["wav"])
|
60 |
if uploaded_file is not None:
|
61 |
st.write("Analsysing...")
|
62 |
-
|
63 |
-
|
64 |
-
waveform = audio
|
65 |
-
# Set the chunk size
|
66 |
chunk_size = 16000
|
67 |
-
|
68 |
-
|
69 |
-
num_chunks = len(waveform) // chunk_size
|
70 |
-
|
71 |
-
# Reshape the waveform into chunks
|
72 |
-
waveform_chunks = np.array_split(waveform[:num_chunks * chunk_size], num_chunks)
|
73 |
-
st.write("Reached stage 3")
|
74 |
snore, other = process_data(waveform_chunks)
|
75 |
|
76 |
total = snore + other
|
@@ -81,16 +70,16 @@ if uploaded_file is not None:
|
|
81 |
percentages = [snore_percentage, other_percentage]
|
82 |
|
83 |
st.write(f'Snore Percentage: {snore_percentage}')
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
|
95 |
|
96 |
# # PERCENTAGE OF SNORING PLOT
|
|
|
28 |
def process_data(waveform_chunks):
|
29 |
snore = 0
|
30 |
other = 0
|
|
|
31 |
for chunk in waveform_chunks:
|
32 |
+
input_tensor = torch.tensor(chunk).unsqueeze(0).to(torch.float32)
|
33 |
+
# st.write(input_tensor[0][98])
|
|
|
|
|
34 |
result = model(input_tensor)
|
35 |
+
# st.write(result)
|
|
|
36 |
if np.abs(result[0][0]) > np.abs(result[0][1]):
|
37 |
other += 1
|
38 |
else:
|
|
|
55 |
uploaded_file = st.file_uploader("Upload Sample", type=["wav"])
|
56 |
if uploaded_file is not None:
|
57 |
st.write("Analsysing...")
|
58 |
+
audio_bytes = uploaded_file.getvalue()
|
59 |
+
audio_array = np.frombuffer(audio_bytes, dtype=np.int16)
|
|
|
|
|
60 |
chunk_size = 16000
|
61 |
+
num_chunks = len(audio_array) // chunk_size
|
62 |
+
waveform_chunks = np.array_split(audio_array[:num_chunks * chunk_size], num_chunks)
|
|
|
|
|
|
|
|
|
|
|
63 |
snore, other = process_data(waveform_chunks)
|
64 |
|
65 |
total = snore + other
|
|
|
70 |
percentages = [snore_percentage, other_percentage]
|
71 |
|
72 |
st.write(f'Snore Percentage: {snore_percentage}')
|
73 |
+
plt.figure(figsize=(8, 4))
|
74 |
+
plt.barh(categories, percentages, color=['#ff0033', '#00ffee'])
|
75 |
+
plt.xlabel('Percentage')
|
76 |
+
plt.title('Percentage of Snoring')
|
77 |
+
plt.xlim(0, 100)
|
78 |
+
|
79 |
+
for i, percentage in enumerate(percentages):
|
80 |
+
plt.text(percentage, i, f' {percentage:.2f}%', va='center')
|
81 |
+
st.write("DONE")
|
82 |
+
st.pyplot(plt)
|
83 |
|
84 |
|
85 |
# # PERCENTAGE OF SNORING PLOT
|