import gradio as gr from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification from huggingface_hub import login # Dictionary of AI artifacts with explanations artifact_definitions = { "Repetition": "The same word or phrase is repeated unnaturally within the text. AI struggles to generate new, diverse text.", "Incoherent Phrases": "Sentences or phrases that don’t make sense when put together. Lack of contextual understanding.", "Ambiguous Pronouns": "Unclear references where pronouns like 'it' or 'they' don’t correspond clearly to any noun. Weakness in coreference resolution.", "Overuse of Filler Words": "Frequent use of words like 'however,' 'therefore,' or 'thus,' which don’t contribute to the meaning of the text. Model generates overly formal language.", "Generic Responses": "Vague answers or phrases that don’t provide meaningful information, such as 'it depends' or 'this is important.' Avoids specificity due to lack of information.", "Contradictions": "Statements in the generated text that contradict each other. Model struggles with logical consistency.", "Unnatural Syntax": "Phrases that sound robotic or awkward compared to natural human language. Incomplete grasp of human grammar nuances.", "Template-like Responses": "Responses that follow a rigid, repetitive format rather than natural flow. Over-reliance on training data patterns.", "Unnecessary Formality": "Overly formal or stiff language that feels unnatural in casual contexts. AI doesn’t adapt to tone appropriately.", "Incorrect Facts": "Inclusion of wrong or outdated information that was not verified. Lack of fact-checking abilities.", "Hallucinations": "Content or information generated by AI that has no basis in the input or training data. Model invents false information.", "Clichéd Phrases": "Overuse of common phrases or idioms that seem out of place in the text. Model mirrors over-represented text data.", "Overuse of Adverbs": "Excessive use of words like 'really,' 'very,' or 'extremely,' which don’t add to the meaning of the sentence. Attempts to mimic human emphasis poorly.", "Inconsistent Terminology": "Shifting between different terms for the same concept within a short text. Lack of term consistency management.", "Overgeneralization": "Statements that are too broad or generic, such as 'all people' or 'always.' AI fails to account for nuances or specifics.", "Lack of Subject-Specific Knowledge": "Responses that avoid deeper understanding of specialized topics. Insufficient training in specific domains.", "Awkward Phrasing": "Sentences that sound unnatural due to word order or selection. Lack of nuanced syntactic understanding.", "Redundancy": "Repetition of information or points already made earlier in the text. Fails to maintain conciseness.", "Unintended Humor": "Sentences that are accidentally funny due to odd phrasing or unexpected associations. AI misunderstanding of language subtleties." } # Load the model from Hugging Face # Replace with the actual username and repository name of your model model_name_or_path = "facebook/bart-large-mnli" # Example: Replace with your model repo name model = AutoModelForSequenceClassification.from_pretrained(model_name_or_path) tokenizer = AutoTokenizer.from_pretrained(model_name_or_path) # Create a pipeline for text classification artifact_classifier = pipeline("text-classification", model=model, tokenizer=tokenizer) # Function to detect AI artifacts and provide explanations def detect_artifacts(text): results = artifact_classifier(text) response = [] for result in results: label = result['label'] score = result['score'] explanation = artifact_definitions.get(label, "No explanation available.") response.append(f"**Artifact Detected**: {label}\n**Confidence**: {score:.2f}\n**Explanation**: {explanation}") return "\n\n".join(response) # Gradio interface setup interface = gr.Interface( fn=detect_artifacts, inputs="text", outputs="text", title="AI Artifact Detection", description=( "Paste AI-generated text to detect common AI artifacts, such as repetition, " "contradictions, or unnatural syntax. The app will also explain why these artifacts occur." ), examples=[ ["However, the issue was repeated multiple times, making it confusing and unclear."], ["The process was very redundant and robotic."], ["At the end of the day, this contradiction was unavoidable."] ] ) # Launch the Gradio app if __name__ == "__main__": interface.launch()