File size: 1,063 Bytes
e39313b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline


model_id = "Nadasr/sentAnalysisModel"

classifier = pipeline(
    "text-classification",
    model=model_id,
    tokenizer=model_id,
    return_all_scores=False
)


label_map = {
    "LABEL_0": "سلبي",
    "LABEL_1": "إيجابي",
    "0": "سلبي",
    "1": "إيجابي",
}

def predict(text):
    text = text.strip()
    if not text:
        return "اكتب الجملة أولاً 🙂"

    result = classifier(text)[0]
    label = label_map.get(result["label"], result["label"])
    score = round(float(result["score"]), 3)
    return f"{label} (score = {score})"

demo = gr.Interface(
    fn=predict,
    inputs=gr.Textbox(lines=3, label="النص العربي"),
    outputs=gr.Textbox(label="نتيجة التحليل"),
    title="نموذج تحليل المشاعر بالعربية",
    description="أدخل الجملة وسيتم تصنيفها إلى إيجابي أو سلبي."
)

if __name__ == "__main__":
    demo.launch()