CCockrum commited on
Commit
816fffb
·
verified ·
1 Parent(s): 3dd36e8

Create static/index.html

Browse files
Files changed (1) hide show
  1. static/index.html +650 -0
static/index.html ADDED
@@ -0,0 +1,650 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>La Casseuse - French Language Tutor</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
9
+ <script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
10
+ <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
11
+ </head>
12
+ <body>
13
+ <div id="root"></div>
14
+
15
+ <script type="text/babel">
16
+ const { useState, useEffect, useRef } = React;
17
+
18
+ // Lucide Icons as inline SVG components
19
+ const Send = () => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><line x1="22" y1="2" x2="11" y2="13"></line><polygon points="22 2 15 22 11 13 2 9 22 2"></polygon></svg>;
20
+ const Loader2 = () => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" className="animate-spin"><line x1="12" y1="2" x2="12" y2="6"></line><line x1="12" y1="18" x2="12" y2="22"></line><line x1="4.93" y1="4.93" x2="7.76" y2="7.76"></line><line x1="16.24" y1="16.24" x2="19.07" y2="19.07"></line><line x1="2" y1="12" x2="6" y2="12"></line><line x1="18" y1="12" x2="22" y2="12"></line><line x1="4.93" y1="19.07" x2="7.76" y2="16.24"></line><line x1="16.24" y1="7.76" x2="19.07" y2="4.93"></line></svg>;
21
+ const Mic = () => <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"></path><path d="M19 10v2a7 7 0 0 1-14 0v-2"></path><line x1="12" y1="19" x2="12" y2="23"></line><line x1="8" y1="23" x2="16" y2="23"></line></svg>;
22
+ const MicOff = () => <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><line x1="1" y1="1" x2="23" y2="23"></line><path d="M9 9v3a3 3 0 0 0 5.12 2.12M15 9.34V4a3 3 0 0 0-5.94-.6"></path><path d="M17 16.95A7 7 0 0 1 5 12v-2m14 0v2a7 7 0 0 1-.11 1.23"></path><line x1="12" y1="19" x2="12" y2="23"></line><line x1="8" y1="23" x2="16" y2="23"></line></svg>;
23
+ const Volume2 = ({ size = 16 }) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"></polygon><path d="M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"></path></svg>;
24
+ const VolumeX = () => <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><polygon points="11 5 6 9 2 9 2 15 6 15 11 19 11 5"></polygon><line x1="23" y1="9" x2="17" y2="15"></line><line x1="17" y1="9" x2="23" y2="15"></line></svg>;
25
+ const MessageSquare = ({ size = 24 }) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"></path></svg>;
26
+ const Settings = ({ size = 20 }) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="12" cy="12" r="3"></circle><path d="M12 1v6m0 6v6m9-9h-6m-6 0H3"></path></svg>;
27
+ const BookOpen = ({ size = 20 }) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"></path><path d="M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z"></path></svg>;
28
+ const Trophy = ({ size = 16 }) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M6 9H4.5a2.5 2.5 0 0 1 0-5H6"></path><path d="M18 9h1.5a2.5 2.5 0 0 0 0-5H18"></path><path d="M4 22h16"></path><path d="M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22"></path><path d="M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22"></path><path d="M18 2H6v7a6 6 0 0 0 12 0V2Z"></path></svg>;
29
+ const Target = ({ size = 16 }) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="12" cy="12" r="10"></circle><circle cx="12" cy="12" r="6"></circle><circle cx="12" cy="12" r="2"></circle></svg>;
30
+ const RotateCcw = ({ size = 20 }) => <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><polyline points="1 4 1 10 7 10"></polyline><path d="M3.51 15a9 9 0 1 0 2.13-9.36L1 10"></path></svg>;
31
+
32
+ function FrenchTutor() {
33
+ const [messages, setMessages] = useState([]);
34
+ const [input, setInput] = useState('');
35
+ const [loading, setLoading] = useState(false);
36
+ const [level, setLevel] = useState('intermediate');
37
+ const [feedbackMode, setFeedbackMode] = useState('balanced');
38
+ const [showSettings, setShowSettings] = useState(false);
39
+ const [isListening, setIsListening] = useState(false);
40
+ const [autoSpeak, setAutoSpeak] = useState(true);
41
+ const [voiceSpeed, setVoiceSpeed] = useState(0.9);
42
+ const [currentMode, setCurrentMode] = useState('conversation');
43
+ const [vocabularyList, setVocabularyList] = useState([]);
44
+ const [showVocab, setShowVocab] = useState(false);
45
+ const [pronunciationScore, setPronunciationScore] = useState(null);
46
+ const messagesEndRef = useRef(null);
47
+ const recognitionRef = useRef(null);
48
+ const synthRef = useRef(window.speechSynthesis);
49
+
50
+ const conversationTopics = {
51
+ beginner: [
52
+ 'Introducing yourself',
53
+ 'Ordering food at a café',
54
+ 'Asking for directions',
55
+ 'Shopping for clothes',
56
+ 'Talking about hobbies',
57
+ 'Describing your family'
58
+ ],
59
+ intermediate: [
60
+ 'Planning a vacation',
61
+ 'Discussing current events',
62
+ 'Describing your job',
63
+ 'Talking about movies and books',
64
+ 'Health and wellness',
65
+ 'French culture and traditions'
66
+ ],
67
+ advanced: [
68
+ 'Debating social issues',
69
+ 'Discussing philosophy and ethics',
70
+ 'Analyzing French literature',
71
+ 'French politics and history',
72
+ 'Business and professional topics',
73
+ 'Idioms and expressions'
74
+ ]
75
+ };
76
+
77
+ const scrollToBottom = () => {
78
+ messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
79
+ };
80
+
81
+ useEffect(() => {
82
+ scrollToBottom();
83
+ }, [messages]);
84
+
85
+ useEffect(() => {
86
+ if (messages.length === 0) {
87
+ const welcomeMessage = {
88
+ role: 'assistant',
89
+ content: level === 'beginner'
90
+ ? "Bonjour ! Je suis La Casseuse, votre tutrice de français. Hello! I'm La Casseuse, your French tutor. Choose a conversation topic or start speaking freely!"
91
+ : level === 'intermediate'
92
+ ? "Bonjour ! Comment allez-vous ? Choose a topic or start a free conversation. I'll track your vocabulary and help with pronunciation."
93
+ : "Bonjour ! Ravi de vous rencontrer. Select a discussion topic or let's have a natural conversation. I'll help you master advanced French.",
94
+ timestamp: new Date().toISOString()
95
+ };
96
+ setMessages([welcomeMessage]);
97
+
98
+ if (autoSpeak) {
99
+ setTimeout(() => speak(welcomeMessage.content), 500);
100
+ }
101
+ }
102
+ }, [level]);
103
+
104
+ useEffect(() => {
105
+ if ('webkitSpeechRecognition' in window || 'SpeechRecognition' in window) {
106
+ const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
107
+ recognitionRef.current = new SpeechRecognition();
108
+ recognitionRef.current.continuous = false;
109
+ recognitionRef.current.interimResults = false;
110
+ recognitionRef.current.lang = 'fr-FR';
111
+
112
+ recognitionRef.current.onresult = (event) => {
113
+ const transcript = event.results[0][0].transcript;
114
+ const confidence = event.results[0][0].confidence;
115
+
116
+ const score = Math.round(confidence * 100);
117
+ setPronunciationScore(score);
118
+
119
+ setInput(transcript);
120
+ setIsListening(false);
121
+ };
122
+
123
+ recognitionRef.current.onerror = (event) => {
124
+ console.error('Speech recognition error:', event.error);
125
+ setIsListening(false);
126
+ };
127
+
128
+ recognitionRef.current.onend = () => {
129
+ setIsListening(false);
130
+ };
131
+ }
132
+
133
+ return () => {
134
+ if (recognitionRef.current) {
135
+ recognitionRef.current.stop();
136
+ }
137
+ };
138
+ }, []);
139
+
140
+ const buildSystemPrompt = () => {
141
+ const levelDescriptions = {
142
+ beginner: 'A1-A2 level learner who is just starting with French. Use simple vocabulary and grammar. Provide translations for most French text. Be encouraging and patient.',
143
+ intermediate: 'B1-B2 level learner with basic French knowledge. Use more complex structures. Provide translations selectively. Challenge them while being supportive.',
144
+ advanced: 'C1-C2 level learner approaching fluency. Use natural, native-level French. Minimal translations. Focus on nuance, idioms, and cultural context.'
145
+ };
146
+
147
+ const feedbackDescriptions = {
148
+ minimal: 'Only correct major errors. Keep the conversation flowing naturally.',
149
+ balanced: 'Correct important errors and occasionally highlight good usage. Balance correction with encouragement.',
150
+ detailed: 'Provide thorough feedback on grammar, vocabulary choices, and pronunciation tips. Explain rules and alternatives.'
151
+ };
152
+
153
+ let basePrompt = `You are La Casseuse, an expert French language tutor having a conversation with a ${levelDescriptions[level]}
154
+
155
+ Feedback style: ${feedbackDescriptions[feedbackMode]}
156
+
157
+ Guidelines:
158
+ 1. Respond naturally in French at the appropriate level
159
+ 2. Keep responses conversational and relatively concise (2-4 sentences typically) since this is spoken conversation
160
+ 3. When providing corrections, integrate them naturally
161
+ 4. Use encouragement: "Très bien!", "Excellent!", "C'est ça!"`;
162
+
163
+ if (currentMode === 'vocabulary') {
164
+ basePrompt += `\n\nVOCABULARY MODE: At the end of your response, list 2-3 key vocabulary words or phrases from your message in this exact format:\nVOCAB: word1 (translation), word2 (translation), word3 (translation)`;
165
+ } else if (currentMode === 'pronunciation') {
166
+ basePrompt += `\n\nPRONUNCIATION MODE: Focus on helping them pronounce difficult words. When they make pronunciation errors, gently correct them and provide tips on French phonetics.`;
167
+ }
168
+
169
+ basePrompt += `\n\nFor beginners: Provide English translations in parentheses after French sentences.\nFor intermediate: Provide translations only for complex phrases or new vocabulary.\nFor advanced: Use French almost exclusively, with minimal English support.`;
170
+
171
+ return basePrompt;
172
+ };
173
+
174
+ const extractVocabulary = (text) => {
175
+ const vocabMatch = text.match(/VOCAB: (.+?)(?:\n|$)/);
176
+ if (vocabMatch) {
177
+ const vocabItems = vocabMatch[1].split(',').map(item => {
178
+ const parts = item.trim().match(/(.+?)\s*\((.+?)\)/);
179
+ if (parts) {
180
+ return { word: parts[1].trim(), translation: parts[2].trim() };
181
+ }
182
+ return null;
183
+ }).filter(Boolean);
184
+
185
+ setVocabularyList(prev => [...vocabItems, ...prev].slice(0, 30));
186
+ return text.replace(/VOCAB: .+?(?:\n|$)/, '').trim();
187
+ }
188
+ return text;
189
+ };
190
+
191
+ const handleSend = async (textToSend = input) => {
192
+ if (!textToSend.trim() || loading) return;
193
+
194
+ const userMessage = {
195
+ role: 'user',
196
+ content: textToSend,
197
+ timestamp: new Date().toISOString()
198
+ };
199
+
200
+ setMessages(prev => [...prev, userMessage]);
201
+ setInput('');
202
+ setLoading(true);
203
+
204
+ try {
205
+ const conversationHistory = [...messages, userMessage].map(msg => ({
206
+ role: msg.role,
207
+ content: msg.content
208
+ }));
209
+
210
+ // Call OUR backend instead of Claude directly
211
+ const response = await fetch('/api/chat', {
212
+ method: 'POST',
213
+ headers: {
214
+ 'Content-Type': 'application/json',
215
+ },
216
+ body: JSON.stringify({
217
+ model: 'claude-sonnet-4-20250514',
218
+ max_tokens: 1000,
219
+ system: buildSystemPrompt(),
220
+ messages: conversationHistory
221
+ })
222
+ });
223
+
224
+ const data = await response.json();
225
+
226
+ if (data.content && data.content[0]) {
227
+ let content = data.content[0].text;
228
+
229
+ if (currentMode === 'vocabulary') {
230
+ content = extractVocabulary(content);
231
+ }
232
+
233
+ const assistantMessage = {
234
+ role: 'assistant',
235
+ content: content,
236
+ timestamp: new Date().toISOString()
237
+ };
238
+ setMessages(prev => [...prev, assistantMessage]);
239
+
240
+ if (autoSpeak) {
241
+ setTimeout(() => speak(assistantMessage.content), 300);
242
+ }
243
+ } else if (data.error) {
244
+ setMessages(prev => [...prev, {
245
+ role: 'assistant',
246
+ content: `Error: ${data.error}`,
247
+ timestamp: new Date().toISOString()
248
+ }]);
249
+ }
250
+ } catch (error) {
251
+ console.error('Error:', error);
252
+ setMessages(prev => [...prev, {
253
+ role: 'assistant',
254
+ content: 'Désolé, there was an error. Please try again.',
255
+ timestamp: new Date().toISOString()
256
+ }]);
257
+ } finally {
258
+ setLoading(false);
259
+ }
260
+ };
261
+
262
+ const speak = (text) => {
263
+ synthRef.current.cancel();
264
+
265
+ const cleanText = text.replace(/[✏️📚🗣️🇫🇷*]/g, '').replace(/\([^)]*\)/g, '');
266
+ const utterance = new SpeechSynthesisUtterance(cleanText);
267
+ utterance.lang = 'fr-FR';
268
+ utterance.rate = voiceSpeed;
269
+
270
+ const voices = synthRef.current.getVoices();
271
+ const frenchVoice = voices.find(voice => voice.lang.startsWith('fr'));
272
+ if (frenchVoice) {
273
+ utterance.voice = frenchVoice;
274
+ }
275
+
276
+ synthRef.current.speak(utterance);
277
+ };
278
+
279
+ const toggleListening = () => {
280
+ if (!recognitionRef.current) {
281
+ alert('Speech recognition is not supported in your browser. Please use Chrome, Edge, or Safari.');
282
+ return;
283
+ }
284
+
285
+ if (isListening) {
286
+ recognitionRef.current.stop();
287
+ setIsListening(false);
288
+ } else {
289
+ synthRef.current.cancel();
290
+ setInput('');
291
+ setPronunciationScore(null);
292
+ recognitionRef.current.start();
293
+ setIsListening(true);
294
+ }
295
+ };
296
+
297
+ const stopSpeaking = () => {
298
+ synthRef.current.cancel();
299
+ };
300
+
301
+ const startTopicConversation = async (topic) => {
302
+ const topicMessage = `Let's practice: ${topic}`;
303
+ setInput(topicMessage);
304
+ await handleSend(topicMessage);
305
+ };
306
+
307
+ const resetConversation = () => {
308
+ setMessages([]);
309
+ setVocabularyList([]);
310
+ setPronunciationScore(null);
311
+ const welcomeMessage = {
312
+ role: 'assistant',
313
+ content: "Bonjour ! Ready for a new conversation? Choose a topic or start speaking!",
314
+ timestamp: new Date().toISOString()
315
+ };
316
+ setMessages([welcomeMessage]);
317
+ if (autoSpeak) speak(welcomeMessage.content);
318
+ };
319
+
320
+ useEffect(() => {
321
+ if (input && !isListening) {
322
+ handleSend(input);
323
+ }
324
+ }, [input, isListening]);
325
+
326
+ const getPronunciationColor = (score) => {
327
+ if (score >= 80) return 'text-green-600';
328
+ if (score >= 60) return 'text-yellow-600';
329
+ return 'text-red-600';
330
+ };
331
+
332
+ const getPronunciationLabel = (score) => {
333
+ if (score >= 90) return 'Excellent!';
334
+ if (score >= 80) return 'Very Good';
335
+ if (score >= 70) return 'Good';
336
+ if (score >= 60) return 'Fair';
337
+ return 'Keep Practicing';
338
+ };
339
+
340
+ return (
341
+ <div className="flex flex-col h-screen bg-gradient-to-br from-blue-50 to-indigo-50">
342
+ {/* Header */}
343
+ <div className="bg-white shadow-sm border-b border-gray-200 px-6 py-4">
344
+ <div className="flex items-center justify-between max-w-6xl mx-auto">
345
+ <div className="flex items-center gap-3">
346
+ <div className="bg-blue-600 text-white p-2 rounded-lg">
347
+ <MessageSquare size={24} />
348
+ </div>
349
+ <div>
350
+ <h1 className="text-2xl font-bold text-gray-900">La Casseuse</h1>
351
+ <p className="text-sm text-gray-600">Your French conversation partner</p>
352
+ </div>
353
+ </div>
354
+ <div className="flex gap-2">
355
+ <button
356
+ onClick={() => setShowVocab(!showVocab)}
357
+ className={`p-2 rounded-lg transition-colors ${showVocab ? 'bg-blue-100 text-blue-600' : 'hover:bg-gray-100 text-gray-600'}`}
358
+ title="Vocabulary List"
359
+ >
360
+ <BookOpen size={20} />
361
+ {vocabularyList.length > 0 && (
362
+ </div>
363
+ </div>
364
+ ))}
365
+ {loading && (
366
+ <div className="flex justify-start">
367
+ <div className="bg-white text-gray-900 shadow-sm border border-gray-200 rounded-2xl px-4 py-3">
368
+ <Loader2 />
369
+ </div>
370
+ </div>
371
+ )}
372
+ <div ref={messagesEndRef} />
373
+ </div>
374
+ </div>
375
+ </div>
376
+
377
+ {/* Voice Controls */}
378
+ <div className="bg-white border-t border-gray-200 px-4 py-6">
379
+ <div className="max-w-6xl mx-auto">
380
+ <div className="flex flex-col items-center gap-4">
381
+ {/* Microphone Button */}
382
+ <button
383
+ onClick={toggleListening}
384
+ disabled={loading}
385
+ className={`w-20 h-20 rounded-full flex items-center justify-center transition-all shadow-lg ${
386
+ isListening
387
+ ? 'bg-red-500 hover:bg-red-600 animate-pulse'
388
+ : 'bg-blue-600 hover:bg-blue-700'
389
+ } text-white disabled:opacity-50 disabled:cursor-not-allowed`}
390
+ >
391
+ {isListening ? <MicOff /> : <Mic />}
392
+ </button>
393
+
394
+ {isListening && (
395
+ <div className="text-center">
396
+ <p className="text-sm font-medium text-gray-700">Listening...</p>
397
+ <p className="text-xs text-gray-500">Speak in French</p>
398
+ </div>
399
+ )}
400
+
401
+ {/* Text Input Alternative */}
402
+ <div className="w-full flex gap-2">
403
+ <input
404
+ type="text"
405
+ value={input}
406
+ onChange={(e) => setInput(e.target.value)}
407
+ onKeyPress={(e) => e.key === 'Enter' && handleSend()}
408
+ placeholder="Or type your message in French..."
409
+ className="flex-1 px-4 py-2 border border-gray-300 rounded-xl focus:ring-2 focus:ring-blue-500 focus:border-transparent text-sm"
410
+ disabled={loading || isListening}
411
+ />
412
+ <button
413
+ onClick={() => handleSend()}
414
+ disabled={loading || !input.trim() || isListening}
415
+ className="bg-blue-600 text-white px-4 py-2 rounded-xl hover:bg-blue-700 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
416
+ >
417
+ {loading ? <Loader2 /> : <Send />}
418
+ </button>
419
+ <button
420
+ onClick={stopSpeaking}
421
+ className="bg-gray-600 text-white px-4 py-2 rounded-xl hover:bg-gray-700 transition-colors flex items-center gap-2"
422
+ title="Stop speaking"
423
+ >
424
+ <VolumeX />
425
+ </button>
426
+ </div>
427
+
428
+ <p className="text-xs text-gray-500 text-center">
429
+ Click microphone to speak • Choose topics from sidebar • {currentMode === 'vocabulary' && 'Building vocabulary list'}
430
+ </p>
431
+ </div>
432
+ </div>
433
+ </div>
434
+ </div>
435
+ );
436
+ }
437
+
438
+ ReactDOM.createRoot(document.getElementById('root')).render(<FrenchTutor />);
439
+ </script>
440
+ </body>
441
+ </html><span className="ml-1 text-xs font-bold">{vocabularyList.length}</span>
442
+ )}
443
+ </button>
444
+ <button
445
+ onClick={resetConversation}
446
+ className="p-2 hover:bg-gray-100 rounded-lg transition-colors text-gray-600"
447
+ title="New Conversation"
448
+ >
449
+ <RotateCcw size={20} />
450
+ </button>
451
+ <button
452
+ onClick={() => setShowSettings(!showSettings)}
453
+ className="p-2 hover:bg-gray-100 rounded-lg transition-colors text-gray-600"
454
+ >
455
+ <Settings size={20} />
456
+ </button>
457
+ </div>
458
+ </div>
459
+ </div>
460
+
461
+ {/* Mode Selector */}
462
+ <div className="bg-white border-b border-gray-200 px-6 py-3">
463
+ <div className="max-w-6xl mx-auto flex gap-2">
464
+ <button
465
+ onClick={() => setCurrentMode('conversation')}
466
+ className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
467
+ currentMode === 'conversation'
468
+ ? 'bg-blue-600 text-white'
469
+ : 'bg-gray-100 text-gray-700 hover:bg-gray-200'
470
+ }`}
471
+ >
472
+ <MessageSquare size={16} style={{display: 'inline', marginRight: '4px'}} />
473
+ Free Talk
474
+ </button>
475
+ <button
476
+ onClick={() => setCurrentMode('vocabulary')}
477
+ className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
478
+ currentMode === 'vocabulary'
479
+ ? 'bg-blue-600 text-white'
480
+ : 'bg-gray-100 text-gray-700 hover:bg-gray-200'
481
+ }`}
482
+ >
483
+ <BookOpen size={16} style={{display: 'inline', marginRight: '4px'}} />
484
+ Vocabulary Builder
485
+ </button>
486
+ <button
487
+ onClick={() => setCurrentMode('pronunciation')}
488
+ className={`px-4 py-2 rounded-lg text-sm font-medium transition-colors ${
489
+ currentMode === 'pronunciation'
490
+ ? 'bg-blue-600 text-white'
491
+ : 'bg-gray-100 text-gray-700 hover:bg-gray-200'
492
+ }`}
493
+ >
494
+ Pronunciation Practice
495
+ </button>
496
+ </div>
497
+ </div>
498
+
499
+ {/* Settings Panel */}
500
+ {showSettings && (
501
+ <div className="bg-white border-b border-gray-200 px-6 py-4">
502
+ <div className="max-w-6xl mx-auto">
503
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
504
+ <div>
505
+ <label className="block text-sm font-medium text-gray-700 mb-2">
506
+ Proficiency Level
507
+ </label>
508
+ <select
509
+ value={level}
510
+ onChange={(e) => setLevel(e.target.value)}
511
+ className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
512
+ >
513
+ <option value="beginner">Beginner (A1-A2)</option>
514
+ <option value="intermediate">Intermediate (B1-B2)</option>
515
+ <option value="advanced">Advanced (C1-C2)</option>
516
+ </select>
517
+ </div>
518
+ <div>
519
+ <label className="block text-sm font-medium text-gray-700 mb-2">
520
+ Feedback Style
521
+ </label>
522
+ <select
523
+ value={feedbackMode}
524
+ onChange={(e) => setFeedbackMode(e.target.value)}
525
+ className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
526
+ >
527
+ <option value="minimal">Minimal - Flow over accuracy</option>
528
+ <option value="balanced">Balanced - Mix of both</option>
529
+ <option value="detailed">Detailed - Maximum learning</option>
530
+ </select>
531
+ </div>
532
+ <div>
533
+ <label className="flex items-center gap-2">
534
+ <input
535
+ type="checkbox"
536
+ checked={autoSpeak}
537
+ onChange={(e) => setAutoSpeak(e.target.checked)}
538
+ className="w-4 h-4 text-blue-600 rounded"
539
+ />
540
+ <span className="text-sm font-medium text-gray-700">
541
+ Auto-play responses
542
+ </span>
543
+ </label>
544
+ </div>
545
+ <div>
546
+ <label className="block text-sm font-medium text-gray-700 mb-2">
547
+ Voice Speed: {voiceSpeed.toFixed(1)}x
548
+ </label>
549
+ <input
550
+ type="range"
551
+ min="0.5"
552
+ max="1.5"
553
+ step="0.1"
554
+ value={voiceSpeed}
555
+ onChange={(e) => setVoiceSpeed(parseFloat(e.target.value))}
556
+ className="w-full"
557
+ />
558
+ </div>
559
+ </div>
560
+ </div>
561
+ </div>
562
+ )}
563
+
564
+ {/* Vocabulary Sidebar */}
565
+ {showVocab && (
566
+ <div className="bg-white border-b border-gray-200 px-6 py-4 max-h-64 overflow-y-auto">
567
+ <div className="max-w-6xl mx-auto">
568
+ <h3 className="text-lg font-bold text-gray-900 mb-3 flex items-center gap-2">
569
+ <BookOpen size={20} />
570
+ Your Vocabulary ({vocabularyList.length})
571
+ </h3>
572
+ {vocabularyList.length === 0 ? (
573
+ <p className="text-gray-500 text-sm">Start a vocabulary building session to collect new words!</p>
574
+ ) : (
575
+ <div className="grid grid-cols-1 md:grid-cols-3 gap-2">
576
+ {vocabularyList.map((item, idx) => (
577
+ <div key={idx} className="bg-blue-50 rounded-lg p-2">
578
+ <p className="font-semibold text-blue-900">{item.word}</p>
579
+ <p className="text-sm text-gray-600">{item.translation}</p>
580
+ </div>
581
+ ))}
582
+ </div>
583
+ )}
584
+ </div>
585
+ </div>
586
+ )}
587
+
588
+ <div className="flex-1 flex overflow-hidden">
589
+ {/* Topic Selector Sidebar */}
590
+ <div className="w-64 bg-white border-r border-gray-200 overflow-y-auto p-4">
591
+ <h3 className="text-sm font-bold text-gray-900 mb-3 flex items-center gap-2">
592
+ <Target size={16} />
593
+ Conversation Topics
594
+ </h3>
595
+ <div className="space-y-2">
596
+ {conversationTopics[level].map((topic, idx) => (
597
+ <button
598
+ key={idx}
599
+ onClick={() => startTopicConversation(topic)}
600
+ disabled={loading}
601
+ className="w-full text-left px-3 py-2 text-sm rounded-lg bg-gray-50 hover:bg-blue-50 hover:text-blue-700 transition-colors disabled:opacity-50"
602
+ >
603
+ {topic}
604
+ </button>
605
+ ))}
606
+ </div>
607
+
608
+ {pronunciationScore !== null && (
609
+ <div className="mt-6 p-3 bg-gradient-to-br from-purple-50 to-pink-50 rounded-lg">
610
+ <div className="flex items-center gap-2 mb-2">
611
+ <Trophy size={16} />
612
+ <span className="text-sm font-bold text-gray-900">Last Score</span>
613
+ </div>
614
+ <div className={`text-3xl font-bold ${getPronunciationColor(pronunciationScore)}`}>
615
+ {pronunciationScore}%
616
+ </div>
617
+ <p className="text-xs text-gray-600 mt-1">{getPronunciationLabel(pronunciationScore)}</p>
618
+ </div>
619
+ )}
620
+ </div>
621
+
622
+ {/* Messages */}
623
+ <div className="flex-1 overflow-y-auto px-4 py-6">
624
+ <div className="max-w-4xl mx-auto space-y-4">
625
+ {messages.map((msg, idx) => (
626
+ <div
627
+ key={idx}
628
+ className={`flex ${msg.role === 'user' ? 'justify-end' : 'justify-start'}`}
629
+ >
630
+ <div
631
+ className={`max-w-2xl rounded-2xl px-4 py-3 ${
632
+ msg.role === 'user'
633
+ ? 'bg-blue-600 text-white'
634
+ : 'bg-white text-gray-900 shadow-sm border border-gray-200'
635
+ }`}
636
+ >
637
+ <div className="flex items-start gap-2">
638
+ <div className="flex-1 whitespace-pre-wrap break-words">
639
+ {msg.content}
640
+ </div>
641
+ {msg.role === 'assistant' && (
642
+ <button
643
+ onClick={() => speak(msg.content)}
644
+ className="flex-shrink-0 p-1 hover:bg-gray-100 rounded transition-colors"
645
+ title="Listen"
646
+ >
647
+ <Volume2 size={16} />
648
+ </button>
649
+ )}
650
+ </div>