CoolFace
Apppublic

imseldrith/ChatGPT-Detection

sourceHugging Facegplupdated 3y agoView on Hugging Face
2likes
app.py32 linesDownload Raw Back to root
1import gradio as gr2import spacy3import os4import re5os.system("python -m spacy download en_core_web_sm")6nlp = spacy.load("en_core_web_sm")7 8def detect_ai_content(text):9    # Count the number of words in the text10    word_count = len(text.split())11 12    # Analyze the text using Spacy13    doc = nlp(text)14 15    # Count the number of tokens that are not in Spacy's default stop word list16    non_stopword_tokens = [token for token in doc if not token.is_stop]17    non_stopword_count = len(non_stopword_tokens)18 19    # Calculate the percentage of non-stopword tokens20    percentage_ai = (1 - non_stopword_count / word_count) * 10021 22    # Clean the text by removing extra spaces, line breaks and special characters23    cleaned_text = re.sub(r'\s+', ' ', text).strip()24    cleaned_text = re.sub(r'[^\w\s]', '', cleaned_text)25 26    # Return a dictionary with the percentage of AI-generated content and the cleaned text27    return {28        "text": cleaned_text,29        "percentage": f"{percentage_ai:.2f}% AI-generated content"30    }31 32gr.Interface(detect_ai_content, "text", "json").launch()