|
import os |
|
import sys |
|
os.system("pip install transformers==4.27.0") |
|
os.system("pip install torch") |
|
os.system("pip install openai") |
|
os.system("pip install accelerate") |
|
from transformers import pipeline, WhisperModel, WhisperTokenizer, WhisperFeatureExtractor |
|
os.system("pip install evaluate") |
|
|
|
|
|
os.system("pip install datasets") |
|
|
|
os.system("pip install spicy==1.8.1") |
|
os.system("pip install soundfile") |
|
os.system("pip install jiwer") |
|
os.system("pip install datasets[audio]") |
|
os.system("pip install numba==0.51.2") |
|
from evaluate import evaluator |
|
from datasets import load_dataset, Audio, disable_caching, set_caching_enabled |
|
|
|
set_caching_enabled(False) |
|
disable_caching() |
|
|
|
|
|
|
|
|
|
huggingface_token = os.environ["huggingface_token"] |
|
|
|
miso_tokenizer = WhisperTokenizer.from_pretrained("mskov/whisper_miso", use_auth_token=huggingface_token) |
|
miso_feature_extractor = WhisperFeatureExtractor.from_pretrained("mskov/whisper_miso", use_auth_token=huggingface_token) |
|
whisper_miso=WhisperModel.from_pretrained("mskov/whisper_miso", use_auth_token=huggingface_token, device_map="auto") |
|
|
|
|
|
|
|
|
|
task_evaluator = evaluator("automatic-speech-recognition") |
|
|
|
|
|
|
|
|
|
dataset = load_dataset("mskov/miso_test", split="test").cast_column("audio", Audio()) |
|
results = task_evaluator.compute( |
|
model_or_pipeline=whisper_miso, |
|
|
|
data=dataset, |
|
tokenizer=miso_tokenizer, |
|
feature_extractor=miso_feature_extractor, |
|
input_column="audio", |
|
label_column="audio", |
|
|
|
strategy="simple", |
|
metric="wer", |
|
) |
|
print(results) |
|
|
|
|
|
def transcribe(audio, state=""): |
|
text = p(audio)["text"] |
|
state += text + " " |
|
returnstate, state |
|
|
|
gr.Interface( |
|
fn=transcribe, |
|
inputs=[ |
|
gr.Audio(source="microphone", type="filepath", streaming=True), |
|
"state" |
|
], |
|
outputs=[ |
|
"textbox", |
|
"state" |
|
], |
|
live=True).launch() |