RexChan commited on
Commit
651716c
·
verified ·
1 Parent(s): 37d0c01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -3,7 +3,7 @@ from transformers import WhisperForConditionalGeneration, WhisperProcessor
3
  from transformers import pipeline
4
  import librosa
5
  import torch
6
- from spleeter.separator import Separator
7
  from pydub import AudioSegment
8
  from IPython.display import Audio
9
  import os
@@ -11,6 +11,9 @@ import accelerate
11
 
12
 
13
 
 
 
 
14
  # preprocess and crop audio file
15
  def audio_preprocess(file_name = '/test1/vocals.wav'):
16
  # separate music and vocal
@@ -23,13 +26,17 @@ def audio_preprocess(file_name = '/test1/vocals.wav'):
23
  end_time = 110000 # e.g. 40 seconds, 40000
24
 
25
 
26
- audio = AudioSegment.from_file(output_file) #(file_name)
 
 
27
  cropped_audio = audio[start_time:end_time]
28
  processed_audio = cropped_audio
29
  # .export('cropped_vocals.wav', format='wav') # save vocal audio file
30
  return processed_audio
31
 
32
 
 
 
33
  # ASR transcription
34
  def asr_model(processed_audio):
35
  # load audio file
@@ -81,7 +88,7 @@ def senti_model(transcription):
81
 
82
 
83
  # main
84
- def main():
85
 
86
 
87
  # processed_audio = audio_preprocess(input_file)
@@ -108,7 +115,7 @@ if __name__ == '__main__':
108
  # steamlit setup
109
  st.set_page_config(page_title="Sentiment Analysis on Your Cantonese Song",)
110
  st.header("Cantonese Song Sentiment Analyzer")
111
- input_file = st.file_uploader("upload a song in mp3 format") #, type="mp3") # upload song
112
  if input_file is not None:
113
  st.write("File uploaded successfully!")
114
  st.write(input_file)
@@ -119,8 +126,8 @@ if __name__ == '__main__':
119
 
120
  # load song
121
  #input_file = os.path.isfile("test1.mp3")
122
- output_file = os.path.isdir("")
123
 
124
 
125
  if button_click:
126
- main()
 
3
  from transformers import pipeline
4
  import librosa
5
  import torch
6
+ # from spleeter.separator import Separator
7
  from pydub import AudioSegment
8
  from IPython.display import Audio
9
  import os
 
11
 
12
 
13
 
14
+
15
+
16
+
17
  # preprocess and crop audio file
18
  def audio_preprocess(file_name = '/test1/vocals.wav'):
19
  # separate music and vocal
 
26
  end_time = 110000 # e.g. 40 seconds, 40000
27
 
28
 
29
+
30
+
31
+ audio = AudioSegment.from_file(file_name)
32
  cropped_audio = audio[start_time:end_time]
33
  processed_audio = cropped_audio
34
  # .export('cropped_vocals.wav', format='wav') # save vocal audio file
35
  return processed_audio
36
 
37
 
38
+
39
+
40
  # ASR transcription
41
  def asr_model(processed_audio):
42
  # load audio file
 
88
 
89
 
90
  # main
91
+ def main(input_file):
92
 
93
 
94
  # processed_audio = audio_preprocess(input_file)
 
115
  # steamlit setup
116
  st.set_page_config(page_title="Sentiment Analysis on Your Cantonese Song",)
117
  st.header("Cantonese Song Sentiment Analyzer")
118
+ input_file = st.file_uploader("upload a song in mp3 format", type="mp3") # upload song
119
  if input_file is not None:
120
  st.write("File uploaded successfully!")
121
  st.write(input_file)
 
126
 
127
  # load song
128
  #input_file = os.path.isfile("test1.mp3")
129
+ # output_file = os.path.isdir("")
130
 
131
 
132
  if button_click:
133
+ main(input_file=input_file)