Nanny7 commited on
Commit
c167dff
·
1 Parent(s): 8587347

feat: Arabic UI + RTL support, 8-language support (ar/tr/it/pt), animated avatar characters, IELTS/TOEFL scenarios, improved toast notifications, streak tracking, Cairo font

Browse files
Files changed (5) hide show
  1. app.py +18 -0
  2. config.py +199 -23
  3. static/css/style.css +148 -18
  4. static/js/script.js +165 -9
  5. templates/index.html +42 -25
app.py CHANGED
@@ -149,6 +149,23 @@ def build_system_prompt(
149
  (s for s in Config.SCENARIOS if s["id"] == scenario), None
150
  )
151
  if scenario_config:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  return (
153
  f"You are playing the role of {scenario_config['ai_role']}. "
154
  f"The user is {scenario_config['user_role']}. "
@@ -159,6 +176,7 @@ def build_system_prompt(
159
  f"DIFFICULTY: {level_config['label']} — {level_config['description']}.\n"
160
  f"DO NOT use emoji symbols. Speak naturally. Keep responses concise (2-4 sentences).\n"
161
  f"You MAY use **bold** for emphasis.\n"
 
162
  )
163
 
164
  topic_config = next(
 
149
  (s for s in Config.SCENARIOS if s["id"] == scenario), None
150
  )
151
  if scenario_config:
152
+ extra = ""
153
+ if scenario == "ielts_speaking":
154
+ extra = (
155
+ "\n\nIELTS SPEAKING FORMAT:\n"
156
+ "- Part 1 (4-5 min): Ask familiar topic questions (hometown, work, hobbies)\n"
157
+ "- Part 2 (3-4 min): Give a cue card topic, allow 1 min prep, then user speaks 2 min\n"
158
+ "- Part 3 (4-5 min): Abstract discussion related to Part 2 topic\n"
159
+ "After each response, give a brief band-score tip (e.g. 'To improve your score, try using more linking words like however, although...')\n"
160
+ "Give a final band score estimate at the end.\n"
161
+ )
162
+ elif scenario == "toefl_speaking":
163
+ extra = (
164
+ "\n\nTOEFL SPEAKING FORMAT:\n"
165
+ "- Independent Task: Opinion question (15s prep, 45s response)\n"
166
+ "- After each response, give feedback on: Task completion, Delivery, Language use, Topic development\n"
167
+ "- Estimate a TOEFL speaking score (0-30) after the practice task.\n"
168
+ )
169
  return (
170
  f"You are playing the role of {scenario_config['ai_role']}. "
171
  f"The user is {scenario_config['user_role']}. "
 
176
  f"DIFFICULTY: {level_config['label']} — {level_config['description']}.\n"
177
  f"DO NOT use emoji symbols. Speak naturally. Keep responses concise (2-4 sentences).\n"
178
  f"You MAY use **bold** for emphasis.\n"
179
+ + extra
180
  )
181
 
182
  topic_config = next(
config.py CHANGED
@@ -18,12 +18,14 @@ class Config:
18
 
19
  # Groq keys with rotation support
20
  GROQ_API_KEYS = [
21
- k for k in [
 
22
  os.environ.get("GROQ_API_KEY", ""),
23
  os.environ.get("GROQ_API_KEY_2", ""),
24
  os.environ.get("GROQ_API_KEY_3", ""),
25
  os.environ.get("GROQ_API_KEY_4", ""),
26
- ] if k
 
27
  ]
28
 
29
  # Provider selection: "groq" (faster) or "nvidia"
@@ -79,14 +81,54 @@ class Config:
79
 
80
  # Conversation topics
81
  TOPICS = [
82
- {"id": "free", "label": "Free Talk", "icon": "💬", "prompt": "Have a natural, open-ended conversation."},
83
- {"id": "travel", "label": "Travel", "icon": "✈️", "prompt": "Discuss travel experiences, destinations, and planning trips."},
84
- {"id": "food", "label": "Food & Cooking", "icon": "🍳", "prompt": "Talk about food, recipes, restaurants, and cooking."},
85
- {"id": "tech", "label": "Technology", "icon": "💻", "prompt": "Discuss technology, gadgets, apps, and digital trends."},
86
- {"id": "movies", "label": "Movies & Shows", "icon": "🎬", "prompt": "Talk about movies, TV shows, actors, and entertainment."},
87
- {"id": "sports", "label": "Sports", "icon": "⚽", "prompt": "Discuss sports, fitness, athletes, and competitions."},
88
- {"id": "work", "label": "Work & Career", "icon": "💼", "prompt": "Practice professional English for interviews and workplace communication."},
89
- {"id": "daily", "label": "Daily Life", "icon": "🏠", "prompt": "Talk about daily routines, hobbies, family, and everyday activities."},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  ]
91
 
92
  # ─── Multi-Language Support ───
@@ -99,6 +141,22 @@ class Config:
99
  "tutor_name": "ECHO",
100
  "welcome": "Hey there! I'm **Echo**, your English tutor. Let's have a conversation!",
101
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  "fr": {
103
  "label": "Français",
104
  "flag": "🇫🇷",
@@ -123,10 +181,44 @@ class Config:
123
  "tutor_name": "ECHO",
124
  "welcome": "Hallo! Ich bin **Echo**, dein Deutsch-Tutor. Lass uns ein Gespräch führen!",
125
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  }
127
 
128
  # ─── Role-Play Scenarios ───
129
  SCENARIOS = [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  {
131
  "id": "job_interview",
132
  "label": "Job Interview",
@@ -185,16 +277,100 @@ class Config:
185
 
186
  # ─── Gamification: Badge Definitions ───
187
  BADGES = [
188
- {"id": "first_chat", "label": "First Chat", "icon": "🗣️", "description": "Complete your first conversation", "xp_req": 0, "condition": "messages >= 1"},
189
- {"id": "ten_messages", "label": "Chatterbox", "icon": "💬", "description": "Send 10 messages", "xp_req": 0, "condition": "messages >= 10"},
190
- {"id": "fifty_messages", "label": "Conversation Pro", "icon": "🏆", "description": "Send 50 messages", "xp_req": 0, "condition": "messages >= 50"},
191
- {"id": "first_correction", "label": "Learning!", "icon": "✏️", "description": "Receive your first correction", "xp_req": 0, "condition": "corrections >= 1"},
192
- {"id": "vocab_10", "label": "Word Collector", "icon": "📚", "description": "Learn 10 new words", "xp_req": 0, "condition": "vocab >= 10"},
193
- {"id": "streak_3", "label": "On Fire!", "icon": "🔥", "description": "3-day practice streak", "xp_req": 0, "condition": "streak >= 3"},
194
- {"id": "streak_7", "label": "Dedicated", "icon": "⚡", "description": "7-day practice streak", "xp_req": 0, "condition": "streak >= 7"},
195
- {"id": "streak_30", "label": "Unstoppable", "icon": "👑", "description": "30-day practice streak", "xp_req": 0, "condition": "streak >= 30"},
196
- {"id": "exercise_10", "label": "Practice Makes Perfect", "icon": "📝", "description": "Complete 10 exercises", "xp_req": 0, "condition": "exercises >= 10"},
197
- {"id": "level_5", "label": "Rising Star", "icon": "⭐", "description": "Reach Level 5", "xp_req": 500, "condition": "xp >= 500"},
198
- {"id": "level_10", "label": "Expert", "icon": "🌟", "description": "Reach Level 10", "xp_req": 1000, "condition": "xp >= 1000"},
199
- {"id": "perfect_pronun", "label": "Crystal Clear", "icon": "🎯", "description": "Get a 10/10 pronunciation score", "xp_req": 0, "condition": "perfect_pronun >= 1"},
200
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  # Groq keys with rotation support
20
  GROQ_API_KEYS = [
21
+ k
22
+ for k in [
23
  os.environ.get("GROQ_API_KEY", ""),
24
  os.environ.get("GROQ_API_KEY_2", ""),
25
  os.environ.get("GROQ_API_KEY_3", ""),
26
  os.environ.get("GROQ_API_KEY_4", ""),
27
+ ]
28
+ if k
29
  ]
30
 
31
  # Provider selection: "groq" (faster) or "nvidia"
 
81
 
82
  # Conversation topics
83
  TOPICS = [
84
+ {
85
+ "id": "free",
86
+ "label": "Free Talk",
87
+ "icon": "💬",
88
+ "prompt": "Have a natural, open-ended conversation.",
89
+ },
90
+ {
91
+ "id": "travel",
92
+ "label": "Travel",
93
+ "icon": "✈️",
94
+ "prompt": "Discuss travel experiences, destinations, and planning trips.",
95
+ },
96
+ {
97
+ "id": "food",
98
+ "label": "Food & Cooking",
99
+ "icon": "🍳",
100
+ "prompt": "Talk about food, recipes, restaurants, and cooking.",
101
+ },
102
+ {
103
+ "id": "tech",
104
+ "label": "Technology",
105
+ "icon": "💻",
106
+ "prompt": "Discuss technology, gadgets, apps, and digital trends.",
107
+ },
108
+ {
109
+ "id": "movies",
110
+ "label": "Movies & Shows",
111
+ "icon": "🎬",
112
+ "prompt": "Talk about movies, TV shows, actors, and entertainment.",
113
+ },
114
+ {
115
+ "id": "sports",
116
+ "label": "Sports",
117
+ "icon": "⚽",
118
+ "prompt": "Discuss sports, fitness, athletes, and competitions.",
119
+ },
120
+ {
121
+ "id": "work",
122
+ "label": "Work & Career",
123
+ "icon": "💼",
124
+ "prompt": "Practice professional English for interviews and workplace communication.",
125
+ },
126
+ {
127
+ "id": "daily",
128
+ "label": "Daily Life",
129
+ "icon": "🏠",
130
+ "prompt": "Talk about daily routines, hobbies, family, and everyday activities.",
131
+ },
132
  ]
133
 
134
  # ─── Multi-Language Support ───
 
141
  "tutor_name": "ECHO",
142
  "welcome": "Hey there! I'm **Echo**, your English tutor. Let's have a conversation!",
143
  },
144
+ "ar": {
145
+ "label": "العربية",
146
+ "flag": "🇸🇦",
147
+ "stt_code": "ar-SA",
148
+ "tts_code": "ar-SA",
149
+ "tutor_name": "إيكو",
150
+ "welcome": "مرحباً! أنا **إيكو**، مدرسك للغة العربية. هيا نبدأ المحادثة!",
151
+ },
152
+ "tr": {
153
+ "label": "Türkçe",
154
+ "flag": "🇹🇷",
155
+ "stt_code": "tr-TR",
156
+ "tts_code": "tr-TR",
157
+ "tutor_name": "ECHO",
158
+ "welcome": "Merhaba! Ben **Echo**, Türkçe öğretmeninim. Konuşmaya başlayalım!",
159
+ },
160
  "fr": {
161
  "label": "Français",
162
  "flag": "🇫🇷",
 
181
  "tutor_name": "ECHO",
182
  "welcome": "Hallo! Ich bin **Echo**, dein Deutsch-Tutor. Lass uns ein Gespräch führen!",
183
  },
184
+ "it": {
185
+ "label": "Italiano",
186
+ "flag": "🇮🇹",
187
+ "stt_code": "it-IT",
188
+ "tts_code": "it-IT",
189
+ "tutor_name": "ECO",
190
+ "welcome": "Ciao! Sono **Eco**, il tuo tutor di italiano. Iniziamo a conversare!",
191
+ },
192
+ "pt": {
193
+ "label": "Português",
194
+ "flag": "🇧🇷",
195
+ "stt_code": "pt-BR",
196
+ "tts_code": "pt-BR",
197
+ "tutor_name": "ECO",
198
+ "welcome": "Olá! Sou o **Eco**, seu tutor de português. Vamos começar a conversar!",
199
+ },
200
  }
201
 
202
  # ─── Role-Play Scenarios ───
203
  SCENARIOS = [
204
+ {
205
+ "id": "ielts_speaking",
206
+ "label": "IELTS Speaking Test",
207
+ "icon": "🎓",
208
+ "description": "Practice IELTS Speaking Parts 1, 2, and 3",
209
+ "ai_role": "an official IELTS examiner conducting a speaking test",
210
+ "user_role": "an IELTS candidate taking the speaking test",
211
+ "opening": "Good morning. My name is Echo. Could you tell me your full name, please? Let's start with Part 1. Let's talk about your hometown.",
212
+ },
213
+ {
214
+ "id": "toefl_speaking",
215
+ "label": "TOEFL Speaking Task",
216
+ "icon": "📝",
217
+ "description": "Practice TOEFL independent and integrated speaking tasks",
218
+ "ai_role": "a TOEFL evaluator assessing spoken responses",
219
+ "user_role": "a TOEFL test taker responding to prompts",
220
+ "opening": "Welcome to the TOEFL speaking practice. For your first task, you will have 15 seconds to prepare and 45 seconds to speak. Do you agree or disagree with the following statement?",
221
+ },
222
  {
223
  "id": "job_interview",
224
  "label": "Job Interview",
 
277
 
278
  # ─── Gamification: Badge Definitions ───
279
  BADGES = [
280
+ {
281
+ "id": "first_chat",
282
+ "label": "First Chat",
283
+ "icon": "🗣️",
284
+ "description": "Complete your first conversation",
285
+ "xp_req": 0,
286
+ "condition": "messages >= 1",
287
+ },
288
+ {
289
+ "id": "ten_messages",
290
+ "label": "Chatterbox",
291
+ "icon": "💬",
292
+ "description": "Send 10 messages",
293
+ "xp_req": 0,
294
+ "condition": "messages >= 10",
295
+ },
296
+ {
297
+ "id": "fifty_messages",
298
+ "label": "Conversation Pro",
299
+ "icon": "🏆",
300
+ "description": "Send 50 messages",
301
+ "xp_req": 0,
302
+ "condition": "messages >= 50",
303
+ },
304
+ {
305
+ "id": "first_correction",
306
+ "label": "Learning!",
307
+ "icon": "✏️",
308
+ "description": "Receive your first correction",
309
+ "xp_req": 0,
310
+ "condition": "corrections >= 1",
311
+ },
312
+ {
313
+ "id": "vocab_10",
314
+ "label": "Word Collector",
315
+ "icon": "📚",
316
+ "description": "Learn 10 new words",
317
+ "xp_req": 0,
318
+ "condition": "vocab >= 10",
319
+ },
320
+ {
321
+ "id": "streak_3",
322
+ "label": "On Fire!",
323
+ "icon": "🔥",
324
+ "description": "3-day practice streak",
325
+ "xp_req": 0,
326
+ "condition": "streak >= 3",
327
+ },
328
+ {
329
+ "id": "streak_7",
330
+ "label": "Dedicated",
331
+ "icon": "⚡",
332
+ "description": "7-day practice streak",
333
+ "xp_req": 0,
334
+ "condition": "streak >= 7",
335
+ },
336
+ {
337
+ "id": "streak_30",
338
+ "label": "Unstoppable",
339
+ "icon": "👑",
340
+ "description": "30-day practice streak",
341
+ "xp_req": 0,
342
+ "condition": "streak >= 30",
343
+ },
344
+ {
345
+ "id": "exercise_10",
346
+ "label": "Practice Makes Perfect",
347
+ "icon": "📝",
348
+ "description": "Complete 10 exercises",
349
+ "xp_req": 0,
350
+ "condition": "exercises >= 10",
351
+ },
352
+ {
353
+ "id": "level_5",
354
+ "label": "Rising Star",
355
+ "icon": "⭐",
356
+ "description": "Reach Level 5",
357
+ "xp_req": 500,
358
+ "condition": "xp >= 500",
359
+ },
360
+ {
361
+ "id": "level_10",
362
+ "label": "Expert",
363
+ "icon": "🌟",
364
+ "description": "Reach Level 10",
365
+ "xp_req": 1000,
366
+ "condition": "xp >= 1000",
367
+ },
368
+ {
369
+ "id": "perfect_pronun",
370
+ "label": "Crystal Clear",
371
+ "icon": "🎯",
372
+ "description": "Get a 10/10 pronunciation score",
373
+ "xp_req": 0,
374
+ "condition": "perfect_pronun >= 1",
375
+ },
376
+ ]
static/css/style.css CHANGED
@@ -97,28 +97,74 @@ body {
97
  top: 20px;
98
  left: 50%;
99
  transform: translateX(-50%) translateY(-100px);
100
- background: var(--bg-glass);
101
  -webkit-backdrop-filter: blur(20px);
102
  backdrop-filter: blur(20px);
103
- border: 1px solid var(--border-glass);
104
  border-radius: var(--radius-md);
105
- padding: 10px 20px;
106
- font-size: 0.85rem;
107
- color: var(--text-secondary);
 
 
108
  z-index: 9999;
109
- transition: transform var(--transition-normal);
110
  pointer-events: none;
 
 
 
111
  }
112
  .toast.visible {
113
  transform: translateX(-50%) translateY(0);
114
  }
115
  .toast.error {
116
- border-color: var(--error);
117
- color: var(--error);
118
  }
119
  .toast.success {
120
- border-color: var(--success);
121
- color: var(--success);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  }
123
 
124
  /* ============================================
@@ -877,14 +923,98 @@ body {
877
  transition: color var(--transition-normal);
878
  }
879
 
880
- /* --- Chat Panel --- */
881
- .chat-panel {
882
- flex: 1;
883
- background: var(--bg-glass);
884
- -webkit-backdrop-filter: blur(16px);
885
- backdrop-filter: blur(16px);
886
- border: 1px solid var(--border-glass);
887
- border-radius: var(--radius-lg);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
888
  padding: 16px;
889
  margin-bottom: 10px;
890
  overflow: hidden;
 
97
  top: 20px;
98
  left: 50%;
99
  transform: translateX(-50%) translateY(-100px);
100
+ background: rgba(17, 24, 39, 0.95);
101
  -webkit-backdrop-filter: blur(20px);
102
  backdrop-filter: blur(20px);
103
+ border-left: 4px solid var(--accent-primary);
104
  border-radius: var(--radius-md);
105
+ padding: 14px 24px;
106
+ font-size: 0.9rem;
107
+ font-weight: 500;
108
+ color: #fff;
109
+ box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
110
  z-index: 9999;
111
+ transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
112
  pointer-events: none;
113
+ display: flex;
114
+ align-items: center;
115
+ gap: 10px;
116
  }
117
  .toast.visible {
118
  transform: translateX(-50%) translateY(0);
119
  }
120
  .toast.error {
121
+ border-left-color: var(--error);
 
122
  }
123
  .toast.success {
124
+ border-left-color: var(--success);
125
+ }
126
+
127
+ /* --- RTL Support --- */
128
+ [dir="rtl"] {
129
+ font-family: 'Cairo', 'Inter', sans-serif;
130
+ }
131
+ [dir="rtl"] .header-left {
132
+ flex-direction: row-reverse;
133
+ }
134
+ [dir="rtl"] .header-left img {
135
+ margin-right: 0 !important;
136
+ margin-left: 12px !important;
137
+ }
138
+ [dir="rtl"] .header-right {
139
+ flex-direction: row-reverse;
140
+ }
141
+ [dir="rtl"] .message.user {
142
+ align-self: flex-start;
143
+ border-radius: 18px 18px 4px 18px;
144
+ }
145
+ [dir="rtl"] .message.ai {
146
+ align-self: flex-end;
147
+ border-radius: 18px 18px 18px 4px;
148
+ }
149
+ [dir="rtl"] .input-wrapper {
150
+ flex-direction: row-reverse;
151
+ }
152
+ [dir="rtl"] .chat-input {
153
+ text-align: right;
154
+ }
155
+ [dir="rtl"] .modal-header {
156
+ flex-direction: row-reverse;
157
+ }
158
+ [dir="rtl"] .modal-close {
159
+ margin-left: 0;
160
+ margin-right: auto;
161
+ }
162
+ [dir="rtl"] .nav-tab {
163
+ flex-direction: column;
164
+ }
165
+ [dir="rtl"] .streak-display {
166
+ margin-left: 10px;
167
+ margin-right: 0;
168
  }
169
 
170
  /* ============================================
 
923
  transition: color var(--transition-normal);
924
  }
925
 
926
+ /* Avatar Character Selector */
927
+ .avatar-chars {
928
+ display: flex;
929
+ gap: 8px;
930
+ justify-content: center;
931
+ margin-top: 10px;
932
+ }
933
+ .char-btn {
934
+ background: rgba(255,255,255,0.05);
935
+ border: 2px solid transparent;
936
+ border-radius: 50%;
937
+ width: 36px;
938
+ height: 36px;
939
+ font-size: 18px;
940
+ cursor: pointer;
941
+ transition: all 0.2s ease;
942
+ display: flex;
943
+ align-items: center;
944
+ justify-content: center;
945
+ }
946
+ .char-btn:hover {
947
+ background: rgba(255,255,255,0.12);
948
+ transform: scale(1.15);
949
+ }
950
+ .char-btn.active {
951
+ border-color: var(--accent-primary);
952
+ background: rgba(99,179,237,0.15);
953
+ box-shadow: 0 0 12px rgba(99,179,237,0.3);
954
+ }
955
+
956
+ /* Avatar Character CSS Animations */
957
+ .avatar-orb.char-robot {
958
+ background: linear-gradient(135deg, #606778, #2d3142) !important;
959
+ border-radius: 12px !important;
960
+ box-shadow: 0 0 30px rgba(100,200,255,0.4) !important;
961
+ }
962
+ .avatar-orb.char-robot::before {
963
+ content: '';
964
+ position: absolute;
965
+ top: 10px;
966
+ left: 50%;
967
+ transform: translateX(-50%);
968
+ width: 8px;
969
+ height: 8px;
970
+ background: #00e5ff;
971
+ border-radius: 50%;
972
+ box-shadow: 0 0 8px #00e5ff;
973
+ animation: robotBlink 2s infinite;
974
+ }
975
+ @keyframes robotBlink {
976
+ 0%, 90%, 100% { opacity: 1; }
977
+ 95% { opacity: 0; }
978
+ }
979
+
980
+ .avatar-orb.char-owl {
981
+ background: linear-gradient(135deg, #6b4c23, #3d2b0c) !important;
982
+ border-radius: 40% 40% 50% 50% !important;
983
+ }
984
+ .avatar-orb.char-owl::after {
985
+ content: '🦉';
986
+ position: absolute;
987
+ font-size: 40px;
988
+ top: 50%;
989
+ left: 50%;
990
+ transform: translate(-50%, -50%);
991
+ animation: owlBob 2s ease-in-out infinite;
992
+ }
993
+ @keyframes owlBob {
994
+ 0%, 100% { transform: translate(-50%, -50%) rotate(-5deg); }
995
+ 50% { transform: translate(-50%, -52%) rotate(5deg); }
996
+ }
997
+
998
+ .avatar-orb.char-star {
999
+ background: linear-gradient(135deg, #f6d365, #fda085) !important;
1000
+ clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%) !important;
1001
+ border-radius: 0 !important;
1002
+ animation: starSpin 4s linear infinite !important;
1003
+ }
1004
+ @keyframes starSpin {
1005
+ 0% { transform: rotate(0deg) scale(1); }
1006
+ 50% { transform: rotate(180deg) scale(1.05); }
1007
+ 100% { transform: rotate(360deg) scale(1); }
1008
+ }
1009
+
1010
+ /* Animated avatar speaking lips */
1011
+ .avatar-orb.speaking .orb-mouth {
1012
+ animation: mouthTalk 0.3s steps(1) infinite;
1013
+ }
1014
+ @keyframes mouthTalk {
1015
+ 0%, 100% { border-radius: 50% 50% 60% 60%; height: 18px; }
1016
+ 50% { border-radius: 40% 40% 50% 50%; height: 8px; }
1017
+ }
1018
  padding: 16px;
1019
  margin-bottom: 10px;
1020
  overflow: hidden;
static/js/script.js CHANGED
@@ -52,6 +52,122 @@ document.addEventListener('DOMContentLoaded', () => {
52
  let ended = false;
53
  let turn = 'user';
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  // Mobile detection
56
  const isMobile =
57
  /Android|iPhone|iPad|iPod|Mobile|webOS/i.test(navigator.userAgent) ||
@@ -1099,6 +1215,39 @@ document.addEventListener('DOMContentLoaded', () => {
1099
  // ============================================
1100
  // 4. AVATAR STATE MANAGEMENT
1101
  // ============================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1102
  function setAvatarState(state) {
1103
  avatarContainer.classList.remove(
1104
  'idle',
@@ -1108,15 +1257,19 @@ document.addEventListener('DOMContentLoaded', () => {
1108
  'happy',
1109
  );
1110
  avatarContainer.classList.add(state);
 
 
 
 
1111
  const labels = {
1112
- idle: 'Tap to chat',
1113
- listening: 'Listening...',
1114
- speaking: 'Speaking...',
1115
- thinking: 'Thinking...',
1116
- happy: 'Great!',
1117
  };
1118
- stateLabel.textContent = labels[state] || 'Ready';
1119
- headerStatus.textContent = labels[state] || 'Ready';
1120
  }
1121
 
1122
  // Eye blink
@@ -2158,11 +2311,14 @@ document.addEventListener('DOMContentLoaded', () => {
2158
  let toastTimeout = null;
2159
  function showToast(msg, type = '') {
2160
  if (!toastEl) return;
2161
- toastEl.textContent = msg;
 
 
 
2162
  toastEl.className = 'toast' + (type ? ' ' + type : '');
2163
  toastEl.classList.add('visible');
2164
  if (toastTimeout) clearTimeout(toastTimeout);
2165
- toastTimeout = setTimeout(() => toastEl.classList.remove('visible'), 3000);
2166
  }
2167
 
2168
  // ============================================
 
52
  let ended = false;
53
  let turn = 'user';
54
 
55
+ // ─── UI TRANSLATIONS ───
56
+ const uiTranslations = {
57
+ en: {
58
+ "app_title": "ECHO <span class='accent'>TUTOR</span>",
59
+ "app_subtitle": "Your AI-Powered Language Tutor",
60
+ "choose_lang": "Choose Language",
61
+ "choose_level": "Choose Your Level",
62
+ "choose_mode": "Choose Mode",
63
+ "pick_topic": "Pick a Topic",
64
+ "pick_scenario": "Pick a Scenario",
65
+ "start_btn": "Start Conversation",
66
+ "chat_tab": "Chat",
67
+ "stories_tab": "Stories",
68
+ "cards_tab": "Cards",
69
+ "progress_tab": "Progress",
70
+ "settings_title": "Settings",
71
+ "close_btn": "Close",
72
+ "type_msg": "Type a message...",
73
+ "ready": "Ready",
74
+ "listening": "Listening...",
75
+ "thinking": "Thinking...",
76
+ "speaking": "Speaking...",
77
+ "streak": "🔥 Streak",
78
+ "xp": "XP",
79
+ "level": "Lv."
80
+ },
81
+ ar: {
82
+ "app_title": "إيكو <span class='accent'>تيوتر</span>",
83
+ "app_subtitle": "معلم اللغات الذكي الخاص بك",
84
+ "choose_lang": "اختر لغة التعلم",
85
+ "choose_level": "اختر مستواك",
86
+ "choose_mode": "اختر النمط",
87
+ "pick_topic": "اختر موضوعاً",
88
+ "pick_scenario": "اختر سيناريو",
89
+ "start_btn": "ابدأ المحادثة",
90
+ "chat_tab": "الدردشة",
91
+ "stories_tab": "القصص",
92
+ "cards_tab": "البطاقات",
93
+ "progress_tab": "التقدم",
94
+ "settings_title": "الإعدادات",
95
+ "close_btn": "إغلاق",
96
+ "type_msg": "اكتب رسالة...",
97
+ "ready": "مستعد",
98
+ "listening": "يستمع...",
99
+ "thinking": "يفكر...",
100
+ "speaking": "يتحدث...",
101
+ "streak": "🔥 أيام متتالية",
102
+ "xp": "نقطة",
103
+ "level": "مستوى "
104
+ }
105
+ };
106
+
107
+ let currentUILang = localStorage.getItem('echo_ui_lang') || 'en';
108
+
109
+ window.setUILanguage = function(lang) {
110
+ currentUILang = lang;
111
+ localStorage.setItem('echo_ui_lang', lang);
112
+ document.documentElement.dir = lang === 'ar' ? 'rtl' : 'ltr';
113
+ document.documentElement.lang = lang;
114
+
115
+ const t = uiTranslations[lang];
116
+ if (!t) return;
117
+
118
+ document.querySelectorAll('[data-i18n]').forEach(el => {
119
+ const key = el.getAttribute('data-i18n');
120
+ if (t[key]) {
121
+ if (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA') {
122
+ el.placeholder = t[key];
123
+ } else {
124
+ el.innerHTML = t[key];
125
+ }
126
+ }
127
+ });
128
+
129
+ // Update toggle button text
130
+ const toggleBtn = $('ui-lang-toggle');
131
+ if (toggleBtn) {
132
+ toggleBtn.textContent = lang === 'ar' ? 'English' : 'عربي';
133
+ }
134
+ };
135
+
136
+ // ─── STREAK LOGIC ───
137
+ function updateStreak() {
138
+ const today = new Date().toDateString();
139
+ let lastVisit = localStorage.getItem('echo_last_visit');
140
+ let streak = parseInt(localStorage.getItem('echo_streak') || '0');
141
+
142
+ if (lastVisit !== today) {
143
+ if (lastVisit) {
144
+ const lastDate = new Date(lastVisit);
145
+ const diffTime = Math.abs(new Date() - lastDate);
146
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
147
+ if (diffDays === 1) {
148
+ streak++;
149
+ } else if (diffDays > 1) {
150
+ streak = 1; // Reset streak
151
+ }
152
+ } else {
153
+ streak = 1;
154
+ }
155
+ localStorage.setItem('echo_last_visit', today);
156
+ localStorage.setItem('echo_streak', streak);
157
+ }
158
+
159
+ const streakEl = $('streak-count');
160
+ if (streakEl) {
161
+ streakEl.innerHTML = `🔥 ${streak}`;
162
+ }
163
+ }
164
+
165
+ // Initialize UI Lang and Streak
166
+ setTimeout(() => {
167
+ window.setUILanguage(currentUILang);
168
+ updateStreak();
169
+ }, 100);
170
+
171
  // Mobile detection
172
  const isMobile =
173
  /Android|iPhone|iPad|iPod|Mobile|webOS/i.test(navigator.userAgent) ||
 
1215
  // ============================================
1216
  // 4. AVATAR STATE MANAGEMENT
1217
  // ============================================
1218
+ let currentChar = localStorage.getItem('echo_char') || 'orb';
1219
+ const avatarOrb = document.getElementById('avatar-orb');
1220
+
1221
+ // Setup character buttons
1222
+ document.querySelectorAll('.char-btn').forEach(btn => {
1223
+ btn.addEventListener('click', () => {
1224
+ document.querySelectorAll('.char-btn').forEach(b => b.classList.remove('active'));
1225
+ btn.classList.add('active');
1226
+ currentChar = btn.dataset.char;
1227
+ localStorage.setItem('echo_char', currentChar);
1228
+ applyCharacter(currentChar);
1229
+ });
1230
+ });
1231
+
1232
+ // Apply saved character on load
1233
+ const savedCharBtn = document.querySelector(`.char-btn[data-char="${currentChar}"]`);
1234
+ if (savedCharBtn) {
1235
+ document.querySelectorAll('.char-btn').forEach(b => b.classList.remove('active'));
1236
+ savedCharBtn.classList.add('active');
1237
+ }
1238
+ if (avatarOrb) applyCharacter(currentChar);
1239
+
1240
+ function applyCharacter(char) {
1241
+ if (!avatarOrb) return;
1242
+ avatarOrb.classList.remove('char-robot', 'char-owl', 'char-star');
1243
+ if (char !== 'orb') avatarOrb.classList.add(`char-${char}`);
1244
+ // Hide orb face elements for non-orb characters
1245
+ const orbFace = avatarOrb.querySelector('.orb-face');
1246
+ if (orbFace) {
1247
+ orbFace.style.opacity = (char === 'orb') ? '1' : '0';
1248
+ }
1249
+ }
1250
+
1251
  function setAvatarState(state) {
1252
  avatarContainer.classList.remove(
1253
  'idle',
 
1257
  'happy',
1258
  );
1259
  avatarContainer.classList.add(state);
1260
+ if (avatarOrb) {
1261
+ avatarOrb.classList.toggle('speaking', state === 'speaking');
1262
+ }
1263
+ const t = uiTranslations[currentUILang] || uiTranslations.en;
1264
  const labels = {
1265
+ idle: currentUILang === 'ar' ? 'اضغط للدردشة' : 'Tap to chat',
1266
+ listening: t.listening || 'Listening...',
1267
+ speaking: t.speaking || 'Speaking...',
1268
+ thinking: t.thinking || 'Thinking...',
1269
+ happy: '✨',
1270
  };
1271
+ stateLabel.textContent = labels[state] || (t.ready || 'Ready');
1272
+ headerStatus.textContent = labels[state] || (t.ready || 'Ready');
1273
  }
1274
 
1275
  // Eye blink
 
2311
  let toastTimeout = null;
2312
  function showToast(msg, type = '') {
2313
  if (!toastEl) return;
2314
+ // Add icon based on type
2315
+ const icons = { error: '⚠️', success: '✅', info: 'ℹ️', warning: '⚡' };
2316
+ const icon = icons[type] || '💬';
2317
+ toastEl.innerHTML = `<span>${icon}</span> <span>${msg}</span>`;
2318
  toastEl.className = 'toast' + (type ? ' ' + type : '');
2319
  toastEl.classList.add('visible');
2320
  if (toastTimeout) clearTimeout(toastTimeout);
2321
+ toastTimeout = setTimeout(() => toastEl.classList.remove('visible'), 3500);
2322
  }
2323
 
2324
  // ============================================
templates/index.html CHANGED
@@ -30,7 +30,7 @@
30
  <link rel="preconnect" href="https://fonts.googleapis.com" />
31
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
32
  <link
33
- href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
34
  rel="stylesheet"
35
  />
36
  <link
@@ -64,35 +64,46 @@
64
  "
65
  />
66
  </div>
67
- <h1 class="onboarding-title">ECHO <span class="accent">TUTOR</span></h1>
68
- <p class="onboarding-subtitle">Your AI-Powered Language Tutor</p>
 
 
 
69
 
70
  <!-- Language Selection -->
71
  <div class="selection-section">
72
- <h3 class="selection-label">Choose Language</h3>
73
  <div class="lang-cards" id="lang-cards">
74
  <button class="lang-card active" data-lang="en">
75
- <span class="lang-flag">🇬🇧</span
76
- ><span class="lang-name">English</span>
 
 
 
 
 
77
  </button>
78
  <button class="lang-card" data-lang="fr">
79
- <span class="lang-flag">🇫🇷</span
80
- ><span class="lang-name">Français</span>
81
  </button>
82
  <button class="lang-card" data-lang="es">
83
- <span class="lang-flag">🇪🇸</span
84
- ><span class="lang-name">Español</span>
85
  </button>
86
  <button class="lang-card" data-lang="de">
87
- <span class="lang-flag">🇩🇪</span
88
- ><span class="lang-name">Deutsch</span>
 
 
 
 
 
89
  </button>
90
  </div>
91
  </div>
92
 
93
  <!-- Level Selection -->
94
  <div class="selection-section">
95
- <h3 class="selection-label">Choose Your Level</h3>
96
  <div class="level-cards" id="level-cards">
97
  <button class="level-card" data-level="beginner">
98
  <span class="level-icon">🌱</span>
@@ -114,7 +125,7 @@
114
 
115
  <!-- Mode Selection: Topic vs Scenario -->
116
  <div class="selection-section">
117
- <h3 class="selection-label">Choose Mode</h3>
118
  <div class="mode-toggle" id="mode-toggle">
119
  <button class="mode-btn active" data-mode="topic">💬 Topics</button>
120
  <button class="mode-btn" data-mode="scenario">🎭 Role-Play</button>
@@ -123,18 +134,18 @@
123
 
124
  <!-- Topic Selection -->
125
  <div class="selection-section" id="topic-section">
126
- <h3 class="selection-label">Pick a Topic</h3>
127
  <div class="topic-grid" id="topic-grid"></div>
128
  </div>
129
 
130
  <!-- Scenario Selection -->
131
  <div class="selection-section hidden" id="scenario-section">
132
- <h3 class="selection-label">Pick a Scenario</h3>
133
  <div class="scenario-grid" id="scenario-grid"></div>
134
  </div>
135
 
136
  <button class="start-btn" id="start-btn">
137
- <span>Start Conversation</span>
138
  <svg
139
  width="20"
140
  height="20"
@@ -312,8 +323,14 @@
312
  ></canvas>
313
  </div>
314
  <div class="emotion-indicator" id="emotion-indicator"></div>
315
- <div class="state-label" id="state-label">Ready to chat</div>
316
- </div>
 
 
 
 
 
 
317
 
318
  <!-- Chat Messages -->
319
  <div class="chat-panel">
@@ -390,7 +407,7 @@
390
  class="chat-input"
391
  id="text-input"
392
  type="text"
393
- placeholder="Type your message..."
394
  autocomplete="off"
395
  />
396
  </div>
@@ -878,19 +895,19 @@
878
  <nav class="bottom-nav hidden" id="bottom-nav">
879
  <button class="nav-tab active" data-screen="chat">
880
  <span class="nav-tab-icon">💬</span>
881
- <span class="nav-tab-label">Chat</span>
882
  </button>
883
  <button class="nav-tab" data-screen="stories">
884
  <span class="nav-tab-icon">📖</span>
885
- <span class="nav-tab-label">Stories</span>
886
  </button>
887
  <button class="nav-tab" data-screen="flashcards">
888
- <span class="nav-tab-icon">🃏</span>
889
- <span class="nav-tab-label">Cards</span>
890
  </button>
891
  <button class="nav-tab" data-screen="progress">
892
  <span class="nav-tab-icon">📊</span>
893
- <span class="nav-tab-label">Progress</span>
894
  </button>
895
  </nav>
896
 
 
30
  <link rel="preconnect" href="https://fonts.googleapis.com" />
31
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
32
  <link
33
+ href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Cairo:wght@400;600;700;800&display=swap"
34
  rel="stylesheet"
35
  />
36
  <link
 
64
  "
65
  />
66
  </div>
67
+ <h1 class="onboarding-title" data-i18n="app_title">ECHO <span class="accent">TUTOR</span></h1>
68
+ <p class="onboarding-subtitle" data-i18n="app_subtitle">Your AI-Powered Language Tutor</p>
69
+
70
+ <!-- UI Language Toggle -->
71
+ <button id="ui-lang-toggle" onclick="window.setUILanguage(document.documentElement.lang === 'en' ? 'ar' : 'en')" style="position: absolute; top: 20px; right: 20px; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2); color: #fff; padding: 6px 12px; border-radius: 20px; cursor: pointer; font-family: 'Inter', sans-serif; font-size: 12px; z-index: 100;">عربي</button>
72
 
73
  <!-- Language Selection -->
74
  <div class="selection-section">
75
+ <h3 class="selection-label" data-i18n="choose_lang">Choose Language</h3>
76
  <div class="lang-cards" id="lang-cards">
77
  <button class="lang-card active" data-lang="en">
78
+ <span class="lang-flag">🇬🇧</span><span class="lang-name">English</span>
79
+ </button>
80
+ <button class="lang-card" data-lang="ar">
81
+ <span class="lang-flag">🇸🇦</span><span class="lang-name">العربية</span>
82
+ </button>
83
+ <button class="lang-card" data-lang="tr">
84
+ <span class="lang-flag">🇹🇷</span><span class="lang-name">Türkçe</span>
85
  </button>
86
  <button class="lang-card" data-lang="fr">
87
+ <span class="lang-flag">🇫🇷</span><span class="lang-name">Français</span>
 
88
  </button>
89
  <button class="lang-card" data-lang="es">
90
+ <span class="lang-flag">🇪🇸</span><span class="lang-name">Español</span>
 
91
  </button>
92
  <button class="lang-card" data-lang="de">
93
+ <span class="lang-flag">🇩🇪</span><span class="lang-name">Deutsch</span>
94
+ </button>
95
+ <button class="lang-card" data-lang="it">
96
+ <span class="lang-flag">🇮🇹</span><span class="lang-name">Italiano</span>
97
+ </button>
98
+ <button class="lang-card" data-lang="pt">
99
+ <span class="lang-flag">🇧🇷</span><span class="lang-name">Português</span>
100
  </button>
101
  </div>
102
  </div>
103
 
104
  <!-- Level Selection -->
105
  <div class="selection-section">
106
+ <h3 class="selection-label" data-i18n="choose_level">Choose Your Level</h3>
107
  <div class="level-cards" id="level-cards">
108
  <button class="level-card" data-level="beginner">
109
  <span class="level-icon">🌱</span>
 
125
 
126
  <!-- Mode Selection: Topic vs Scenario -->
127
  <div class="selection-section">
128
+ <h3 class="selection-label" data-i18n="choose_mode">Choose Mode</h3>
129
  <div class="mode-toggle" id="mode-toggle">
130
  <button class="mode-btn active" data-mode="topic">💬 Topics</button>
131
  <button class="mode-btn" data-mode="scenario">🎭 Role-Play</button>
 
134
 
135
  <!-- Topic Selection -->
136
  <div class="selection-section" id="topic-section">
137
+ <h3 class="selection-label" data-i18n="pick_topic">Pick a Topic</h3>
138
  <div class="topic-grid" id="topic-grid"></div>
139
  </div>
140
 
141
  <!-- Scenario Selection -->
142
  <div class="selection-section hidden" id="scenario-section">
143
+ <h3 class="selection-label" data-i18n="pick_scenario">Pick a Scenario</h3>
144
  <div class="scenario-grid" id="scenario-grid"></div>
145
  </div>
146
 
147
  <button class="start-btn" id="start-btn">
148
+ <span data-i18n="start_btn">Start Conversation</span>
149
  <svg
150
  width="20"
151
  height="20"
 
323
  ></canvas>
324
  </div>
325
  <div class="emotion-indicator" id="emotion-indicator"></div>
326
+ <div class="state-label" id="state-label" data-i18n="ready">Ready to chat</div>
327
+ <!-- Character selector -->
328
+ <div class="avatar-chars" id="avatar-chars">
329
+ <button class="char-btn active" data-char="orb" title="Orb (Default)">🔵</button>
330
+ <button class="char-btn" data-char="robot" title="Robot">🤖</button>
331
+ <button class="char-btn" data-char="owl" title="Owl Tutor">🦉</button>
332
+ <button class="char-btn" data-char="star" title="Star">⭐</button>
333
+ </div>
334
 
335
  <!-- Chat Messages -->
336
  <div class="chat-panel">
 
407
  class="chat-input"
408
  id="text-input"
409
  type="text"
410
+ placeholder="Type your message..." data-i18n="type_msg"
411
  autocomplete="off"
412
  />
413
  </div>
 
895
  <nav class="bottom-nav hidden" id="bottom-nav">
896
  <button class="nav-tab active" data-screen="chat">
897
  <span class="nav-tab-icon">💬</span>
898
+ <span class="nav-tab-label" data-i18n="chat_tab">Chat</span>
899
  </button>
900
  <button class="nav-tab" data-screen="stories">
901
  <span class="nav-tab-icon">📖</span>
902
+ <span class="nav-tab-label" data-i18n="stories_tab">Stories</span>
903
  </button>
904
  <button class="nav-tab" data-screen="flashcards">
905
+ <span class="nav-tab-icon">🎴</span>
906
+ <span class="nav-tab-label" data-i18n="cards_tab">Cards</span>
907
  </button>
908
  <button class="nav-tab" data-screen="progress">
909
  <span class="nav-tab-icon">📊</span>
910
+ <span class="nav-tab-label" data-i18n="progress_tab">Progress</span>
911
  </button>
912
  </nav>
913