marcsixtysix commited on
Commit
e0e6c89
·
verified ·
1 Parent(s): dd0d65b

api language tool

Browse files
Files changed (1) hide show
  1. app.py +18 -22
app.py CHANGED
@@ -1,29 +1,25 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
- import language_tool_python
4
-
5
- tool = language_tool_python.LanguageTool('pl')
6
 
7
  def correct_polish_text(text):
8
- max_iterations = 3
9
- for _ in range(max_iterations):
10
- matches = tool.check(text)
11
- if not matches:
12
- break
13
- corrected_parts = []
14
- last_pos = 0
15
- for match in matches:
16
- start = match.offset
17
- end = start + match.errorLength
18
- corrected_parts.append(text[last_pos:start])
19
- if match.replacements:
20
- corrected_parts.append(match.replacements[0])
21
- else:
22
- corrected_parts.append(text[start:end])
23
- last_pos = end
24
- corrected_parts.append(text[last_pos:])
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")