Abdulrahman Al-Ghamdi
commited on
Create code.py
Browse files
code.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the sentiment analysis pipeline using your fine-tuned model
|
5 |
+
model_name = "Abduuu/ArabReview-Sentiment"
|
6 |
+
sentiment_pipeline = pipeline("text-classification", model=model_name, tokenizer=model_name)
|
7 |
+
|
8 |
+
# Define label mapping for better readability
|
9 |
+
label_mapping = {"LABEL_0": "Negative 😞", "LABEL_1": "Positive 😊"}
|
10 |
+
|
11 |
+
# Define a function for sentiment prediction
|
12 |
+
def predict_sentiment(review):
|
13 |
+
result = sentiment_pipeline(review)[0]
|
14 |
+
sentiment_label = label_mapping[result["label"]]
|
15 |
+
confidence = f"{result['score']:.2f}"
|
16 |
+
return f"Sentiment: {sentiment_label} | Confidence: {confidence}"
|
17 |
+
|
18 |
+
# Define Gradio interface
|
19 |
+
iface = gr.Interface(
|
20 |
+
fn=predict_sentiment, # Function for sentiment prediction
|
21 |
+
inputs=gr.Textbox(label="Enter Your Restaurant Review", placeholder="اكتب مراجعتك هنا..."),
|
22 |
+
outputs=gr.Textbox(label="Predicted Sentiment", interactive=False),
|
23 |
+
title="🍽️ Arabic Restaurant Review Sentiment Analysis 🚀",
|
24 |
+
description="Enter an Arabic restaurant review, and the model will predict whether it's **Positive 😊** or **Negative 😞**.",
|
25 |
+
examples=[
|
26 |
+
["الطعام لذيذ جدًا والخدمة رائعة!"], # Positive
|
27 |
+
["التجربة كانت مريعة، الطعام كان سيئًا جدًا!"], # Negative
|
28 |
+
["السعر مرتفع جدًا مقابل الجودة المتوسطة."], # Neutral
|
29 |
+
["لن أعود إلى هذا المكان أبدًا، أسوأ تجربة لي!"], # Negative
|
30 |
+
["أفضل مطعم زرته في حياتي!"], # Positive
|
31 |
+
],
|
32 |
+
allow_flagging="never" # Disables user flagging for simplicity
|
33 |
+
)
|
34 |
+
|
35 |
+
# Launch the app
|
36 |
+
if __name__ == "__main__":
|
37 |
+
iface.launch()
|