Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,8 @@
|
|
| 1 |
-
import os
|
| 2 |
import gradio as gr
|
| 3 |
-
from transformers import pipeline
|
| 4 |
import spacy
|
| 5 |
import subprocess
|
| 6 |
import nltk
|
| 7 |
from nltk.corpus import wordnet
|
| 8 |
-
from gensim import downloader as api
|
| 9 |
|
| 10 |
# Ensure necessary NLTK data is downloaded
|
| 11 |
nltk.download('wordnet')
|
|
@@ -18,24 +15,6 @@ except OSError:
|
|
| 18 |
subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
|
| 19 |
nlp = spacy.load("en_core_web_sm")
|
| 20 |
|
| 21 |
-
# Load a smaller Word2Vec model from Gensim's pre-trained models
|
| 22 |
-
word_vectors = api.load("glove-wiki-gigaword-50")
|
| 23 |
-
|
| 24 |
-
# Load the English AI detection pipeline using the Hello-SimpleAI model
|
| 25 |
-
pipeline_en = pipeline(task="text-classification", model="Hello-SimpleAI/chatgpt-detector-roberta")
|
| 26 |
-
|
| 27 |
-
# AI detection function using the Hello-SimpleAI/chatgpt-detector-roberta model
|
| 28 |
-
def detect_ai_generated(text):
|
| 29 |
-
res = pipeline_en(text)[0]
|
| 30 |
-
label = res['label'] # "LABEL_0" or "LABEL_1"
|
| 31 |
-
score = res['score'] * 100 # Convert probability to percentage
|
| 32 |
-
|
| 33 |
-
# Map the model's label to human-readable label
|
| 34 |
-
human_readable_label = "AI" if label == "LABEL_1" else "Human"
|
| 35 |
-
|
| 36 |
-
# Return formatted string with label and percentage score
|
| 37 |
-
return f"The content is {score:.2f}% {human_readable_label} Written", score
|
| 38 |
-
|
| 39 |
# Function to get synonyms using NLTK WordNet
|
| 40 |
def get_synonyms_nltk(word, pos):
|
| 41 |
synsets = wordnet.synsets(word, pos=pos)
|
|
@@ -105,19 +84,16 @@ def paraphrase_and_correct(text):
|
|
| 105 |
|
| 106 |
return final_text
|
| 107 |
|
| 108 |
-
# Gradio interface
|
| 109 |
-
with gr.Blocks() as
|
| 110 |
with gr.Row():
|
| 111 |
with gr.Column():
|
| 112 |
text_input = gr.Textbox(lines=5, label="Input Text")
|
| 113 |
-
detect_button = gr.Button("AI Detection")
|
| 114 |
paraphrase_button = gr.Button("Paraphrase & Correct")
|
| 115 |
with gr.Column():
|
| 116 |
-
|
| 117 |
-
output_prob = gr.Textbox(label="Probability (%)")
|
| 118 |
|
| 119 |
-
|
| 120 |
-
paraphrase_button.click(paraphrase_and_correct, inputs=text_input, outputs=output_label)
|
| 121 |
|
| 122 |
-
# Launch the Gradio app
|
| 123 |
-
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import spacy
|
| 3 |
import subprocess
|
| 4 |
import nltk
|
| 5 |
from nltk.corpus import wordnet
|
|
|
|
| 6 |
|
| 7 |
# Ensure necessary NLTK data is downloaded
|
| 8 |
nltk.download('wordnet')
|
|
|
|
| 15 |
subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
|
| 16 |
nlp = spacy.load("en_core_web_sm")
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# Function to get synonyms using NLTK WordNet
|
| 19 |
def get_synonyms_nltk(word, pos):
|
| 20 |
synsets = wordnet.synsets(word, pos=pos)
|
|
|
|
| 84 |
|
| 85 |
return final_text
|
| 86 |
|
| 87 |
+
# Gradio interface for paraphrasing and text correction
|
| 88 |
+
with gr.Blocks() as paraphrase_interface:
|
| 89 |
with gr.Row():
|
| 90 |
with gr.Column():
|
| 91 |
text_input = gr.Textbox(lines=5, label="Input Text")
|
|
|
|
| 92 |
paraphrase_button = gr.Button("Paraphrase & Correct")
|
| 93 |
with gr.Column():
|
| 94 |
+
output_text = gr.Textbox(label="Paraphrased Text")
|
|
|
|
| 95 |
|
| 96 |
+
paraphrase_button.click(paraphrase_and_correct, inputs=text_input, outputs=output_text)
|
|
|
|
| 97 |
|
| 98 |
+
# Launch the Gradio app for paraphrasing and text correction
|
| 99 |
+
paraphrase_interface.launch(debug=False)
|