|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
model_name = "Abduuu/ArabReview-Sentiment" |
|
sentiment_pipeline = pipeline("text-classification", model=model_name, tokenizer=model_name) |
|
|
|
|
|
label_mapping = {"LABEL_0": "Negative 😞", "LABEL_1": "Positive 😊"} |
|
|
|
|
|
def predict_sentiment(review): |
|
result = sentiment_pipeline(review)[0] |
|
sentiment_label = label_mapping[result["label"]] |
|
confidence = f"{result['score']:.2f}" |
|
return f"Sentiment: {sentiment_label} | Confidence: {confidence}" |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_sentiment, |
|
inputs=gr.Textbox(label="Enter Your Restaurant Review", placeholder="اكتب مراجعتك هنا..."), |
|
outputs=gr.Textbox(label="Predicted Sentiment", interactive=False), |
|
title="🍽️ Arabic Restaurant Review Sentiment Analysis 🚀", |
|
description="Enter an Arabic restaurant review, and the model will predict whether it's **Positive 😊** or **Negative 😞**.", |
|
examples=[ |
|
["الطعام لذيذ جدًا والخدمة رائعة!"], |
|
["التجربة كانت مريعة، الطعام كان سيئًا جدًا!"], |
|
["السعر مرتفع جدًا مقابل الجودة المتوسطة."], |
|
["لن أعود إلى هذا المكان أبدًا، أسوأ تجربة لي!"], |
|
["أفضل مطعم زرته في حياتي!"], |
|
], |
|
allow_flagging="never" |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
iface.launch() |
|
|