AbdullaShafeeg commited on
Commit
28cc6c6
·
1 Parent(s): 6c938cd

big update

Browse files
Files changed (1) hide show
  1. app.py +50 -40
app.py CHANGED
@@ -10,6 +10,7 @@ import wave
10
  import io
11
  from scipy.io import wavfile
12
  import pydub
 
13
 
14
  # MODEL LOADING and INITIALISATION
15
  model = torch.jit.load("snorenetv1_small.ptl")
@@ -62,46 +63,55 @@ if upload_file is not None:
62
 
63
  # with open("output.wav", 'wb') as wav_file:
64
  # wav_file.write(wav_make)
65
- audio = pydub.AudioSegment.from_wav(upload_file)
66
- audio.export(upload_file.name, format='wav')
67
- sr, waveform = wavfile.read(upload_file.name)
68
- snore = 0
69
- other = 0
70
- s=0
71
- n=16000
72
- endReached = False
73
-
74
- while(endReached==False):
75
- input_tensor = torch.tensor(waveform[s:n]).unsqueeze(0).to(torch.float32)
76
- result = model(input_tensor)
77
- if np.abs(result[0][0]) > np.abs(result[0][1]):
78
- other += 1
79
- else:
80
- snore += 1
81
- s += 16000
82
- n += 16000
83
- if(n >= len(waveform)):
84
- endReached = True
85
-
86
- # PERCENTAGE OF SNORING PLOT
87
-
88
- total = snore + other
89
- snore_percentage = (snore / total) * 100
90
- other_percentage = (other / total) * 100
91
-
92
- categories = ["Snore", "Other"]
93
- percentages = [snore_percentage, other_percentage]
94
-
95
- plt.figure(figsize=(8, 4))
96
- plt.barh(categories, percentages, color=['#ff0033', '#00ffee'])
97
- plt.xlabel('Percentage')
98
- plt.title('Percentage of Snoring')
99
- plt.xlim(0, 100)
100
-
101
- for i, percentage in enumerate(percentages):
102
- plt.text(percentage, i, f' {percentage:.2f}%', va='center')
103
-
104
- st.pyplot(plt)
 
 
 
 
 
 
 
 
 
105
 
106
 
107
 
 
10
  import io
11
  from scipy.io import wavfile
12
  import pydub
13
+ import time
14
 
15
  # MODEL LOADING and INITIALISATION
16
  model = torch.jit.load("snorenetv1_small.ptl")
 
63
 
64
  # with open("output.wav", 'wb') as wav_file:
65
  # wav_file.write(wav_make)
66
+ file_uploaded = False
67
+ if file_uploaded == False:
68
+ st.write("Uploading File.....")
69
+ audio = pydub.AudioSegment.from_wav(upload_file)
70
+ file_uploaded = True
71
+ time.sleep(2)
72
+ st.write("File Uploaded!")
73
+
74
+ if file_uploaded == True:
75
+ st.write("Analysing...")
76
+ audio.export(upload_file.name, format='wav')
77
+ sr, waveform = wavfile.read(upload_file.name)
78
+ snore = 0
79
+ other = 0
80
+ s=0
81
+ n=16000
82
+ endReached = False
83
+
84
+ while(endReached==False):
85
+ input_tensor = torch.tensor(waveform[s:n]).unsqueeze(0).to(torch.float32)
86
+ result = model(input_tensor)
87
+ if np.abs(result[0][0]) > np.abs(result[0][1]):
88
+ other += 1
89
+ else:
90
+ snore += 1
91
+ s += 16000
92
+ n += 16000
93
+ if(n >= len(waveform)):
94
+ endReached = True
95
+
96
+ # PERCENTAGE OF SNORING PLOT
97
+
98
+ total = snore + other
99
+ snore_percentage = (snore / total) * 100
100
+ other_percentage = (other / total) * 100
101
+
102
+ categories = ["Snore", "Other"]
103
+ percentages = [snore_percentage, other_percentage]
104
+
105
+ plt.figure(figsize=(8, 4))
106
+ plt.barh(categories, percentages, color=['#ff0033', '#00ffee'])
107
+ plt.xlabel('Percentage')
108
+ plt.title('Percentage of Snoring')
109
+ plt.xlim(0, 100)
110
+
111
+ for i, percentage in enumerate(percentages):
112
+ plt.text(percentage, i, f' {percentage:.2f}%', va='center')
113
+ st.write("DONE")
114
+ st.pyplot(plt)
115
 
116
 
117