sashtech commited on
Commit
4faf0a2
·
verified ·
1 Parent(s): 2174db5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -23
app.py CHANGED
@@ -11,11 +11,19 @@ import random
11
  import string
12
 
13
  # Ensure necessary NLTK data is downloaded
14
- nltk.download('punkt')
15
- nltk.download('stopwords')
16
- nltk.download('averaged_perceptron_tagger')
17
- nltk.download('wordnet')
18
- nltk.download('omw-1.4')
 
 
 
 
 
 
 
 
19
 
20
  top_words = set(stopwords.words("english")) # More efficient as a set
21
 
@@ -207,27 +215,25 @@ def correct_spelling(text):
207
  # Main function for paraphrasing and grammar correction
208
  def paraphrase_and_correct(text):
209
  cleaned_text = remove_redundant_words(text)
 
 
 
 
 
 
 
 
210
  plag_removed = plagiarism_removal(cleaned_text)
211
- paraphrased_text = capitalize_sentences_and_nouns(plag_removed)
212
- paraphrased_text = force_first_letter_capital(paraphrased_text)
213
- paraphrased_text = correct_article_errors(paraphrased_text)
214
- paraphrased_text = correct_tense_errors(paraphrased_text)
215
- paraphrased_text = ensure_subject_verb_agreement(paraphrased_text)
216
- paraphrased_text = fix_possessives(paraphrased_text)
217
- paraphrased_text = correct_spelling(paraphrased_text)
218
- paraphrased_text = fix_punctuation_spacing(paraphrased_text)
219
-
220
- return paraphrased_text
221
-
222
- # Gradio app setup
223
  with gr.Blocks() as demo:
 
224
  with gr.Tab("AI Detection"):
225
- t1 = gr.Textbox(lines=5, label='Text')
226
- button1 = gr.Button("🤖 Predict!")
227
- label1 = gr.Textbox(lines=1, label='Predicted Label 🎃')
228
- score1 = gr.Textbox(lines=1, label='Prob')
229
-
230
- button1.click(fn=predict_en, inputs=t1, outputs=[label1, score1])
231
 
232
  with gr.Tab("Paraphrasing and Grammar Correction"):
233
  t2 = gr.Textbox(lines=5, label='Input Text')
 
11
  import string
12
 
13
  # Ensure necessary NLTK data is downloaded
14
+ def download_nltk_resources():
15
+ try:
16
+ nltk.download('punkt')
17
+ nltk.download('stopwords')
18
+ nltk.download('averaged_perceptron_tagger')
19
+ nltk.download('wordnet')
20
+ nltk.download('omw-1.4')
21
+ nltk.download('punkt_tab') # Added punkt_tab download
22
+ except Exception as e:
23
+ print(f"Error downloading NLTK resources: {e}")
24
+
25
+ # Call the download function
26
+ download_nltk_resources()
27
 
28
  top_words = set(stopwords.words("english")) # More efficient as a set
29
 
 
215
  # Main function for paraphrasing and grammar correction
216
  def paraphrase_and_correct(text):
217
  cleaned_text = remove_redundant_words(text)
218
+ cleaned_text = fix_punctuation_spacing(cleaned_text)
219
+ cleaned_text = fix_possessives(cleaned_text)
220
+ cleaned_text = capitalize_sentences_and_nouns(cleaned_text)
221
+ cleaned_text = force_first_letter_capital(cleaned_text)
222
+ cleaned_text = correct_tense_errors(cleaned_text)
223
+ cleaned_text = correct_article_errors(cleaned_text)
224
+ cleaned_text = ensure_subject_verb_agreement(cleaned_text)
225
+ cleaned_text = correct_spelling(cleaned_text)
226
  plag_removed = plagiarism_removal(cleaned_text)
227
+ return plag_removed
228
+
229
+ # Create the Gradio interface
 
 
 
 
 
 
 
 
 
230
  with gr.Blocks() as demo:
231
+ gr.Markdown("# AI Text Processor")
232
  with gr.Tab("AI Detection"):
233
+ t1 = gr.Textbox(lines=5, label='Input Text')
234
+ output1 = gr.Label()
235
+ button1 = gr.Button("🚀 Process!")
236
+ button1.click(fn=predict_en, inputs=t1, outputs=output1)
 
 
237
 
238
  with gr.Tab("Paraphrasing and Grammar Correction"):
239
  t2 = gr.Textbox(lines=5, label='Input Text')