NadaAlsuhaimi commited on
Commit
8c73c83
·
verified ·
1 Parent(s): 07bfcf5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ model_name = "CAMeL-Lab/bert-base-arabic-camelbert-da-sentiment"
5
+ sentiment_pipeline = pipeline("text-classification", model=model_name)
6
+
7
+ def analyze_sentiment(text):
8
+ if not text.strip():
9
+ return " من فضلك أدخل نصاً"
10
+
11
+ result = sentiment_pipeline(text)[0]
12
+ label = result["label"]
13
+ score = result["score"]
14
+
15
+ labels_map = {
16
+ "positive": "إيجابي ",
17
+ "negative": "سلبي ",
18
+ "neutral": "محايد "
19
+ }
20
+
21
+ arabic_label = labels_map.get(label.lower(), label)
22
+ confidence = f"{score * 100:.1f}%"
23
+
24
+ return f"**النتيجة:** {arabic_label}\n\n**نسبة الثقة:** {confidence}"
25
+
26
+
27
+ demo = gr.Interface(
28
+ fn=analyze_sentiment,
29
+ inputs=gr.Textbox(
30
+ label="أدخل النص العربي هنا",
31
+ placeholder="مثال: المنتج رائع وأنصح به الجميع",
32
+ lines=3
33
+ ),
34
+ outputs=gr.Markdown(label="التحليل"),
35
+ title="🔍 محلل المشاعر العربي",
36
+ description="تحليل النصوص العربية - إيجابي، سلبي، أو محايد",
37
+ examples=[
38
+ ["المنتج ممتاز وسعره مناسب جداً"],
39
+ ["خدمة سيئة جداً ولن أرجع مرة ثانية"],
40
+ ["المكان عادي لا بأس به"],
41
+ ]
42
+ )
43
+
44
+ demo.launch()
45
+