Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
model_id = "Nadasr/sentAnalysisModel"
|
| 6 |
+
|
| 7 |
+
classifier = pipeline(
|
| 8 |
+
"text-classification",
|
| 9 |
+
model=model_id,
|
| 10 |
+
tokenizer=model_id,
|
| 11 |
+
return_all_scores=False
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
label_map = {
|
| 16 |
+
"LABEL_0": "سلبي",
|
| 17 |
+
"LABEL_1": "إيجابي",
|
| 18 |
+
"0": "سلبي",
|
| 19 |
+
"1": "إيجابي",
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
def predict(text):
|
| 23 |
+
text = text.strip()
|
| 24 |
+
if not text:
|
| 25 |
+
return "اكتب الجملة أولاً 🙂"
|
| 26 |
+
|
| 27 |
+
result = classifier(text)[0]
|
| 28 |
+
label = label_map.get(result["label"], result["label"])
|
| 29 |
+
score = round(float(result["score"]), 3)
|
| 30 |
+
return f"{label} (score = {score})"
|
| 31 |
+
|
| 32 |
+
demo = gr.Interface(
|
| 33 |
+
fn=predict,
|
| 34 |
+
inputs=gr.Textbox(lines=3, label="النص العربي"),
|
| 35 |
+
outputs=gr.Textbox(label="نتيجة التحليل"),
|
| 36 |
+
title="نموذج تحليل المشاعر بالعربية",
|
| 37 |
+
description="أدخل الجملة وسيتم تصنيفها إلى إيجابي أو سلبي."
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
demo.launch()
|