File size: 1,267 Bytes
ffee8e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 os
import telebot
from transformers import pipeline

# حطي التوكن كمتغير بيئة أو اكتبيه مؤقتاً هنا (بس لا ترفعيه على GitHub)
TELEGRAM_TOKEN = os.environ.get("TELEGRAM_TOKEN")  # الأفضل من متغير بيئة
# أو مؤقتاً:
# TELEGRAM_TOKEN = "1234567890:ABCDEF...."

bot = telebot.TeleBot(TELEGRAM_TOKEN)

sentiment_pipeline = pipeline(
    "text-classification",
    model="Nadasr/sentAnalysisModel",
    tokenizer="Nadasr/sentAnalysisModel",
    return_all_scores=False
)

@bot.message_handler(func=lambda message: True)
def handle_message(message):
    text = message.text.strip()
    if not text:
        bot.reply_to(message, "رجاءً أرسل نص عربي لتحليل مشاعره 🙂")
        return

    result = sentiment_pipeline(text)[0]
    label = result["label"]
    score = round(result["score"], 3)

    if label in ["LABEL_1", "POSITIVE", "positive"]:
        label_ar = "إيجابي 👍"
    elif label in ["LABEL_0", "NEGATIVE", "negative"]:
        label_ar = "سلبي 👎"
    else:
        label_ar = label

    reply = f"التصنيف: {label_ar}\nنسبة الثقة: {score}"
    bot.reply_to(message, reply)

print("Bot is running...")
bot.infinity_polling()