File size: 10,176 Bytes
6f5bdf6
 
 
de6a6a6
 
6f5bdf6
de6a6a6
6f5bdf6
 
 
 
 
 
de6a6a6
6f5bdf6
 
 
 
de6a6a6
6f5bdf6
 
 
 
de6a6a6
6f5bdf6
 
 
 
de6a6a6
6f5bdf6
 
 
 
de6a6a6
6f5bdf6
 
 
 
 
 
 
de6a6a6
6f5bdf6
 
 
 
de6a6a6
6f5bdf6
 
 
 
de6a6a6
6f5bdf6
 
 
 
de6a6a6
 
6f5bdf6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de6a6a6
6f5bdf6
 
 
 
de6a6a6
6f5bdf6
 
 
 
de6a6a6
6f5bdf6
 
 
 
de6a6a6
 
 
6f5bdf6
 
 
 
de6a6a6
6f5bdf6
 
 
de6a6a6
6f5bdf6
 
 
de6a6a6
6f5bdf6
 
de6a6a6
6f5bdf6
 
 
 
de6a6a6
6f5bdf6
 
de6a6a6
6f5bdf6
de6a6a6
6f5bdf6
 
 
 
de6a6a6
6f5bdf6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de6a6a6
6f5bdf6
 
 
 
 
 
 
 
 
de6a6a6
6f5bdf6
 
de6a6a6
6f5bdf6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de6a6a6
6f5bdf6
 
de6a6a6
6f5bdf6
 
 
 
de6a6a6
6f5bdf6
de6a6a6
6f5bdf6
 
 
 
 
de6a6a6
6f5bdf6
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import json
import random
from typing import Dict, List, Optional

