Abdulrahman Al-Ghamdi
Rename code.py to app.py
494ddbd verified
raw
history blame
1.77 kB
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()