sashdev commited on
Commit
f179ad1
·
verified ·
1 Parent(s): a30dc01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -2
app.py CHANGED
@@ -189,6 +189,20 @@ def correct_spelling(text):
189
  corrected_words.append(word)
190
  return ' '.join(corrected_words)
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  def paraphrase_and_correct(text):
193
  paragraphs = text.split("\n\n") # Split by paragraphs
194
 
@@ -205,10 +219,11 @@ def paraphrase_and_correct(text):
205
  paraphrased_text = fix_possessives(paraphrased_text)
206
  paraphrased_text = correct_spelling(paraphrased_text)
207
  paraphrased_text = fix_punctuation_spacing(paraphrased_text)
208
- processed_paragraphs.append(paraphrased_text)
209
 
210
- return "\n\n".join(processed_paragraphs) # Reassemble the text with paragraphs
 
211
 
 
212
  # Gradio app setup
213
  with gr.Blocks() as demo:
214
  with gr.Tab("AI Detection"):
 
189
  corrected_words.append(word)
190
  return ' '.join(corrected_words)
191
 
192
+
193
+
194
+
195
+ def correct_grammar_with_gpt(text):
196
+ # Initialize a pipeline for text generation with a suitable model for grammar correction
197
+ gpt_model = pipeline("text-generation", model="gpt2") # Replace with a grammar correction model if available
198
+
199
+ # Generate a corrected version of the text
200
+ corrected_output = gpt_model(text, max_length=100)[0]['generated_text']
201
+
202
+ return corrected_output.strip()
203
+
204
+
205
+
206
  def paraphrase_and_correct(text):
207
  paragraphs = text.split("\n\n") # Split by paragraphs
208
 
 
219
  paraphrased_text = fix_possessives(paraphrased_text)
220
  paraphrased_text = correct_spelling(paraphrased_text)
221
  paraphrased_text = fix_punctuation_spacing(paraphrased_text)
 
222
 
223
+ # Use GPT for final grammar correction
224
+ final_corrected_text = correct_grammar_with_gpt(paraphrased_text)
225
 
226
+ return final_corrected_text
227
  # Gradio app setup
228
  with gr.Blocks() as demo:
229
  with gr.Tab("AI Detection"):