class KiswahiliKnowledgeBase:
    """Knowledge base for Kiswahili language and East African culture"""
    
    def __init__(self):
        self.proverbs = [
            {
                "swahili": "Mwacha mila ni mtumwa.",
                "english": "He who abandons his culture is a slave.",
                "meaning": "One should cherish and preserve their cultural heritage."
            },
            {
                "swahili": "Haraka haraka haina baraka.",
                "english": "Hurry hurry has no blessing.",
                "meaning": "Rushing leads to mistakes; patience yields better results."
            },
            {
                "swahili": "Asiyesikia la mkuu huvunjika guu.",
                "english": "He who does not listen to elders breaks a leg.",
                "meaning": "Respect and learn from those with experience."
            },
            {
                "swahili": "Mwenye pupa hadiriki kula tamu.",
                "english": "The impatient one misses out on sweetness.",
                "meaning": "Patience is rewarded with better outcomes."
            },
            {
                "swahili": "Ukiona vyaelea, vimeundwa.",
                "english": "If you see things floating, they were made to float.",
                "meaning": "Everything happens for a reason; nothing is accidental."
            }
        ]
        
        self.greetings = {
            "morning": {
                "swahili": "Habari za asubuhi",
                "english": "Good morning",
                "response": "Nzuri, asante"
            },
            "afternoon": {
                "swahili": "Habari za mchana",
                "english": "Good afternoon",
                "response": "Nzuri, na wewe"
            },
            "evening": {
                "swahili": "Habari za jioni",
                "english": "Good evening",
                "response": "Salama, asante"
            },
            "night": {
                "swahili": "Usiku mwema",
                "english": "Good night",
                "response": "Na wewe pia"
            }
        }
        
        self.cultural_facts = [
            "Swahili is a Bantu language with significant Arabic influence",
            "Kiswahili is spoken by over 200 million people across East Africa",
            "The word 'Safari' comes from Swahili, meaning 'journey'",
            "Hakuna Matata means 'no worries' in Swahili",
            "Swahili culture is a blend of African, Arab, and Indian influences",
            "The Swahili coast has been a trading hub for centuries",
            "Swahili is an official language in Kenya, Tanzania, and Uganda",
            "Traditional Swahili architecture features coral stone and intricate wood carvings",
            "Swahili poetry (Utenzi) has a rich literary tradition",
            "The Swahili calendar is based on the Islamic lunar calendar"
        ]
        
        self.lion_king_lore = [
            "Simba means 'lion' in Swahili",
            "Rafiki means 'friend' in Swahili",
            "Hakuna Matata is a Swahili phrase popularized by The Lion King",
            "Pumbaa means 'simpleton' or 'foolish' in Swahili",
            "Shenzi means 'uncouth' or 'barbaric' in Swahili",
            "The Lion King draws inspiration from African landscapes and wildlife",
            "Many character names in The Lion King are Swahili words",
            "The Circle of Life concept reflects African philosophical views",
            "The story incorporates elements from African folklore and Shakespeare's Hamlet"
        ]
        
        self.video_themes = {
            "safari": {
                "description": "African wildlife and landscapes",
                "keywords": ["elephant", "lion", "giraffe", "savanna", "sunset", "acacia"],
                "swahili_terms": ["safari", "wanyama", "nyika", "machozi ya jua"]
            },
            "dance": {
                "description": "Traditional African dance and celebration",
                "keywords": ["maasai", "warriors", "jumping", "drums", "ceremony"],
                "swahili_terms": ["ngoma", "kichwa", "mchezo", "sherehe"]
            },
            "market": {
                "description": "Vibrant African market scenes",
                "keywords": ["market", "vendors", "colorful", "spices", "fabrics"],
                "swahili_terms": ["soko", "biashara", "rangi", "bidhaa"]
            },
            "coastal": {
                "description": "Swahili coast and ocean life",
                "keywords": ["beach", "dhow", "fishing", "coral", "indian ocean"],
                "swahili_terms": ["pwani", "jahazi", "samaki", "bahari"]
            }
        }
    
    def get_random_proverb(self) -> str:
        """Get a random Swahili proverb with translation"""
        proverb = random.choice(self.proverbs)
        return f"{proverb['swahili']} - '{proverb['english']}' ({proverb['meaning']})"
    
    def get_cultural_fact(self) -> str:
        """Get a random cultural fact"""
        return random.choice(self.cultural_facts)
    
    def get_lion_king_fact(self) -> str:
        """Get a random Lion King fact"""
        return random.choice(self.lion_king_lore)
    
    def generate_kiswahili_response(self, base_response: str) -> str:
        """Enhance a response with Kiswahili elements"""
        
        # Add greeting if appropriate
        if any(word in base_response.lower() for word in ['hello', 'hi', 'greetings']):
            greeting = random.choice(list(self.greetings.values()))
            base_response = f"{greeting['swahili']}! {base_response}"
        
        # Add proverb with 30% chance
        if random.random() < 0.3:
            proverb = self.get_random_proverb()
            base_response += f"\n\n🌍 **Dhana ya Kiafrika**: {proverb}"
        
        # Add cultural fact with 20% chance
        if random.random() < 0.2:
            fact = self.get_cultural_fact()
            base_response += f"\n\n📚 **Ujuzi wa Kitamaduni**: {fact}"
        
        return base_response
    
    def get_video_theme_suggestions(self) -> List[Dict]:
        """Get suggestions for cultural video themes"""
        suggestions = []
        for theme, info in self.video_themes.items():
            suggestions.append({
                "theme": theme,
                "description": info["description"],
                "swahili_terms": info["swahili_terms"],
                "prompt_suggestion": f"{info['description']} with {', '.join(info['keywords'][:3])}"
            })
        return suggestions
    
    def enhance_image_prompt(self, prompt: str) -> str:
        """Enhance image prompts with cultural context"""
        prompt_lower = prompt.lower()
        
        # Check for cultural keywords
        for theme, info in self.video_themes.items():
            for keyword in info["keywords"]:
                if keyword in prompt_lower:
                    # Add Swahili terms and cultural context
                    swahili_term = random.choice(info["swahili_terms"])
                    return f"{prompt}, {info['description']}, {swahili_term}, East African style"
        
        return prompt
    
    def get_learning_lesson(self, level: str = "beginner") -> Dict:
        """Get a Kiswahili learning lesson"""
        lessons = {
            "beginner": {
                "topic": "Basic Greetings",
                "phrases": [
                    {"swahili": "Jambo", "english": "Hello", "pronunciation": "Jahm-boh"},
                    {"swahili": "Habari", "english": "How are you?", "pronunciation": "Hah-bah-ree"},
                    {"swahili": "Nzuri", "english": "Good/Fine", "pronunciation": "N-zoo-ree"},
                    {"swahili": "Asante", "english": "Thank you", "pronunciation": "Ah-sahn-teh"},
                    {"swahili": "Karibu", "english": "Welcome", "pronunciation": "Kah-ree-boo"}
                ],
                "practice": "Try greeting someone with 'Jambo' and 'Habari yako?'"
            },
            "intermediate": {
                "topic": "Common Phrases",
                "phrases": [
                    {"swahili": "Tafadhali", "english": "Please", "pronunciation": "Tah-fah-dah-lee"},
                    {"swahili": "Samahani", "english": "Excuse me/Sorry", "pronunciation": "Sah-mah-hah-nee"},
                    {"swahili": "Ndio", "english": "Yes", "pronunciation": "N-dee-oh"},
                    {"swahili": "Hapana", "english": "No", "pronunciation": "Hah-pah-nah"},
                    {"swahili": "Sawa", "english": "Okay", "pronunciation": "Sah-wah"}
                ],
                "practice": "Practice using these phrases in simple conversations"
            },
            "advanced": {
                "topic": "Cultural Expressions",
                "phrases": [
                    {"swahili": "Hakuna Matata", "english": "No worries", "pronunciation": "Hah-koo-nah Mah-tah-tah"},
                    {"swahili": "Pole pole", "english": "Slowly slowly", "pronunciation": "Poh-leh poh-leh"},
                    {"swahili": "Haraka haraka haina baraka", "english": "Hurry hurry has no blessing", "pronunciation": "Hah-rah-kah hah-rah-kah hai-nah bah-rah-kah"}
                ],
                "practice": "Use these proverbs to sound like a native speaker"
            }
        }
        
        return lessons.get(level, lessons["beginner"])

def enhance_with_kiswahili(text: str, knowledge_base: KiswahiliKnowledgeBase = None) -> str:
    """Enhanced version with video support"""
    if knowledge_base is None:
        knowledge_base = KiswahiliKnowledgeBase()
    
    enhanced = knowledge_base.generate_kiswahili_response(text)
    
    # Add video suggestion if talking about visuals
    video_triggers = ['see', 'watch', 'view', 'visual', 'picture', 'image', 'video']
    if any(trigger in text.lower() for trigger in video_triggers):
        video_suggestion = "🎬 **Kipaji cha Video**: Ninaweza kutengeneza video ya kitamaduni kwa ajili yako!"
        enhanced += f"\n\n{video_suggestion}"
    
    return enhanced