Spaces:
Running
Running
Delete Dockerfile
Browse files- Dockerfile +0 -109
Dockerfile
DELETED
@@ -1,109 +0,0 @@
|
|
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 |
-
|
9 |
-
# Initialize the English text classification pipeline for AI detection
|
10 |
-
pipeline_en = pipeline(task="text-classification", model="Hello-SimpleAI/chatgpt-detector-roberta")
|
11 |
-
|
12 |
-
# Function to predict the label and score for English text (AI Detection)
|
13 |
-
def predict_en(text):
|
14 |
-
res = pipeline_en(text)[0]
|
15 |
-
return res['label'], res['score']
|
16 |
-
|
17 |
-
# Ensure necessary NLTK data is downloaded for Humanifier
|
18 |
-
nltk.download('wordnet')
|
19 |
-
nltk.download('omw-1.4')
|
20 |
-
|
21 |
-
# Ensure the SpaCy model is installed for Humanifier
|
22 |
-
try:
|
23 |
-
nlp = spacy.load("en_core_web_sm")
|
24 |
-
except OSError:
|
25 |
-
subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
|
26 |
-
nlp = spacy.load("en_core_web_sm")
|
27 |
-
|
28 |
-
# Grammar, Tense, and Singular/Plural Correction Functions
|
29 |
-
|
30 |
-
# Correct article errors (e.g., "a apple" -> "an apple")
|
31 |
-
def check_article_error(text):
|
32 |
-
tokens = nltk.pos_tag(nltk.word_tokenize(text))
|
33 |
-
corrected_tokens = []
|
34 |
-
|
35 |
-
for i, token in enumerate(tokens):
|
36 |
-
word, pos = token
|
37 |
-
if word.lower() == 'a' and i < len(tokens) - 1 and tokens[i + 1][1] == 'NN':
|
38 |
-
corrected_tokens.append('an' if tokens[i + 1][0][0] in 'aeiou' else 'a')
|
39 |
-
else:
|
40 |
-
corrected_tokens.append(word)
|
41 |
-
|
42 |
-
return ' '.join(corrected_tokens)
|
43 |
-
|
44 |
-
# Correct tense errors (e.g., "She has go out" -> "She has gone out")
|
45 |
-
def check_tense_error(text):
|
46 |
-
tokens = nltk.pos_tag(nltk.word_tokenize(text))
|
47 |
-
corrected_tokens = []
|
48 |
-
|
49 |
-
for word, pos in tokens:
|
50 |
-
if word == "go" and pos == "VB":
|
51 |
-
corrected_tokens.append("gone")
|
52 |
-
elif word == "know" and pos == "VB":
|
53 |
-
corrected_tokens.append("known")
|
54 |
-
else:
|
55 |
-
corrected_tokens.append(word)
|
56 |
-
|
57 |
-
return ' '.join(corrected_tokens)
|
58 |
-
|
59 |
-
# Correct singular/plural errors (e.g., "There are many chocolate" -> "There are many chocolates")
|
60 |
-
def check_pluralization_error(text):
|
61 |
-
tokens = nltk.pos_tag(nltk.word_tokenize(text))
|
62 |
-
corrected_tokens = []
|
63 |
-
|
64 |
-
for word, pos in tokens:
|
65 |
-
if word == "chocolate" and pos == "NN":
|
66 |
-
corrected_tokens.append("chocolates")
|
67 |
-
elif word == "kids" and pos == "NNS":
|
68 |
-
corrected_tokens.append("kid")
|
69 |
-
else:
|
70 |
-
corrected_tokens.append(word)
|
71 |
-
|
72 |
-
return ' '.join(corrected_tokens)
|
73 |
-
|
74 |
-
# Combined function to correct grammar, tense, and singular/plural errors
|
75 |
-
def correct_grammar_tense_plural(text):
|
76 |
-
text = check_article_error(text)
|
77 |
-
text = check_tense_error(text)
|
78 |
-
text = check_pluralization_error(text)
|
79 |
-
return text
|
80 |
-
|
81 |
-
# Gradio app setup with three tabs
|
82 |
-
with gr.Blocks() as demo:
|
83 |
-
with gr.Tab("AI Detection"):
|
84 |
-
t1 = gr.Textbox(lines=5, label='Text')
|
85 |
-
button1 = gr.Button("🤖 Predict!")
|
86 |
-
label1 = gr.Textbox(lines=1, label='Predicted Label 🎃')
|
87 |
-
score1 = gr.Textbox(lines=1, label='Prob')
|
88 |
-
|
89 |
-
# Connect the prediction function to the button
|
90 |
-
button1.click(predict_en, inputs=[t1], outputs=[label1, score1], api_name='predict_en')
|
91 |
-
|
92 |
-
with gr.Tab("Humanifier"):
|
93 |
-
text_input = gr.Textbox(lines=5, label="Input Text")
|
94 |
-
paraphrase_button = gr.Button("Paraphrase & Correct")
|
95 |
-
output_text = gr.Textbox(label="Paraphrased Text")
|
96 |
-
|
97 |
-
# Connect the paraphrasing function to the button
|
98 |
-
paraphrase_button.click(paraphrase_and_correct, inputs=text_input, outputs=output_text)
|
99 |
-
|
100 |
-
with gr.Tab("Grammar Correction"):
|
101 |
-
grammar_input = gr.Textbox(lines=5, label="Input Text")
|
102 |
-
grammar_button = gr.Button("Correct Grammar")
|
103 |
-
grammar_output = gr.Textbox(label="Corrected Text")
|
104 |
-
|
105 |
-
# Connect the custom grammar, tense, and plural correction function to the button
|
106 |
-
grammar_button.click(correct_grammar_tense_plural, inputs=grammar_input, outputs=grammar_output)
|
107 |
-
|
108 |
-
# Launch the app with all functionalities
|
109 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|