Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,32 @@
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
pipe = pipeline(model="marcsixtysix/whisper-base-pl")
|
| 5 |
|
| 6 |
def transcribe(audio):
|
| 7 |
text = pipe(audio)["text"]
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
demo = gr.Interface(
|
| 11 |
fn=transcribe,
|
|
|
|
| 1 |
from transformers import pipeline
|
| 2 |
import gradio as gr
|
| 3 |
+
import requests
|
| 4 |
|
| 5 |
+
def correct_polish_text(text):
|
| 6 |
+
api_url = "https://api.languagetoolplus.com/v2/check"
|
| 7 |
+
params = {
|
| 8 |
+
"text": text,
|
| 9 |
+
"language": "pl",
|
| 10 |
+
}
|
| 11 |
+
response = requests.post(api_url, data=params)
|
| 12 |
+
if response.status_code == 200:
|
| 13 |
+
matches = response.json().get("matches", [])
|
| 14 |
+
corrected_text = text
|
| 15 |
+
for match in reversed(matches):
|
| 16 |
+
start = match["offset"]
|
| 17 |
+
end = start + match["length"]
|
| 18 |
+
replacement = match["replacements"][0]["value"] if match["replacements"] else text[start:end]
|
| 19 |
+
corrected_text = corrected_text[:start] + replacement + corrected_text[end:]
|
| 20 |
+
return corrected_text
|
| 21 |
+
else:
|
| 22 |
+
return text
|
| 23 |
+
|
| 24 |
pipe = pipeline(model="marcsixtysix/whisper-base-pl")
|
| 25 |
|
| 26 |
def transcribe(audio):
|
| 27 |
text = pipe(audio)["text"]
|
| 28 |
+
corrected_text = correct_polish_text(text)
|
| 29 |
+
return corrected_text
|
| 30 |
|
| 31 |
demo = gr.Interface(
|
| 32 |
fn=transcribe,
|