sentiment-ar / app.py
Nadasr's picture
Update app.py
e77e5c1 verified
import gradio as gr
from transformers import pipeline
sentiment_pipeline = pipeline(
"text-classification",
model="Nadasr/sentAnalysisModel",
tokenizer="Nadasr/sentAnalysisModel",
return_all_scores=False # يرجع أفضل لابل فقط
)
def predict_sentiment(text):
text = text.strip()
if not text:
return "رجاءً أدخل نصاً للتصنيف 🙂"
result = sentiment_pipeline(text)[0]
label = result["label"]
score = round(result["score"], 3)
if label in ["LABEL_1", "POSITIVE", "positive"]:
label_ar = "إيجابي 👍"
elif label in ["LABEL_0", "NEGATIVE", "negative"]:
label_ar = "سلبي 👎"
else:
label_ar = label
return f"{label_ar} (الاحتمال = {score})"
demo = gr.Interface(
fn=predict_sentiment,
inputs=gr.Textbox(lines=4, label="أدخل النص العربي هنا"),
outputs=gr.Textbox(label="نتيجة التصنيف"),
title="Arabic Sentiment Analysis",
description="نموذج لتحليل المشاعر للنصوص العربية (إيجابي / سلبي)."
)
if __name__ == "__main__":
demo.launch()