File size: 1,774 Bytes
950f4ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import gradio as gr
from transformers import pipeline

# Load the sentiment analysis pipeline using your fine-tuned model
model_name = "Abduuu/ArabReview-Sentiment"
sentiment_pipeline = pipeline("text-classification", model=model_name, tokenizer=model_name)

# Define label mapping for better readability
label_mapping = {"LABEL_0": "Negative 😞", "LABEL_1": "Positive 😊"}

# Define a function for sentiment prediction
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}"

# Define Gradio interface
iface = gr.Interface(
    fn=predict_sentiment,  # Function for sentiment prediction
    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=[
        ["الطعام لذيذ جدًا والخدمة رائعة!"],  # Positive
        ["التجربة كانت مريعة، الطعام كان سيئًا جدًا!"],  # Negative
        ["السعر مرتفع جدًا مقابل الجودة المتوسطة."],  # Neutral
        ["لن أعود إلى هذا المكان أبدًا، أسوأ تجربة لي!"],  # Negative
        ["أفضل مطعم زرته في حياتي!"],  # Positive
    ],
    allow_flagging="never"  # Disables user flagging for simplicity
)

# Launch the app
if __name__ == "__main__":
    iface.launch()