camparchimedes commited on
Commit
9d34978
·
verified ·
1 Parent(s): 638acc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -9
app.py CHANGED
@@ -68,27 +68,35 @@ def transcribe(microphone, file_upload):
68
 
69
  file = microphone if microphone is not None else file_upload
70
  start_time = time.time()
71
-
72
 
73
  #--------------____________________________________________--------------"
 
74
  device = "cuda" if torch.cuda.is_available() else "cpu"
75
  pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", device=device)
76
- # chunk_length_s=30, generate_kwargs={'task': 'transcribe', 'language': 'no'}
77
  text = pipe(file)["text"]
 
78
  #--------------____________________________________________--------------"
79
 
80
-
81
  end_time = time.time()
82
  output_time = end_time - start_time
83
  word_count = len(text.split())
84
 
85
  # --GPU metrics
86
  memory = psutil.virtual_memory()
87
- gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
88
- gpu_utilization = gpu_utilization[0] if len(gpu_utilization) > 0 else 0
89
- gpu_memory = gpu_memory[0] if len(gpu_memory) > 0 else 0
 
 
 
 
 
 
 
 
90
  # --CPU metric
91
  cpu_usage = psutil.cpu_percent(interval=1)
 
92
  # --system info string
93
  system_info = f"""
94
  *Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB.*
@@ -98,7 +106,7 @@ def transcribe(microphone, file_upload):
98
  *CPU Usage: {cpu_usage}%*
99
  """
100
 
101
- return warn_output + text, system_info
102
 
103
  def save_to_pdf(text, summary):
104
  pdf = FPDF()
@@ -143,7 +151,6 @@ with iface:
143
  with gr.Column():
144
  system_info = gr.Textbox(label="System Info")
145
 
146
-
147
  with gr.Tabs():
148
  with gr.TabItem("Download PDF"):
149
  pdf_text_only = gr.Button("Download PDF with Transcribed Text")
@@ -151,7 +158,19 @@ with iface:
151
 
152
  pdf_text_only.click(fn=lambda text: save_to_pdf(text, ""), inputs=[text_output], outputs=[pdf_output])
153
 
154
-
 
 
 
 
 
 
 
 
 
 
 
 
155
  transcribe_btn.click(fn=transcribe, inputs=[microphone, upload], outputs=[text_output, system_info])
156
 
157
 
 
68
 
69
  file = microphone if microphone is not None else file_upload
70
  start_time = time.time()
 
71
 
72
  #--------------____________________________________________--------------"
73
+
74
  device = "cuda" if torch.cuda.is_available() else "cpu"
75
  pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", device=device)
 
76
  text = pipe(file)["text"]
77
+
78
  #--------------____________________________________________--------------"
79
 
 
80
  end_time = time.time()
81
  output_time = end_time - start_time
82
  word_count = len(text.split())
83
 
84
  # --GPU metrics
85
  memory = psutil.virtual_memory()
86
+
87
+ # Default GPU utilization and memory to 0 in case of an error
88
+ gpu_utilization = 0
89
+ gpu_memory = 0
90
+ try:
91
+ gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
92
+ gpu_utilization = gpu_utilization[0] if len(gpu_utilization) > 0 else 0
93
+ gpu_memory = gpu_memory[0] if len(gpu_memory) > 0 else 0
94
+ except Exception as e:
95
+ print(f"Error retrieving GPU info: {e}")
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
  *CPU Usage: {cpu_usage}%*
107
  """
108
 
109
+ return text, system_info
110
 
111
  def save_to_pdf(text, summary):
112
  pdf = FPDF()
 
151
  with gr.Column():
152
  system_info = gr.Textbox(label="System Info")
153
 
 
154
  with gr.Tabs():
155
  with gr.TabItem("Download PDF"):
156
  pdf_text_only = gr.Button("Download PDF with Transcribed Text")
 
158
 
159
  pdf_text_only.click(fn=lambda text: save_to_pdf(text, ""), inputs=[text_output], outputs=[pdf_output])
160
 
161
+ with gr.Row():
162
+ gr.Markdown('''
163
+ <div align="center">
164
+ <a href="https://opensource.com/resources/what-open-source">
165
+ <img src="https://badgen.net/badge/Open%20Source%20%3F/Yes%21/blue?icon=github" alt="Open Source? Yes!">
166
+ </a>
167
+ <span style="display:inline-block; width: 20px;"></span>
168
+ <a href="https://opensource.org/licenses/Apache-2.0">
169
+ <img src="https://img.shields.io/badge/License-Apache_2.0-blue.svg" alt="License: Apache 2.0">
170
+ </a>
171
+ </div>
172
+ ''')
173
+
174
  transcribe_btn.click(fn=transcribe, inputs=[microphone, upload], outputs=[text_output, system_info])
175
 
176