File size: 7,548 Bytes
b65eda7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
220
221
222
223
224
225
226
"""
Multilingual Demo with Apertus Swiss AI
Demonstrates seamless language switching and cultural context
"""

import sys
import os

# Add src directory to path
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))

from multilingual_assistant import SwissMultilingualAssistant


def demo_language_switching():
    """Demonstrate automatic language switching"""
    print("🌍 Multilingual Language Switching Demo")
    print("=" * 50)
    
    assistant = SwissMultilingualAssistant()
    
    # Test prompts in different languages
    test_prompts = [
        ("Guten Tag! Wie funktioniert das Schweizer Bildungssystem?", "German"),
        ("Bonjour! Comment puis-je ouvrir un compte bancaire en Suisse?", "French"),
        ("Ciao! Puoi spiegarmi il sistema sanitario svizzero?", "Italian"),
        ("Hello! What are the benefits of living in Switzerland?", "English"),
        ("Allegra! Co poss far per emprender il rumantsch?", "Romansh")
    ]
    
    for prompt, language in test_prompts:
        print(f"\nπŸ—£οΈ Testing {language}:")
        print(f"User: {prompt}")
        print("πŸ€” Processing...")
        
        try:
            response = assistant.chat(prompt, maintain_context=False)
            print(f"πŸ‡¨πŸ‡­ Apertus: {response}")
            
        except Exception as e:
            print(f"❌ Error: {str(e)}")
        
        print("-" * 40)
    
    # Show language statistics
    stats = assistant.get_language_statistics()
    print(f"\nπŸ“Š Language Usage Statistics:")
    for lang, count in stats['languages_used'].items():
        percentage = stats['language_percentages'][lang]
        print(f"  {lang}: {count} messages ({percentage:.1f}%)")


def demo_context_switching():
    """Demonstrate context-aware language switching"""
    print("\nπŸ”„ Context-Aware Language Switching Demo")
    print("=" * 50)
    
    assistant = SwissMultilingualAssistant()
    
    # Conversation with language switching
    conversation_flow = [
        ("Kannst du mir bei meinen Steuern helfen?", "Starting in German"),
        ("Actually, can you explain it in English please?", "Switching to English"),
        ("Merci, mais peux-tu maintenant l'expliquer en franΓ§ais?", "Switching to French"),
        ("Perfetto! Ora continua in italiano per favore.", "Switching to Italian")
    ]
    
    print("Starting contextual conversation...")
    
    for message, description in conversation_flow:
        print(f"\nπŸ“ {description}")
        print(f"User: {message}")
        
        try:
            response = assistant.chat(message, maintain_context=True)
            print(f"πŸ‡¨πŸ‡­ Apertus: {response}")
            
        except Exception as e:
            print(f"❌ Error: {str(e)}")
    
    print("\nπŸ’Ύ Exporting conversation...")
    conversation_export = assistant.export_conversation("text")
    print(conversation_export[:500] + "..." if len(conversation_export) > 500 else conversation_export)


def demo_swiss_context():
    """Demonstrate Swiss cultural context understanding"""
    print("\nπŸ”οΈ Swiss Cultural Context Demo")
    print("=" * 50)
    
    assistant = SwissMultilingualAssistant()
    
    swiss_context_questions = [
        ("Wie funktioniert die direkte Demokratie in der Schweiz?", "legal"),
        ("Was sind typisch schweizerische Werte?", "cultural"),
        ("Wie grΓΌnde ich ein Unternehmen in der Schweiz?", "business"),
        ("Welche Krankenversicherung brauche ich?", "healthcare"),
        ("Comment fonctionne le système de formation dual?", "education")
    ]
    
    for question, context_type in swiss_context_questions:
        print(f"\n🎯 Context: {context_type}")
        print(f"Question: {question}")
        
        try:
            response = assistant.get_swiss_context_response(question, context_type)
            print(f"πŸ‡¨πŸ‡­ Swiss Context Response: {response}")
            
        except Exception as e:
            print(f"❌ Error: {str(e)}")
        
        print("-" * 30)


def demo_translation_capabilities():
    """Demonstrate translation between Swiss languages"""
    print("\nπŸ”„ Translation Demo")
    print("=" * 50)
    
    assistant = SwissMultilingualAssistant()
    
    original_text = "Die Schweiz ist ein mehrsprachiges Land mit vier Amtssprachen."
    
    translations = [
        ("de", "fr", "German to French"),
        ("de", "it", "German to Italian"),
        ("de", "en", "German to English"),
        ("de", "rm", "German to Romansh")
    ]
    
    print(f"Original text: {original_text}")
    
    for source, target, description in translations:
        print(f"\nπŸ”„ {description}:")
        
        try:
            translated = assistant.translate_text(original_text, source, target)
            print(f"Translation: {translated}")
            
        except Exception as e:
            print(f"❌ Error: {str(e)}")


def interactive_demo():
    """Interactive multilingual chat"""
    print("\nπŸ’¬ Interactive Multilingual Chat")
    print("=" * 50)
    print("Chat in any language! Type 'stats' for statistics, 'quit' to exit")
    
    assistant = SwissMultilingualAssistant()
    
    while True:
        user_input = input("\nπŸ™‹ You: ").strip()
        
        if not user_input:
            continue
            
        if user_input.lower() == 'quit':
            break
            
        if user_input.lower() == 'stats':
            stats = assistant.get_language_statistics()
            print("πŸ“Š Conversation Statistics:")
            print(f"Total exchanges: {stats['total_exchanges']}")
            for lang, count in stats['languages_used'].items():
                print(f"  {lang}: {count} messages")
            continue
        
        try:
            response = assistant.chat(user_input)
            print(f"πŸ‡¨πŸ‡­ Apertus: {response}")
            
        except Exception as e:
            print(f"❌ Error: {str(e)}")
    
    # Final statistics
    stats = assistant.get_language_statistics()
    if stats['total_exchanges'] > 0:
        print(f"\nπŸ“Š Final Statistics:")
        print(f"Total exchanges: {stats['total_exchanges']}")
        print(f"Most used language: {stats['most_used_language']}")


def main():
    """Main demo function"""
    print("πŸ‡¨πŸ‡­ Apertus Swiss AI - Multilingual Demo")
    print("Loading Swiss Multilingual Assistant...")
    
    demos = [
        ("1", "Language Switching Demo", demo_language_switching),
        ("2", "Context Switching Demo", demo_context_switching),
        ("3", "Swiss Cultural Context Demo", demo_swiss_context),
        ("4", "Translation Demo", demo_translation_capabilities),
        ("5", "Interactive Chat", interactive_demo)
    ]
    
    print("\nAvailable demos:")
    for num, name, _ in demos:
        print(f"  {num}. {name}")
    
    print("  0. Run all demos")
    
    choice = input("\nChoose demo (0-5): ").strip()
    
    if choice == "0":
        for num, name, demo_func in demos[:-1]:  # Exclude interactive demo
            print(f"\n{'='*20} {name} {'='*20}")
            try:
                demo_func()
            except Exception as e:
                print(f"❌ Demo failed: {str(e)}")
    else:
        for num, name, demo_func in demos:
            if choice == num:
                try:
                    demo_func()
                except Exception as e:
                    print(f"❌ Demo failed: {str(e)}")
                break
        else:
            print("Invalid choice!")


if __name__ == "__main__":
    main()