camparchimedes commited on
Commit
071df52
1 Parent(s): 2f03bd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -20
app.py CHANGED
@@ -57,19 +57,18 @@ SIDEBAR_INFO = f"""
57
 
58
  warnings.filterwarnings("ignore")
59
 
60
- #def convert_to_wav(filepath):
61
- #_,file_ending = os.path.splitext(f'{filepath}')
62
- #audio_file = filepath.replace(file_ending, ".wav")
63
- #print("starting conversion to wav")
64
- #os.system(f'ffmpeg -i "{filepath}" -ar 16000 -ac 1 -c:a pcm_s16le "{audio_file}"')
65
- #return audio_file
66
 
67
  #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
68
- def convert_to_wav(audio_file):
69
- audio = AudioSegment.from_file(audio_file, format="m4a")
70
- wav_file = "temp.wav"
71
- audio.export(wav_file, format="wav")
72
- return wav_file
73
 
74
  device = "cuda" if torch.cuda.is_available() else "cpu"
75
 
@@ -81,8 +80,8 @@ pipe = pipeline(
81
  )
82
 
83
  def transcribe_audio(audio_file, batch_size=10):
84
- if audio_file.endswith(".m4a"):
85
- audio_file = convert_to_wav(audio_file)
86
 
87
  start_time = time.time()
88
 
@@ -96,10 +95,6 @@ def transcribe_audio(audio_file, batch_size=10):
96
  output_time = end_time - start_time
97
  word_count = len(text.split())
98
 
99
- result = f"Transcription: {text.strip()}\n\nTime taken: {output_time:.2f} seconds\nNumber of words: {word_count}"
100
-
101
-
102
- return text.strip(), result
103
 
104
  memory = psutil.virtual_memory()
105
  gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
@@ -107,8 +102,12 @@ def transcribe_audio(audio_file, batch_size=10):
107
  gpu_memory = gpu_memory[0] if len(gpu_memory) > 0 else 0
108
  system_info = f"""
109
  *Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB.*
110
- *Processing time: {time_diff:.5} seconds.*
111
- *GPU Utilization: {gpu_utilization}%, GPU Memory: {gpu_memory}"""
 
 
 
 
112
  #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
113
 
114
  # Clean/preprocess text
@@ -119,6 +118,7 @@ def clean_text(text):
119
  return text
120
 
121
  nlp = spacy.blank("nb") # 'nb' ==> codename = Norwegian Bokmål
 
122
  spacy_stop_words = spacy.lang.nb.stop_words.STOP_WORDS
123
 
124
  def preprocess_text(text):
@@ -224,7 +224,6 @@ iface = gr.Blocks()
224
  with iface:
225
 
226
  gr.Image(LOGO) # LOGO variable as string to gr.Image constructor
227
- gr.HTML(SIDEBAR_INFO)
228
  gr.Markdown(HEADER_INFO)
229
 
230
  with gr.Tabs():
 
57
 
58
  warnings.filterwarnings("ignore")
59
 
60
+ def convert_to_wav(filepath):
61
+ _,file_ending = os.path.splitext(f'{filepath}')
62
+ audio_file = filepath.replace(file_ending, ".wav")
63
+ os.system(f'ffmpeg -i "{filepath}" -ar 16000 -ac 1 -c:a pcm_s16le "{audio_file}"')
64
+ return audio_file
 
65
 
66
  #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
67
+ #def convert_to_wav(audio_file):
68
+ #audio = AudioSegment.from_file(audio_file, format="m4a")
69
+ #wav_file = "temp.wav"
70
+ #audio.export(wav_file, format="wav")
71
+ #return wav_file
72
 
73
  device = "cuda" if torch.cuda.is_available() else "cpu"
74
 
 
80
  )
81
 
82
  def transcribe_audio(audio_file, batch_size=10):
83
+ #if audio_file.endswith(".m4a"):
84
+ #audio_file = convert_to_wav(audio_file)
85
 
86
  start_time = time.time()
87
 
 
95
  output_time = end_time - start_time
96
  word_count = len(text.split())
97
 
 
 
 
 
98
 
99
  memory = psutil.virtual_memory()
100
  gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
 
102
  gpu_memory = gpu_memory[0] if len(gpu_memory) > 0 else 0
103
  system_info = f"""
104
  *Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB.*
105
+ *Processing time: {output_time:.2f} seconds.*
106
+ *Number of words: {word_count}*
107
+ *GPU Utilization: {gpu_utilization}%, GPU Memory: {gpu_memory}*"""
108
+
109
+
110
+ return text.strip(), system_info
111
  #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
112
 
113
  # Clean/preprocess text
 
118
  return text
119
 
120
  nlp = spacy.blank("nb") # 'nb' ==> codename = Norwegian Bokmål
121
+ nlp.add_pipe('sentencizer')
122
  spacy_stop_words = spacy.lang.nb.stop_words.STOP_WORDS
123
 
124
  def preprocess_text(text):
 
224
  with iface:
225
 
226
  gr.Image(LOGO) # LOGO variable as string to gr.Image constructor
 
227
  gr.Markdown(HEADER_INFO)
228
 
229
  with gr.Tabs():