import gradio as gr from transformers import pipeline # Load the hate speech detection model from Hugging Face classifier = pipeline("text-classification", model="unitary/unbiased-toxic-roberta") def detect_hate_speech(text): """Detect hate speech in the given text.""" sentences = text.split(".") hate_speech = [] for sentence in sentences: if sentence.strip(): result = classifier(sentence.strip())[0] if result["label"] in ["toxic", "insult", "hate"]: hate_speech.append(sentence.strip()) return hate_speech if hate_speech else "No hate speech detected" # Create Gradio interface iface = gr.Interface( fn=detect_hate_speech, inputs=gr.Textbox(lines=5, placeholder="Enter text here..."), outputs="json", title="Hate Speech Detection", description="Enter a sentence or paragraph to check for hate speech.", ) # Launch the app iface.launch()