import gradio as gr from transformers import pipeline # Load the sentiment analysis pipeline model_name = "monsifnadir/DarijaBERT-Sentiment" # Change if necessary sentiment_pipeline = pipeline("text-classification", model=model_name) # Map numerical labels to sentiment categories label_map = { "LABEL_0": "Negative", "LABEL_1": "Neutral", "LABEL_2": "Positive" } def classify_text(text): result = sentiment_pipeline(text) label = result[0]["label"] score = result[0]["score"] # Map the label to actual sentiment sentiment = label_map.get(label, "Unknown") return f"Sentiment: {sentiment} (Confidence: {score:.2f})" # Create Gradio interface iface = gr.Interface( fn=classify_text, inputs=gr.Textbox(lines=2, placeholder="Enter a Darija sentence..."), outputs="text", title="Darija Sentiment Analysis", description="Enter a text in Darija to analyze its sentiment (Positive, Negative, Neutral)." ) # Launch the app iface.launch()