File size: 2,919 Bytes
5d6bb57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import random
import time

def analyze_sentiment(text):
    """
    Simulates the sentiment analysis model.
    """
    positive_keywords = ['خوب', 'عالی', 'خوشحال', 'محشر', 'دوست', 'عشق', 'موفق', 'سالم', 'خنده', '🙂', '😊', '❤️', 'good', 'great', 'love']
    negative_keywords = ['بد', 'غمگین', 'ترس', 'تنفر', 'مرگ', 'درد', 'خسته', 'مشکل', '😔', '😢', '😡', 'bad', 'sad', 'hate']

    text_lower = text.lower()
    
    pos_count = sum(1 for word in positive_keywords if word in text_lower)
    neg_count = sum(1 for word in negative_keywords if word in text_lower)

    if pos_count > neg_count:
        label = "POSITIVE"
        score = random.uniform(0.7, 0.99)
    elif neg_count > pos_count:
        label = "NEGATIVE"
        score = random.uniform(0.7, 0.99)
    else:
        label = "NEUTRAL"
        score = random.uniform(0.4, 0.6)

    return {"label": label, "score": score}

def generate_ai_response(text):
    """Generates a response based on sentiment."""
    result = analyze_sentiment(text)
    label = result['label']
    score = f"{result['score']*100:.1f}"

    if label == "POSITIVE":
        return f"😊 خوشحالم که حالتان خوب است! (اطمینان: {score}%)"
    elif label == "NEGATIVE":
        return f"😔 متاسفم که اینطور احساس می‌کنید. امیدوارم روزتان بهتر شود. (اطمینان: {score}%)"
    else:
        return f"🤔 پیام شما دریافت شد. (اطمینان: {score}%)"

def get_mock_rooms():
    return [
        {"id": 1, "name": "اتاق عمومی", "description": "گفتگوی آزاد"},
        {"id": 2, "name": "گفتگوی فنی", "description": "بحث درباره برنامه نویسی"},
        {"id": 3, "name": "پشتیبانی", "description": "سوالات و پاسخ‌ها"}
    ]

def get_mock_users():
    return [
        {"id": 1, "name": "علی رضایی", "online": True},
        {"id": 2, "name": "سارا محمدی", "online": True},
        {"id": 3, "name": "رضا کریمی", "online": False},
        {"id": 4, "name": "مریم حسینی", "online": True},
        {"id": 5, "name": "سیستم ادمین", "online": True},
    ]

def get_initial_messages():
    return [
        {
            "id": 1,
            "room_id": 1,
            "user_id": "admin",
            "username": "سیستم ادمین",
            "text": "به چت روم خوش آمدید! لطفاً قوانین را رعایت کنید.",
            "time": "10:00",
            "is_deleted": False
        },
        {
            "id": 2,
            "room_id": 1,
            "user_id": "user1",
            "username": "علی رضایی",
            "text": "سلام به همه! حالتون چطوره؟",
            "time": "10:05",
            "is_deleted": False
        }
    ]