highlight mode
Browse files- app.py +1 -1
- search_errors_logic.py +45 -6
app.py
CHANGED
@@ -136,7 +136,7 @@ def main():
|
|
136 |
if not text.strip():
|
137 |
st.warning("Введите текст для проверки")
|
138 |
else:
|
139 |
-
text, errors = check_text(text, tool, mode="chat_gpt")
|
140 |
if not errors:
|
141 |
st.success("Ошибок не найдено.")
|
142 |
else:
|
|
|
136 |
if not text.strip():
|
137 |
st.warning("Введите текст для проверки")
|
138 |
else:
|
139 |
+
text, errors = check_text(text, tool, mode="chat_gpt", highlight_mode=True)
|
140 |
if not errors:
|
141 |
st.success("Ошибок не найдено.")
|
142 |
else:
|
search_errors_logic.py
CHANGED
@@ -51,7 +51,7 @@ corrected text:
|
|
51 |
"я решил пойти в"
|
52 |
|
53 |
Твой ответ:
|
54 |
-
Опечатка: повтор
|
55 |
|
56 |
|
57 |
Теперь твоя очередь:
|
@@ -183,11 +183,14 @@ def add_comments_to_text(text, errors, add_errors=False):
|
|
183 |
return text.replace("\n", " ")
|
184 |
|
185 |
|
186 |
-
def check_text(text, tool, mode="chat_gpt", add_errors=False):
|
187 |
if mode == "tool":
|
188 |
return check_text_with_tool(text, tool, add_errors=add_errors)
|
189 |
else:
|
190 |
-
|
|
|
|
|
|
|
191 |
|
192 |
|
193 |
def check_text_chat_gpt(text, fixed_text=None, add_errors=False, *args, **kwargs):
|
@@ -196,12 +199,48 @@ def check_text_chat_gpt(text, fixed_text=None, add_errors=False, *args, **kwargs
|
|
196 |
changes = find_corrected_positions(text, fixed_text)
|
197 |
errors = []
|
198 |
for change in changes:
|
199 |
-
start_orig,
|
200 |
start_corr, end_corr = get_piece_of_text_bounds(fixed_text, change['corrected'][0], change['corrected'][1])
|
201 |
-
inp = prompt_compare_get_comment.format(text[start_orig:
|
202 |
errors.append({
|
203 |
'start': start_orig,
|
204 |
-
'end':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
205 |
'message': get_gpt_response(inp, client_name="vsegpt"),
|
206 |
})
|
207 |
|
|
|
51 |
"я решил пойти в"
|
52 |
|
53 |
Твой ответ:
|
54 |
+
Опечатка: повтор пробела.
|
55 |
|
56 |
|
57 |
Теперь твоя очередь:
|
|
|
183 |
return text.replace("\n", " ")
|
184 |
|
185 |
|
186 |
+
def check_text(text, tool, mode="chat_gpt", highlight_mode=False, add_errors=False):
|
187 |
if mode == "tool":
|
188 |
return check_text_with_tool(text, tool, add_errors=add_errors)
|
189 |
else:
|
190 |
+
if highlight_mode:
|
191 |
+
return check_text_chat_gpt_highlight_mode(text, add_errors=add_errors)
|
192 |
+
else:
|
193 |
+
return check_text_chat_gpt(text, add_errors=add_errors)
|
194 |
|
195 |
|
196 |
def check_text_chat_gpt(text, fixed_text=None, add_errors=False, *args, **kwargs):
|
|
|
199 |
changes = find_corrected_positions(text, fixed_text)
|
200 |
errors = []
|
201 |
for change in changes:
|
202 |
+
start_orig, end_orig = get_piece_of_text_bounds(text, change['original'][0], change['original'][1])
|
203 |
start_corr, end_corr = get_piece_of_text_bounds(fixed_text, change['corrected'][0], change['corrected'][1])
|
204 |
+
inp = prompt_compare_get_comment.format(text[start_orig:end_orig], fixed_text[start_corr:end_corr])
|
205 |
errors.append({
|
206 |
'start': start_orig,
|
207 |
+
'end': end_orig,
|
208 |
+
'message': get_gpt_response(inp, client_name="vsegpt"),
|
209 |
+
})
|
210 |
+
|
211 |
+
text_with_comments = add_comments_to_text(text, errors, add_errors=add_errors)
|
212 |
+
return text_with_comments, errors
|
213 |
+
|
214 |
+
|
215 |
+
def check_text_chat_gpt_highlight_mode(text, fixed_text=None, add_errors=False, *args, **kwargs):
|
216 |
+
if fixed_text is None:
|
217 |
+
fixed_text = get_gpt_response(prompt_fix_text_gpt.format(text), "vsegpt")
|
218 |
+
changes = find_corrected_positions(text, fixed_text)
|
219 |
+
bounds_init = []
|
220 |
+
for change in changes:
|
221 |
+
start_orig, end_orig = get_piece_of_text_bounds(text, change['original'][0], change['original'][1])
|
222 |
+
start_corr, end_corr = get_piece_of_text_bounds(fixed_text, change['corrected'][0], change['corrected'][1])
|
223 |
+
bounds_init.append({"start_orig": start_orig,
|
224 |
+
"end_orig": end_orig,
|
225 |
+
"start_corr": start_corr,
|
226 |
+
"end_corr": end_corr})
|
227 |
+
|
228 |
+
bounds_init = sorted(bounds_init, key=lambda x: x["start_orig"])
|
229 |
+
bounds_result = [bounds_init[0]] if len(bounds_init) > 0 else []
|
230 |
+
for bound in bounds_init[1:]:
|
231 |
+
if bounds_result[-1]["end_orig"] >= bound["start_orig"]:
|
232 |
+
bounds_result[-1]["end_orig"] = max(bounds_result[-1]["end_orig"], bound["end_orig"])
|
233 |
+
bounds_result[-1]["end_corr"] = max(bounds_result[-1]["end_corr"], bound["end_corr"])
|
234 |
+
else:
|
235 |
+
bounds_result.append(bound.copy())
|
236 |
+
|
237 |
+
errors = []
|
238 |
+
for bound in bounds_result:
|
239 |
+
inp = prompt_compare_get_comment.format(text[bound["start_orig"]:bound["end_orig"]],
|
240 |
+
fixed_text[bound["start_corr"]:bound["end_corr"]])
|
241 |
+
errors.append({
|
242 |
+
'start': start_orig,
|
243 |
+
'end': end_orig,
|
244 |
'message': get_gpt_response(inp, client_name="vsegpt"),
|
245 |
})
|
246 |
|