AbdullaShafeeg commited on
Commit
26e6e62
·
1 Parent(s): 8176b6f

big update

Browse files
Files changed (1) hide show
  1. app.py +11 -18
app.py CHANGED
@@ -40,24 +40,10 @@ st.title('Real-Time Snore Detection App 😴')
40
 
41
  uploaded_file = st.file_uploader("Upload Sample", type=["wav"])
42
  if uploaded_file is not None:
43
- st.write("Saving File.....")
44
  audio = pydub.AudioSegment.from_wav(uploaded_file)
45
- audio.export(uploaded_file.name, format='wav')
46
- time.sleep(2)
47
- st.write("File Saved!")
48
-
49
-
50
-
51
- # PERCENTAGE OF SNORING PLOT
52
-
53
-
54
-
55
- if st.button("Analyse"):
56
- filename = uploaded_file.name
57
- cwdir = os.getcwd()
58
- file_path = os.path.join(cwdir, filename)
59
- while(endReached==False):
60
- sr, waveform = wavfile.read(uploaded_file.name)
61
  input_tensor = torch.tensor(waveform[s:n]).unsqueeze(0).to(torch.float32)
62
  result = model(input_tensor)
63
  if np.abs(result[0][0]) > np.abs(result[0][1]):
@@ -66,8 +52,9 @@ if st.button("Analyse"):
66
  snore += 1
67
  s += 16000
68
  n += 16000
69
- if(n >= len(waveform)):
70
  endReached = True
 
71
  total = snore + other
72
  snore_percentage = (snore / total) * 100
73
  other_percentage = (other / total) * 100
@@ -85,6 +72,12 @@ if st.button("Analyse"):
85
  plt.text(percentage, i, f' {percentage:.2f}%', va='center')
86
  st.write("DONE")
87
  st.pyplot(plt)
 
 
 
 
 
 
88
 
89
 
90
 
 
40
 
41
  uploaded_file = st.file_uploader("Upload Sample", type=["wav"])
42
  if uploaded_file is not None:
 
43
  audio = pydub.AudioSegment.from_wav(uploaded_file)
44
+ audio_data = np.array(audio.get_array_of_samples())
45
+ waveform= audio_data
46
+ while(endReached == False):
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  input_tensor = torch.tensor(waveform[s:n]).unsqueeze(0).to(torch.float32)
48
  result = model(input_tensor)
49
  if np.abs(result[0][0]) > np.abs(result[0][1]):
 
52
  snore += 1
53
  s += 16000
54
  n += 16000
55
+ if(n>=len(waveform)):
56
  endReached = True
57
+
58
  total = snore + other
59
  snore_percentage = (snore / total) * 100
60
  other_percentage = (other / total) * 100
 
72
  plt.text(percentage, i, f' {percentage:.2f}%', va='center')
73
  st.write("DONE")
74
  st.pyplot(plt)
75
+
76
+
77
+ # # PERCENTAGE OF SNORING PLOT
78
+
79
+
80
+
81
 
82
 
83