api language tool
Browse files
app.py
CHANGED
|
@@ -1,29 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
tool = language_tool_python.LanguageTool('pl')
|
| 6 |
|
| 7 |
def correct_polish_text(text):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
text = ''.join(corrected_parts)
|
| 26 |
-
return text
|
| 27 |
|
| 28 |
def transcribe(audio):
|
| 29 |
pipe = pipeline(model="marcsixtysix/whisper-base-pl")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 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 |
def transcribe(audio):
|
| 25 |
pipe = pipeline(model="marcsixtysix/whisper-base-pl")
|