File size: 1,228 Bytes
6d8cf49 30a0e4f 0b59fd9 30a0e4f 0b59fd9 30a0e4f 6d8cf49 0b59fd9 6d8cf49 c9d1d9c 3d67274 6d8cf49 30a0e4f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
from transformers import pipeline
import gradio as gr
import requests
def correct_polish_text(text):
api_url = "https://api.languagetoolplus.com/v2/check"
params = {
"text": text,
"language": "pl",
}
response = requests.post(api_url, data=params)
if response.status_code == 200:
matches = response.json().get("matches", [])
corrected_text = text
for match in reversed(matches):
start = match["offset"]
end = start + match["length"]
replacement = match["replacements"][0]["value"] if match["replacements"] else text[start:end]
corrected_text = corrected_text[:start] + replacement + corrected_text[end:]
return corrected_text
else:
return text
pipe = pipeline(model="marcsixtysix/whisper-base-pl")
def transcribe(audio):
text = pipe(audio)["text"]
corrected_text = correct_polish_text(text)
return corrected_text
demo = gr.Interface(
fn=transcribe,
inputs=gr.Audio(type="filepath"),
outputs="text",
title="Polish speech recognition",
description="Realtime demo for Polish speech recognition using a fine-tuned Whisper Base model.",
)
demo.launch(share=True) |