| import gradio as gr |
| from transformers import pipeline |
|
|
| model_name = "CAMeL-Lab/bert-base-arabic-camelbert-da-sentiment" |
| sentiment_pipeline = pipeline("text-classification", model=model_name) |
|
|
| def analyze_sentiment(text): |
| if not text.strip(): |
| return " من فضلك أدخل نصاً" |
| |
| result = sentiment_pipeline(text)[0] |
| label = result["label"] |
| score = result["score"] |
| |
| labels_map = { |
| "positive": "إيجابي ", |
| "negative": "سلبي ", |
| "neutral": "محايد " |
| } |
| |
| arabic_label = labels_map.get(label.lower(), label) |
| confidence = f"{score * 100:.1f}%" |
| |
| return f"**النتيجة:** {arabic_label}\n\n**نسبة الثقة:** {confidence}" |
|
|
|
|
| demo = gr.Interface( |
| fn=analyze_sentiment, |
| inputs=gr.Textbox( |
| label="أدخل النص العربي هنا", |
| placeholder="مثال: المنتج رائع وأنصح به الجميع", |
| lines=3 |
| ), |
| outputs=gr.Markdown(label="التحليل"), |
| title="🔍 محلل المشاعر العربي", |
| description="تحليل النصوص العربية - إيجابي، سلبي، أو محايد", |
| examples=[ |
| ["المنتج ممتاز وسعره مناسب جداً"], |
| ["خدمة سيئة جداً ولن أرجع مرة ثانية"], |
| ["المكان عادي لا بأس به"], |
| ] |
| ) |
|
|
| demo.launch() |
|
|
|
|