| 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() |
|
|