HyperMind-Labs commited on
Commit
f758117
·
1 Parent(s): cdc9234
Files changed (1) hide show
  1. app.py +41 -30
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
- 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
 
 
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