Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -48,12 +48,13 @@ HEADER_INFO = """
|
|
48 |
# WEB APP ✨| Norwegian WHISPER Model
|
49 |
Switch Work [Transkribering av lydfiler til norsk skrift]
|
50 |
""".strip()
|
51 |
-
LOGO = "https://huggingface.co/spaces/camparchimedes/transcription_app/
|
52 |
SIDEBAR_INFO = f"""
|
53 |
<div align="center">
|
54 |
<img src="{LOGO}" style="width: 100%; height: auto;"/>
|
55 |
</div>
|
56 |
"""
|
|
|
57 |
|
58 |
def convert_to_wav(filepath):
|
59 |
_,file_ending = os.path.splitext(f'{filepath}')
|
@@ -61,12 +62,9 @@ def convert_to_wav(filepath):
|
|
61 |
os.system(f'ffmpeg -i "{filepath}" -ar 16000 -ac 1 -c:a pcm_s16le "{audio_file}"')
|
62 |
return audio_file
|
63 |
|
64 |
-
pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", device=0)
|
65 |
|
66 |
def transcribe_audio(audio_file):
|
67 |
-
#if audio_file.endswith(".m4a"):
|
68 |
-
#audio_file = convert_to_wav(audio_file)
|
69 |
-
|
70 |
start_time = time.time()
|
71 |
|
72 |
outputs = pipe(audio_file, return_timestamps=False, generate_kwargs={'task': 'transcribe', 'language': 'no'}) # skip_special_tokens=True
|
@@ -76,15 +74,24 @@ def transcribe_audio(audio_file):
|
|
76 |
|
77 |
output_time = end_time - start_time
|
78 |
word_count = len(text.split())
|
|
|
|
|
79 |
memory = psutil.virtual_memory()
|
80 |
gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
|
81 |
gpu_utilization = gpu_utilization[0] if len(gpu_utilization) > 0 else 0
|
82 |
gpu_memory = gpu_memory[0] if len(gpu_memory) > 0 else 0
|
|
|
|
|
|
|
|
|
|
|
83 |
system_info = f"""
|
84 |
*Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB.*
|
85 |
*Processing time: {output_time:.2f} seconds.*
|
86 |
*Number of words: {word_count}*
|
87 |
-
*GPU Utilization: {gpu_utilization}%, GPU Memory: {gpu_memory}*
|
|
|
|
|
88 |
|
89 |
return text.strip(), system_info
|
90 |
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
|
48 |
# WEB APP ✨| Norwegian WHISPER Model
|
49 |
Switch Work [Transkribering av lydfiler til norsk skrift]
|
50 |
""".strip()
|
51 |
+
LOGO = "https://huggingface.co/spaces/camparchimedes/transcription_app/blob/main/logo.png"
|
52 |
SIDEBAR_INFO = f"""
|
53 |
<div align="center">
|
54 |
<img src="{LOGO}" style="width: 100%; height: auto;"/>
|
55 |
</div>
|
56 |
"""
|
57 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
58 |
|
59 |
def convert_to_wav(filepath):
|
60 |
_,file_ending = os.path.splitext(f'{filepath}')
|
|
|
62 |
os.system(f'ffmpeg -i "{filepath}" -ar 16000 -ac 1 -c:a pcm_s16le "{audio_file}"')
|
63 |
return audio_file
|
64 |
|
65 |
+
pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", device=0 if device == "cuda" else -1)
|
66 |
|
67 |
def transcribe_audio(audio_file):
|
|
|
|
|
|
|
68 |
start_time = time.time()
|
69 |
|
70 |
outputs = pipe(audio_file, return_timestamps=False, generate_kwargs={'task': 'transcribe', 'language': 'no'}) # skip_special_tokens=True
|
|
|
74 |
|
75 |
output_time = end_time - start_time
|
76 |
word_count = len(text.split())
|
77 |
+
|
78 |
+
# GPU usage
|
79 |
memory = psutil.virtual_memory()
|
80 |
gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
|
81 |
gpu_utilization = gpu_utilization[0] if len(gpu_utilization) > 0 else 0
|
82 |
gpu_memory = gpu_memory[0] if len(gpu_memory) > 0 else 0
|
83 |
+
|
84 |
+
# CPU usage
|
85 |
+
cpu_usage = psutil.cpu_percent(interval=1)
|
86 |
+
|
87 |
+
# System info string
|
88 |
system_info = f"""
|
89 |
*Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB.*
|
90 |
*Processing time: {output_time:.2f} seconds.*
|
91 |
*Number of words: {word_count}*
|
92 |
+
*GPU Utilization: {gpu_utilization}%, GPU Memory: {gpu_memory}*
|
93 |
+
*CPU Usage: {cpu_usage}%*
|
94 |
+
"""
|
95 |
|
96 |
return text.strip(), system_info
|
97 |
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|