camparchimedes commited on
Commit
e79814a
·
verified ·
1 Parent(s): 73a1be0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -16,7 +16,7 @@
16
  # limitations under the License.
17
  # -------------------------------------------------------------------------
18
 
19
- #import spaces
20
  import gradio as gr
21
  from PIL import Image
22
  #from pydub import AudioSegment
@@ -64,11 +64,11 @@ SIDEBAR_INFO = f"""
64
  """
65
 
66
  # ------------transcribe section------------
67
- device = "cuda" if torch.cuda.is_available() else "cpu"
68
- pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", device=device) # chunk_length_s=30, generate_kwargs={'task': 'transcribe', 'language': 'no'}
69
 
70
- #@spaces.GPU()
71
- def transcribe(microphone, file_upload, batch_size=15):
 
72
  warn_output = ""
73
  if (microphone is not None) and (file_upload is not None):
74
  warn_output = (
@@ -80,9 +80,16 @@ def transcribe(microphone, file_upload, batch_size=15):
80
  return "ERROR: You have to either use the microphone or upload an audio file"
81
 
82
  file = microphone if microphone is not None else file_upload
 
83
 
84
  start_time = time.time()
85
- text = pipe(file, batch_size=batch_size, return_timestamps=False)["text"]
 
 
 
 
 
 
86
 
87
  end_time = time.time()
88
  output_time = end_time - start_time
@@ -93,10 +100,8 @@ def transcribe(microphone, file_upload, batch_size=15):
93
  gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
94
  gpu_utilization = gpu_utilization[0] if len(gpu_utilization) > 0 else 0
95
  gpu_memory = gpu_memory[0] if len(gpu_memory) > 0 else 0
96
-
97
  # --CPU metric
98
  cpu_usage = psutil.cpu_percent(interval=1)
99
-
100
  # --system info string
101
  system_info = f"""
102
  *Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB.*
@@ -106,8 +111,7 @@ def transcribe(microphone, file_upload, batch_size=15):
106
  *CPU Usage: {cpu_usage}%*
107
  """
108
 
109
- return warn_output + text.strip(), system_info
110
-
111
 
112
  def save_to_pdf(text, summary):
113
  pdf = FPDF()
@@ -138,7 +142,7 @@ with iface:
138
 
139
  with gr.Row():
140
  gr.Markdown('''
141
- ##### 1. Last opp lydfila 🔊 (dropp ’drag-n-drop’)
142
  2. Trykk på "Transkriber" knappen og vent på svar ☕️
143
  3. Går rimelig bra kjapt med Norwegian NB-Whisper Large⚡️
144
  4. Planlegger tilleggs-funksjoner senere😅
 
16
  # limitations under the License.
17
  # -------------------------------------------------------------------------
18
 
19
+ import spaces
20
  import gradio as gr
21
  from PIL import Image
22
  #from pydub import AudioSegment
 
64
  """
65
 
66
  # ------------transcribe section------------
67
+ ) # chunk_length_s=30, generate_kwargs={'task': 'transcribe', 'language': 'no'}
 
68
 
69
+ @spaces.GPU()
70
+ def transcribe(microphone, file_upload):
71
+ #--------------____________________________________________--------------"
72
  warn_output = ""
73
  if (microphone is not None) and (file_upload is not None):
74
  warn_output = (
 
80
  return "ERROR: You have to either use the microphone or upload an audio file"
81
 
82
  file = microphone if microphone is not None else file_upload
83
+ #--------------____________________________________________--------------"
84
 
85
  start_time = time.time()
86
+
87
+ #--------------____________________________________________--------------"
88
+ device = "cuda" if torch.cuda.is_available() else "cpu"
89
+ pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", device=device)
90
+
91
+ text = pipe(file)["text"]
92
+ #--------------____________________________________________--------------"
93
 
94
  end_time = time.time()
95
  output_time = end_time - start_time
 
100
  gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
101
  gpu_utilization = gpu_utilization[0] if len(gpu_utilization) > 0 else 0
102
  gpu_memory = gpu_memory[0] if len(gpu_memory) > 0 else 0
 
103
  # --CPU metric
104
  cpu_usage = psutil.cpu_percent(interval=1)
 
105
  # --system info string
106
  system_info = f"""
107
  *Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB.*
 
111
  *CPU Usage: {cpu_usage}%*
112
  """
113
 
114
+ return warn_output + text, system_info
 
115
 
116
  def save_to_pdf(text, summary):
117
  pdf = FPDF()
 
142
 
143
  with gr.Row():
144
  gr.Markdown('''
145
+ ##### 1. Last opp lydfila 🔊
146
  2. Trykk på "Transkriber" knappen og vent på svar ☕️
147
  3. Går rimelig bra kjapt med Norwegian NB-Whisper Large⚡️
148
  4. Planlegger tilleggs-funksjoner senere😅