# -*- coding: utf-8 -*- import gradio as gr from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline # Load a general Arabic sentiment analysis model as a proxy for offensive language detection model_name = "nassga/arabic-offensive-comment-model" tokenizer = AutoTokenizer.from_pretrained(model_name) model = AutoModelForSequenceClassification.from_pretrained(model_name) # Create pipeline for classification classifier = pipeline("text-classification", model=model, tokenizer=tokenizer) def predict_offensive(text): result = classifier(text)[0] label = "Offensive" if result["label"] == "LABEL_1" else "Not Offensive" return f"{label} (Confidence: {result['score']:.2f})" gr.Interface( fn=predict_offensive, inputs=gr.Textbox(label="Enter a Kuwaiti Arabic Comment"), outputs=gr.Text(label="Prediction"), title="Kuwaiti Arabic Offensive Language Detector", description="Detects whether a comment is offensive using a fine-tuned Arabic BERT model." ).launch()