HypermindLabs commited on
Commit
db5b28f
·
1 Parent(s): 4db3eab

big update

Browse files
Files changed (1) hide show
  1. app.py +22 -16
app.py CHANGED
@@ -45,17 +45,22 @@ if uploaded_file is not None:
45
  time.sleep(2.5)
46
  audio, sample_rate = librosa.load(uploaded_file, sr=None)
47
  waveform = audio
48
- while(endReached == False):
49
- input_tensor = torch.tensor(waveform[s:n]).unsqueeze(0).to(torch.float32)
 
 
 
 
 
 
 
 
 
50
  result = model(input_tensor)
51
  if np.abs(result[0][0]) > np.abs(result[0][1]):
52
  other += 1
53
  else:
54
  snore += 1
55
- s += 16000
56
- n += 16000
57
- if(n>=len(waveform)):
58
- endReached = True
59
 
60
  total = snore + other
61
  snore_percentage = (snore / total) * 100
@@ -64,16 +69,17 @@ if uploaded_file is not None:
64
  categories = ["Snore", "Other"]
65
  percentages = [snore_percentage, other_percentage]
66
 
67
- plt.figure(figsize=(8, 4))
68
- plt.barh(categories, percentages, color=['#ff0033', '#00ffee'])
69
- plt.xlabel('Percentage')
70
- plt.title('Percentage of Snoring')
71
- plt.xlim(0, 100)
72
-
73
- for i, percentage in enumerate(percentages):
74
- plt.text(percentage, i, f' {percentage:.2f}%', va='center')
75
- st.write("DONE")
76
- st.pyplot(plt)
 
77
 
78
 
79
  # # PERCENTAGE OF SNORING PLOT
 
45
  time.sleep(2.5)
46
  audio, sample_rate = librosa.load(uploaded_file, sr=None)
47
  waveform = audio
48
+ # Set the chunk size
49
+ chunk_size = 16000
50
+
51
+ # Calculate the number of chunks
52
+ num_chunks = len(waveform) // chunk_size
53
+
54
+ # Reshape the waveform into chunks
55
+ waveform_chunks = np.array_split(waveform[:num_chunks * chunk_size], num_chunks)
56
+
57
+ for chunk in waveform_chunks:
58
+ input_tensor = torch.tensor(chunk).unsqueeze(0).to(torch.float32)
59
  result = model(input_tensor)
60
  if np.abs(result[0][0]) > np.abs(result[0][1]):
61
  other += 1
62
  else:
63
  snore += 1
 
 
 
 
64
 
65
  total = snore + other
66
  snore_percentage = (snore / total) * 100
 
69
  categories = ["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