| 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) |