Upto12forenglish commited on
Commit
333f97c
1 Parent(s): 60acb5f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +42 -43
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
- # async def receive_message(message: Message):
48
- # print("Received message:", message.message)
49
- # influent_paragraph = message.message
50
- # corrected_paragraph = influent_paragraph # Initialize with the input text
51
- # mistakes_count = 0
52
- # mistakes = []
53
-
54
- # while True:
55
- # if mistakes_count == 5:
56
- # break
57
- # mistakes_count += 1
58
- # influent_sentences = list(nlp(corrected_paragraph).sents)
59
- # influent_sentences = [sentence.text for sentence in influent_sentences]
60
- # print("[Influent sentences]", influent_sentences)
61
-
62
- # corrected_paragraph = list(gf.correct(corrected_paragraph, max_candidates=1))[0]
63
- # print("[Corrected paragraph]", corrected_paragraph)
64
-
65
- # new_mistakes = []
66
- # for influent_sentence in influent_sentences:
67
- # corrected_sentences = gf.correct(influent_sentence, max_candidates=1)
68
- # print("[Input]", influent_sentence)
69
- # for corrected_sentence in corrected_sentences:
70
- # print("[Correction]", corrected_sentence)
71
- # new_mistakes += gf.get_edits(influent_sentence, corrected_sentence)
72
- # print("[Edits]", new_mistakes)
73
-
74
- # # If no new mistakes are found, exit the loop
75
- # if not new_mistakes:
76
- # break
77
-
78
- # # Add the new mistakes to the list
79
- # mistakes += new_mistakes
80
-
81
- # full_output = "Corrected Paragraph:\n" + corrected_paragraph + "\n\nMistakes:\n"
82
- # for index, (tag, mistake, start, end, correction, corr_start, corr_end) in enumerate(mistakes, start=1):
83
- # full_output += f"{index}. Tag: {tag}\n"
84
- # full_output += f" Mistake: {mistake} (Position: {start}-{end})\n"
85
- # full_output += f" Correction: {correction} (Position: {corr_start}-{corr_end})\n"
86
- # full_output += "\n"
87
-
88
- # print(full_output)
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