Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -35,7 +35,7 @@ import torch
|
|
35 |
#import torchaudio
|
36 |
#import torchaudio.transforms as transforms
|
37 |
|
38 |
-
from transformers import pipeline
|
39 |
|
40 |
import spacy
|
41 |
import networkx as nx
|
@@ -68,14 +68,19 @@ pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large"
|
|
68 |
|
69 |
@spaces.GPU()
|
70 |
def transcribe_audio(audio_file, batch_size=16):
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
72 |
audio = AudioSegment.from_wav(audio_file)
|
73 |
samples = np.array(audio.get_array_of_samples())
|
74 |
sample_rate = audio.frame_rate
|
75 |
|
76 |
start_time = time.time()
|
77 |
|
78 |
-
#
|
79 |
outputs = pipe(samples, sampling_rate=sample_rate, batch_size=batch_size, return_timestamps=False)
|
80 |
text = outputs["text"]
|
81 |
|
@@ -84,16 +89,16 @@ def transcribe_audio(audio_file, batch_size=16):
|
|
84 |
output_time = end_time - start_time
|
85 |
word_count = len(text.split())
|
86 |
|
87 |
-
# GPU usage
|
88 |
memory = psutil.virtual_memory()
|
89 |
gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
|
90 |
gpu_utilization = gpu_utilization[0] if len(gpu_utilization) > 0 else 0
|
91 |
gpu_memory = gpu_memory[0] if len(gpu_memory) > 0 else 0
|
92 |
|
93 |
-
# CPU usage
|
94 |
cpu_usage = psutil.cpu_percent(interval=1)
|
95 |
|
96 |
-
#
|
97 |
system_info = f"""
|
98 |
*Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB.*
|
99 |
*Processing time: {output_time:.2f} seconds.*
|
@@ -108,8 +113,7 @@ def transcribe_audio(audio_file, batch_size=16):
|
|
108 |
# ------------summary section------------
|
109 |
|
110 |
|
111 |
-
|
112 |
-
# -----------------BLOCKS NEED EDIT....!--------------
|
113 |
|
114 |
@spaces.GPU()
|
115 |
def clean_text(text):
|
|
|
35 |
#import torchaudio
|
36 |
#import torchaudio.transforms as transforms
|
37 |
|
38 |
+
from transformers import pipeline #AutoModel
|
39 |
|
40 |
import spacy
|
41 |
import networkx as nx
|
|
|
68 |
|
69 |
@spaces.GPU()
|
70 |
def transcribe_audio(audio_file, batch_size=16):
|
71 |
+
|
72 |
+
# --check if audio_file is tuple
|
73 |
+
if isinstance(audio_file, tuple):
|
74 |
+
audio_file = audio_file[0]
|
75 |
+
|
76 |
+
# --place audio file in numpy array
|
77 |
audio = AudioSegment.from_wav(audio_file)
|
78 |
samples = np.array(audio.get_array_of_samples())
|
79 |
sample_rate = audio.frame_rate
|
80 |
|
81 |
start_time = time.time()
|
82 |
|
83 |
+
# --transcribe
|
84 |
outputs = pipe(samples, sampling_rate=sample_rate, batch_size=batch_size, return_timestamps=False)
|
85 |
text = outputs["text"]
|
86 |
|
|
|
89 |
output_time = end_time - start_time
|
90 |
word_count = len(text.split())
|
91 |
|
92 |
+
# --GPU usage
|
93 |
memory = psutil.virtual_memory()
|
94 |
gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
|
95 |
gpu_utilization = gpu_utilization[0] if len(gpu_utilization) > 0 else 0
|
96 |
gpu_memory = gpu_memory[0] if len(gpu_memory) > 0 else 0
|
97 |
|
98 |
+
# --CPU usage
|
99 |
cpu_usage = psutil.cpu_percent(interval=1)
|
100 |
|
101 |
+
# --system info string
|
102 |
system_info = f"""
|
103 |
*Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB.*
|
104 |
*Processing time: {output_time:.2f} seconds.*
|
|
|
113 |
# ------------summary section------------
|
114 |
|
115 |
|
116 |
+
# ------------for app integration later------------
|
|
|
117 |
|
118 |
@spaces.GPU()
|
119 |
def clean_text(text):
|