hatespeech / app.py
sandbox338's picture
Update app.py
5ddfe23 verified
raw
history blame
788 Bytes
import gradio as gr
from transformers import pipeline
# Load the model from Hugging Face Hub
classifier = pipeline("text-classification", model="sandbox338/hatespeech")
# Define the function for the interface
def classify_text(text):
results = classifier(text)
# Sort by score and show top result
return f"{results[0]['label']} ({results[0]['score']:.2f})"
# Create the interface
interface = gr.Interface(
fn=classify_text,
inputs=gr.Textbox(lines=4, placeholder="Enter Swahili text here..."),
outputs="text",
title="Swahili Hate Speech Classifier",
description="Classifies text as Non-hate speech, Political hate speech, or Offensive language."
)
# Launch the interface (only used if running locally)
if __name__ == "__main__":
interface.launch()