Spaces:
Runtime error
Runtime error
AbdullaShafeeg
commited on
Commit
·
99cbfbc
1
Parent(s):
063e974
app update
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ from st_audiorec import st_audiorec
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
import sounddevice as sd
|
5 |
import numpy as np
|
|
|
|
|
6 |
|
7 |
# Session state
|
8 |
if 'text' not in st.session_state:
|
@@ -40,33 +42,43 @@ with st.expander('About this App'):
|
|
40 |
how much they are snoring during their sleep.
|
41 |
''')
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
# col3.button('Stop', on_click=stop_monitoring)
|
46 |
-
# record_button = col3.button('Monitor')
|
47 |
wav_audio_data = st_audiorec()
|
48 |
if wav_audio_data is not None:
|
49 |
np_wav = np.frombuffer(wav_audio_data, dtype=np.int16)
|
50 |
-
time_axis = np.linspace(0, len(np_wav) / 16000, num=len(np_wav))
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
st.pyplot(plt)
|
58 |
-
# if wav_audio_data is not None:
|
59 |
-
# st.audio(wav_audio_data, format=FORMAT, sample_rate=16000)
|
60 |
|
61 |
-
|
62 |
-
# audio_data.append(np.frombuffer(audio_chunk, dtype=np.int16))
|
63 |
-
|
64 |
-
# if monitoring and len(audio_chunk) >= RATE // FRAMES_PER_BUFFER:
|
65 |
-
# audio_data_chunk = np.concatenate(audio_chunk[:RATE//FRAMES_PER_BUFFER])
|
66 |
-
# print("PROCESSING BY MODEL GOES HERE")
|
67 |
-
# # if model is not None:
|
68 |
-
# # input_tensor = torch.tensor(audio_data_chunk)
|
69 |
-
# # with torch.no_grad():
|
70 |
-
# # output = model(input_tensor)
|
71 |
-
|
72 |
-
# audio_chunk = audio_chunk[1:]
|
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
import sounddevice as sd
|
5 |
import numpy as np
|
6 |
+
import pandas as pd
|
7 |
+
|
8 |
|
9 |
# Session state
|
10 |
if 'text' not in st.session_state:
|
|
|
42 |
how much they are snoring during their sleep.
|
43 |
''')
|
44 |
|
45 |
+
|
46 |
+
|
|
|
|
|
47 |
wav_audio_data = st_audiorec()
|
48 |
if wav_audio_data is not None:
|
49 |
np_wav = np.frombuffer(wav_audio_data, dtype=np.int16)
|
|
|
50 |
|
51 |
+
# PERCENTAGE OF SNORING PLOT
|
52 |
+
|
53 |
+
|
54 |
+
model = np.random.rand(4, 5)
|
55 |
+
|
56 |
+
snore = 0
|
57 |
+
other = 0
|
58 |
+
|
59 |
+
for row in model:
|
60 |
+
for element in row:
|
61 |
+
if element > 0.5:
|
62 |
+
snore += 1
|
63 |
+
else:
|
64 |
+
other += 1
|
65 |
+
|
66 |
+
total = snore + other
|
67 |
+
snore_percentage = (snore / total) * 100
|
68 |
+
other_percentage = (other / total) * 100
|
69 |
+
|
70 |
+
categories = ["Snore", "Other"]
|
71 |
+
percentages = [snore_percentage, other_percentage]
|
72 |
+
|
73 |
+
plt.figure(figsize=(8, 4))
|
74 |
+
plt.barh(categories, percentages, color=['#ff0033', '#00ffee'])
|
75 |
+
plt.xlabel('Percentage')
|
76 |
+
plt.title('Percentage of "Snore" and "Other"')
|
77 |
+
plt.xlim(0, 100)
|
78 |
+
|
79 |
+
for i, percentage in enumerate(percentages):
|
80 |
+
plt.text(percentage, i, f' {percentage:.2f}%', va='center')
|
81 |
+
|
82 |
st.pyplot(plt)
|
|
|
|
|
83 |
|
84 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|