Spaces:
Runtime error
Runtime error
HyperMind-Labs
commited on
Commit
·
f758117
1
Parent(s):
cdc9234
test1
Browse files
app.py
CHANGED
@@ -4,7 +4,12 @@ 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:
|
@@ -47,38 +52,44 @@ with st.expander('About this App'):
|
|
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 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
|
|
|
4 |
import sounddevice as sd
|
5 |
import numpy as np
|
6 |
import pandas as pd
|
7 |
+
import torch
|
8 |
+
import torchaudio
|
9 |
|
10 |
+
# MODEL LOADING and INITIALISATION
|
11 |
+
model = torch.jit.load("snorenetv1_small.ptl")
|
12 |
+
model.eval()
|
13 |
|
14 |
# Session state
|
15 |
if 'text' not in st.session_state:
|
|
|
52 |
wav_audio_data = st_audiorec()
|
53 |
if wav_audio_data is not None:
|
54 |
np_wav = np.frombuffer(wav_audio_data, dtype=np.int16)
|
55 |
+
input_tensor = torch.tenosr(np_wav)
|
56 |
+
st.write(input_tensor.shape)
|
57 |
# PERCENTAGE OF SNORING PLOT
|
58 |
|
59 |
|
60 |
+
|
61 |
+
# waveform, sample_rate = torchaudio.load('test/0_10.wav')
|
62 |
+
# resampler = T.Resample(sample_rate, RESAMPLE_RATE, dtype=waveform.dtype)
|
63 |
+
# signal = resampler(waveform)
|
64 |
+
# signal = torch.mean(signal, dim=0, keepdim=True)
|
65 |
+
# ptl_model(signal)
|
66 |
+
|
67 |
+
# snore = 0
|
68 |
+
# other = 0
|
69 |
+
|
70 |
+
# for row in model:
|
71 |
+
# for element in row:
|
72 |
+
# if element > 0.5:
|
73 |
+
# snore += 1
|
74 |
+
# else:
|
75 |
+
# other += 1
|
76 |
+
|
77 |
+
# total = snore + other
|
78 |
+
# snore_percentage = (snore / total) * 100
|
79 |
+
# other_percentage = (other / total) * 100
|
80 |
+
|
81 |
+
# categories = ["Snore", "Other"]
|
82 |
+
# percentages = [snore_percentage, other_percentage]
|
83 |
+
|
84 |
+
# plt.figure(figsize=(8, 4))
|
85 |
+
# plt.barh(categories, percentages, color=['#ff0033', '#00ffee'])
|
86 |
+
# plt.xlabel('Percentage')
|
87 |
+
# plt.title('Percentage of "Snore" and "Other"')
|
88 |
+
# plt.xlim(0, 100)
|
89 |
+
|
90 |
+
# for i, percentage in enumerate(percentages):
|
91 |
+
# plt.text(percentage, i, f' {percentage:.2f}%', va='center')
|
92 |
+
|
93 |
+
# st.pyplot(plt)
|
94 |
|
95 |
|