Commit
•
333f97c
1
Parent(s):
60acb5f
Update main.py
Browse files
main.py
CHANGED
@@ -44,47 +44,46 @@ async def receive_updates(request: Request):
|
|
44 |
print(f"Original Message ID: {message_id}")
|
45 |
print(f"User ID: {user_id}")
|
46 |
print(f"Chat ID: {chat_id}")
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
# return {"message": "Message received successfully"}
|
90 |
|
|
|
44 |
print(f"Original Message ID: {message_id}")
|
45 |
print(f"User ID: {user_id}")
|
46 |
print(f"Chat ID: {chat_id}")
|
47 |
+
|
48 |
+
influent_paragraph = user_message
|
49 |
+
corrected_paragraph = influent_paragraph # Initialize with the input text
|
50 |
+
mistakes_count = 0
|
51 |
+
mistakes = []
|
52 |
+
|
53 |
+
while True:
|
54 |
+
if mistakes_count == 5:
|
55 |
+
break
|
56 |
+
mistakes_count += 1
|
57 |
+
influent_sentences = list(nlp(corrected_paragraph).sents)
|
58 |
+
influent_sentences = [sentence.text for sentence in influent_sentences]
|
59 |
+
print("[Influent sentences]", influent_sentences)
|
60 |
+
|
61 |
+
corrected_paragraph = list(gf.correct(corrected_paragraph, max_candidates=1))[0]
|
62 |
+
print("[Corrected paragraph]", corrected_paragraph)
|
63 |
+
|
64 |
+
new_mistakes = []
|
65 |
+
for influent_sentence in influent_sentences:
|
66 |
+
corrected_sentences = gf.correct(influent_sentence, max_candidates=1)
|
67 |
+
print("[Input]", influent_sentence)
|
68 |
+
for corrected_sentence in corrected_sentences:
|
69 |
+
print("[Correction]", corrected_sentence)
|
70 |
+
new_mistakes += gf.get_edits(influent_sentence, corrected_sentence)
|
71 |
+
print("[Edits]", new_mistakes)
|
72 |
+
|
73 |
+
# If no new mistakes are found, exit the loop
|
74 |
+
if not new_mistakes:
|
75 |
+
break
|
76 |
+
|
77 |
+
# Add the new mistakes to the list
|
78 |
+
mistakes += new_mistakes
|
79 |
+
|
80 |
+
full_output = "Corrected Paragraph:\n" + corrected_paragraph + "\n\nMistakes:\n"
|
81 |
+
for index, (tag, mistake, start, end, correction, corr_start, corr_end) in enumerate(mistakes, start=1):
|
82 |
+
full_output += f"{index}. Tag: {tag}\n"
|
83 |
+
full_output += f" Mistake: {mistake} (Position: {start}-{end})\n"
|
84 |
+
full_output += f" Correction: {correction} (Position: {corr_start}-{corr_end})\n"
|
85 |
+
full_output += "\n"
|
86 |
+
|
87 |
+
print(full_output)
|
88 |
+
return {"message": "Message received successfully"}
|
|
|
89 |
|