Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -25,14 +25,14 @@ word_vectors = api.load("glove-wiki-gigaword-50")
|
|
25 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
26 |
|
27 |
# Load AI Detector model and tokenizer from Hugging Face (DistilBERT)
|
28 |
-
|
29 |
-
|
30 |
|
31 |
# AI detection function using DistilBERT
|
32 |
def detect_ai_generated(text):
|
33 |
-
inputs =
|
34 |
with torch.no_grad():
|
35 |
-
outputs =
|
36 |
probabilities = torch.softmax(outputs.logits, dim=1)
|
37 |
ai_probability = probabilities[0][1].item() # Probability of being AI-generated
|
38 |
return f"AI-Generated Content Probability: {ai_probability:.2f}%"
|
@@ -96,6 +96,16 @@ def paraphrase_with_spacy_nltk(text):
|
|
96 |
|
97 |
return corrected_text
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
# Gradio interface definition
|
100 |
with gr.Blocks() as interface:
|
101 |
with gr.Row():
|
@@ -107,7 +117,7 @@ with gr.Blocks() as interface:
|
|
107 |
output_text = gr.Textbox(label="Output")
|
108 |
|
109 |
detect_button.click(detect_ai_generated, inputs=text_input, outputs=output_text)
|
110 |
-
paraphrase_button.click(
|
111 |
|
112 |
# Launch the Gradio app
|
113 |
interface.launch(debug=False)
|
|
|
25 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
26 |
|
27 |
# Load AI Detector model and tokenizer from Hugging Face (DistilBERT)
|
28 |
+
tokenizer_ai = AutoTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
29 |
+
model_ai = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english").to(device)
|
30 |
|
31 |
# AI detection function using DistilBERT
|
32 |
def detect_ai_generated(text):
|
33 |
+
inputs = tokenizer_ai(text, return_tensors="pt", truncation=True, max_length=512).to(device)
|
34 |
with torch.no_grad():
|
35 |
+
outputs = model_ai(**inputs)
|
36 |
probabilities = torch.softmax(outputs.logits, dim=1)
|
37 |
ai_probability = probabilities[0][1].item() # Probability of being AI-generated
|
38 |
return f"AI-Generated Content Probability: {ai_probability:.2f}%"
|
|
|
96 |
|
97 |
return corrected_text
|
98 |
|
99 |
+
# Combined function: Paraphrase -> Capitalization
|
100 |
+
def paraphrase_and_correct(text):
|
101 |
+
# Step 1: Paraphrase the text
|
102 |
+
paraphrased_text = paraphrase_with_spacy_nltk(text)
|
103 |
+
|
104 |
+
# Step 2: Capitalize sentences and proper nouns
|
105 |
+
final_text = capitalize_sentences_and_nouns(paraphrased_text)
|
106 |
+
|
107 |
+
return final_text
|
108 |
+
|
109 |
# Gradio interface definition
|
110 |
with gr.Blocks() as interface:
|
111 |
with gr.Row():
|
|
|
117 |
output_text = gr.Textbox(label="Output")
|
118 |
|
119 |
detect_button.click(detect_ai_generated, inputs=text_input, outputs=output_text)
|
120 |
+
paraphrase_button.click(paraphrase_and_correct, inputs=text_input, outputs=output_text)
|
121 |
|
122 |
# Launch the Gradio app
|
123 |
interface.launch(debug=False)
|