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 } ]