Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
-
|
| 7 |
model_name = "HooshvareLab/bert-fa-base-uncased-sentiment-snappfood"
|
| 8 |
|
| 9 |
# تحميل الموديل والتوكنيزر
|
|
@@ -16,17 +16,21 @@ sentiment_analyzer = pipeline("sentiment-analysis", model=model, tokenizer=token
|
|
| 16 |
# دالة التحليل
|
| 17 |
def analyze_sentiment(text):
|
| 18 |
results = sentiment_analyzer(text)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
output = ""
|
| 20 |
for r in results:
|
| 21 |
label = r["label"]
|
|
|
|
| 22 |
score = round(r["score"], 3)
|
| 23 |
-
if label.lower() == "positive":
|
| 24 |
-
label_fa = "مثبت (إيجابي)"
|
| 25 |
-
elif label.lower() == "negative":
|
| 26 |
-
label_fa = "منفی (سلبي)"
|
| 27 |
-
else:
|
| 28 |
-
label_fa = "خنثی (محايد)"
|
| 29 |
output += f"{label_fa}: {score}\n"
|
|
|
|
| 30 |
return output
|
| 31 |
|
| 32 |
# واجهة Gradio
|
|
|
|
| 3 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
+
# موديل التحليل الفارسي
|
| 7 |
model_name = "HooshvareLab/bert-fa-base-uncased-sentiment-snappfood"
|
| 8 |
|
| 9 |
# تحميل الموديل والتوكنيزر
|
|
|
|
| 16 |
# دالة التحليل
|
| 17 |
def analyze_sentiment(text):
|
| 18 |
results = sentiment_analyzer(text)[0]
|
| 19 |
+
|
| 20 |
+
# احتمال تكون التسميات LABEL_0 / LABEL_1 / LABEL_2
|
| 21 |
+
labels_map = {
|
| 22 |
+
"LABEL_0": "منفی (سلبي)",
|
| 23 |
+
"LABEL_1": "خنثی (محايد)",
|
| 24 |
+
"LABEL_2": "مثبت (إيجابي)"
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
output = ""
|
| 28 |
for r in results:
|
| 29 |
label = r["label"]
|
| 30 |
+
label_fa = labels_map.get(label, label)
|
| 31 |
score = round(r["score"], 3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
output += f"{label_fa}: {score}\n"
|
| 33 |
+
|
| 34 |
return output
|
| 35 |
|
| 36 |
# واجهة Gradio
|