camparchimedes commited on
Commit
9bfe584
·
verified ·
1 Parent(s): 078d876

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -35
app.py CHANGED
@@ -56,40 +56,19 @@ CACHE_EXAMPLES = torch.device('cuda') and os.getenv("CACHE_EXAMPLES", "0") == "1
56
  device = torch.device('cuda')
57
  #device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
58
 
59
- def transcribe(file_upload, progress=gr.Progress(track_tqdm=True)):
60
 
61
- file = file_upload # microphone if microphone is not None else
62
  start_time = time.time()
63
-
64
- # -- ex subrosa
65
- audio, sr = librosa.load(file_upload, sr=None)
66
- duration = librosa.get_duration(y=audio, sr=sr)
67
-
68
- # -- asr pipeline
69
- with torch.no_grad():
70
- pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", chunk_length_s=30, device=device)
71
-
72
- # -- process audio in chunks of 30 seconds
73
- chunk_size = sr * 30 # 30 seconds
74
- text = ""
75
- for start in range(0, len(audio), chunk_size):
76
- end = min(start + chunk_size, len(audio))
77
- chunk = audio[start:end]
78
-
79
- # -- convert audio chunk to format for pipeline
80
- chunk_file = "temp_chunk.wav"
81
- sf.write(chunk_file, chunk, sr)
82
-
83
 
 
84
 
85
- import librosa
86
-
87
 
 
88
 
89
-
90
- # -- chnk ad transcriptrauma
91
- chunk_text = pipe(chunk_file)["text"]
92
- text += chunk_text + " "
93
 
94
  end_time = time.time()
95
  output_time = end_time - start_time
@@ -101,21 +80,21 @@ def transcribe(file_upload, progress=gr.Progress(track_tqdm=True)):
101
  memory = psutil.virtual_memory()
102
 
103
  # --cpu metric
104
- #cpu_usage = psutil.cpu_percent(interval=1)
105
 
106
  # --gpu metric
107
- #gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
108
 
109
  # --system info string
110
  system_info = f"""
111
- #Processing time: {output_time:.2f} seconds.
112
- #Number of words: {word_count}
 
113
  GPU Memory: {gpu_memory}%
114
  GPU Utilization: {gpu_utilization}%
115
  """
116
-
117
- return text.strip(), system_info
118
 
 
119
 
120
  ###############################################################################
121
  # Interface.
@@ -186,7 +165,7 @@ with iface:
186
  with gr.Column(scale=3):
187
  text_output = gr.Textbox(label="Transkribert Tekst", elem_id="transcription_output")
188
  with gr.Column(scale=1):
189
- system_info = gr.Textbox(label="Antall sekunder, ord:", elem_id="system_info_box")
190
 
191
 
192
  with gr.Tabs():
 
56
  device = torch.device('cuda')
57
  #device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
58
 
59
+ def transcribe(file_upload, progress=gr.Progress(track_tqdm=True)): # microphone
60
 
61
+ file = file_upload # microphone if microphone is not None else
62
  start_time = time.time()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
+ #--------------____________________________________________--------------"
65
 
66
+ with torch.no_grad():
67
+ pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", chunk_length_s=30, device=device)
68
 
69
+ text = pipe(file)["text"]
70
 
71
+ #--------------____________________________________________--------------"
 
 
 
72
 
73
  end_time = time.time()
74
  output_time = end_time - start_time
 
80
  memory = psutil.virtual_memory()
81
 
82
  # --cpu metric
83
+ cpu_usage = psutil.cpu_percent(interval=1)
84
 
85
  # --gpu metric
86
+ gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
87
 
88
  # --system info string
89
  system_info = f"""
90
+ Processing time: {output_time:.2f} seconds.
91
+ Number of words: {word_count}
92
+ CPU Usage: {cpu_usage}%
93
  GPU Memory: {gpu_memory}%
94
  GPU Utilization: {gpu_utilization}%
95
  """
 
 
96
 
97
+ return text.strip(), system_info
98
 
99
  ###############################################################################
100
  # Interface.
 
165
  with gr.Column(scale=3):
166
  text_output = gr.Textbox(label="Transkribert Tekst", elem_id="transcription_output")
167
  with gr.Column(scale=1):
168
+ system_info = gr.Textbox(label="Antall sekunder, ord, system data:", elem_id="system_info_box")
169
 
170
 
171
  with gr.Tabs():