| import gradio as gr |
| import spacy |
| import os |
| import re |
| os.system("python -m spacy download en_core_web_sm") |
| nlp = spacy.load("en_core_web_sm") |
|
|
| def detect_ai_content(text): |
| |
| word_count = len(text.split()) |
|
|
| |
| doc = nlp(text) |
|
|
| |
| non_stopword_tokens = [token for token in doc if not token.is_stop] |
| non_stopword_count = len(non_stopword_tokens) |
|
|
| |
| percentage_ai = (1 - non_stopword_count / word_count) * 100 |
|
|
| |
| cleaned_text = re.sub(r'\s+', ' ', text).strip() |
| cleaned_text = re.sub(r'[^\w\s]', '', cleaned_text) |
|
|
| |
| return { |
| "text": cleaned_text, |
| "percentage": f"{percentage_ai:.2f}% AI-generated content" |
| } |
|
|
| gr.Interface(detect_ai_content, "text", "json").launch() |