Initial commit
This commit is contained in:
10
frontend/Dockerfile
Normal file
10
frontend/Dockerfile
Normal file
@@ -0,0 +1,10 @@
|
||||
FROM node:20-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY package.json package-lock.json* ./
|
||||
RUN npm install
|
||||
|
||||
COPY . .
|
||||
|
||||
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0", "--port", "3000"]
|
||||
12
frontend/index.html
Normal file
12
frontend/index.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Professeur virtuel</title>
|
||||
<script type="module" src="/src/main.jsx"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
19
frontend/package.json
Normal file
19
frontend/package.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "prof-virtuel-frontend",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-react": "^4.3.4",
|
||||
"vite": "^5.4.14"
|
||||
}
|
||||
}
|
||||
271
frontend/src/App.jsx
Normal file
271
frontend/src/App.jsx
Normal file
@@ -0,0 +1,271 @@
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react'
|
||||
|
||||
const API_BASE = '/api'
|
||||
|
||||
function Avatar({ speaking }) {
|
||||
return (
|
||||
<div className="avatar-shell">
|
||||
<div className={`avatar ${speaking ? 'speaking' : ''}`}>
|
||||
<div className="face">
|
||||
<div className="eyes">
|
||||
<span />
|
||||
<span />
|
||||
</div>
|
||||
<div className={`mouth ${speaking ? 'mouth-speaking' : ''}`} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="avatar-caption">ProfAmi</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function ProgressCard({ item }) {
|
||||
const pct = Math.round(item.mastery_score)
|
||||
return (
|
||||
<div className="progress-card">
|
||||
<div className="progress-head">
|
||||
<strong>{item.label}</strong>
|
||||
<span>{pct}%</span>
|
||||
</div>
|
||||
<div className="progress-bar">
|
||||
<div className="progress-fill" style={{ width: `${pct}%` }} />
|
||||
</div>
|
||||
<small>{item.subject} · preuves: {item.evidence_count}</small>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [students, setStudents] = useState([])
|
||||
const [selectedStudentId, setSelectedStudentId] = useState('')
|
||||
const [form, setForm] = useState({ first_name: '', age: 8, grade: 'CM1' })
|
||||
const [messages, setMessages] = useState([])
|
||||
const [input, setInput] = useState('')
|
||||
const [progress, setProgress] = useState([])
|
||||
const [assessment, setAssessment] = useState(null)
|
||||
const [assessmentAnswer, setAssessmentAnswer] = useState('')
|
||||
const [speaking, setSpeaking] = useState(false)
|
||||
const recognitionRef = useRef(null)
|
||||
|
||||
const selectedStudent = useMemo(
|
||||
() => students.find((s) => String(s.id) === String(selectedStudentId)),
|
||||
[students, selectedStudentId]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
loadStudents()
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedStudentId) {
|
||||
loadProgress(selectedStudentId)
|
||||
}
|
||||
}, [selectedStudentId])
|
||||
|
||||
async function loadStudents() {
|
||||
const res = await fetch(`${API_BASE}/students`)
|
||||
const data = await res.json()
|
||||
setStudents(data)
|
||||
if (data.length && !selectedStudentId) {
|
||||
setSelectedStudentId(String(data[0].id))
|
||||
}
|
||||
}
|
||||
|
||||
async function createStudent(e) {
|
||||
e.preventDefault()
|
||||
const res = await fetch(`${API_BASE}/students`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ ...form, age: Number(form.age) }),
|
||||
})
|
||||
const data = await res.json()
|
||||
await loadStudents()
|
||||
setSelectedStudentId(String(data.id))
|
||||
}
|
||||
|
||||
async function startSession() {
|
||||
if (!selectedStudentId) return
|
||||
const res = await fetch(`${API_BASE}/session/start?student_id=${selectedStudentId}`, { method: 'POST' })
|
||||
const data = await res.json()
|
||||
appendMessage('assistant', data.reply)
|
||||
speak(data.reply)
|
||||
await loadProgress(selectedStudentId)
|
||||
}
|
||||
|
||||
function appendMessage(role, content) {
|
||||
setMessages((prev) => [...prev, { role, content, id: crypto.randomUUID() }])
|
||||
}
|
||||
|
||||
async function sendMessage(e) {
|
||||
e.preventDefault()
|
||||
if (!selectedStudentId || !input.trim()) return
|
||||
const text = input.trim()
|
||||
appendMessage('user', text)
|
||||
setInput('')
|
||||
const res = await fetch(`${API_BASE}/chat`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ student_id: Number(selectedStudentId), message: text }),
|
||||
})
|
||||
const data = await res.json()
|
||||
appendMessage('assistant', data.reply)
|
||||
speak(data.reply)
|
||||
}
|
||||
|
||||
async function loadProgress(studentId) {
|
||||
const res = await fetch(`${API_BASE}/progress/${studentId}`)
|
||||
const data = await res.json()
|
||||
setProgress(data.progress || [])
|
||||
}
|
||||
|
||||
async function fetchAssessment() {
|
||||
if (!selectedStudentId) return
|
||||
const res = await fetch(`${API_BASE}/assessment/next/${selectedStudentId}`)
|
||||
const data = await res.json()
|
||||
setAssessment(data)
|
||||
setAssessmentAnswer('')
|
||||
}
|
||||
|
||||
async function submitAssessment(e) {
|
||||
e.preventDefault()
|
||||
if (!assessment || !assessmentAnswer.trim()) return
|
||||
const res = await fetch(`${API_BASE}/assessment/answer`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
student_id: Number(selectedStudentId),
|
||||
skill_code: assessment.skill_code,
|
||||
answer: assessmentAnswer,
|
||||
}),
|
||||
})
|
||||
const data = await res.json()
|
||||
appendMessage('assistant', `Quiz: ${data.feedback}`)
|
||||
speak(data.feedback)
|
||||
setAssessment(null)
|
||||
setAssessmentAnswer('')
|
||||
await loadProgress(selectedStudentId)
|
||||
}
|
||||
|
||||
function speak(text) {
|
||||
if (!('speechSynthesis' in window)) return
|
||||
window.speechSynthesis.cancel()
|
||||
const utterance = new SpeechSynthesisUtterance(text)
|
||||
utterance.lang = 'fr-FR'
|
||||
utterance.onstart = () => setSpeaking(true)
|
||||
utterance.onend = () => setSpeaking(false)
|
||||
utterance.onerror = () => setSpeaking(false)
|
||||
window.speechSynthesis.speak(utterance)
|
||||
}
|
||||
|
||||
function startVoiceInput() {
|
||||
const Recognition = window.SpeechRecognition || window.webkitSpeechRecognition
|
||||
if (!Recognition) {
|
||||
alert('La reconnaissance vocale du navigateur n\'est pas disponible ici.')
|
||||
return
|
||||
}
|
||||
const recognition = new Recognition()
|
||||
recognition.lang = 'fr-FR'
|
||||
recognition.interimResults = false
|
||||
recognition.maxAlternatives = 1
|
||||
recognition.onresult = (event) => {
|
||||
const transcript = event.results[0][0].transcript
|
||||
setInput(transcript)
|
||||
}
|
||||
recognition.onerror = () => {}
|
||||
recognitionRef.current = recognition
|
||||
recognition.start()
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="layout">
|
||||
<aside className="sidebar card">
|
||||
<h2>Élève</h2>
|
||||
<select value={selectedStudentId} onChange={(e) => setSelectedStudentId(e.target.value)}>
|
||||
<option value="">Choisir un élève</option>
|
||||
{students.map((student) => (
|
||||
<option key={student.id} value={student.id}>
|
||||
{student.first_name} · {student.grade}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
|
||||
<form onSubmit={createStudent} className="stack">
|
||||
<input
|
||||
placeholder="Prénom"
|
||||
value={form.first_name}
|
||||
onChange={(e) => setForm({ ...form, first_name: e.target.value })}
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
min="8"
|
||||
max="12"
|
||||
value={form.age}
|
||||
onChange={(e) => setForm({ ...form, age: e.target.value })}
|
||||
/>
|
||||
<select value={form.grade} onChange={(e) => setForm({ ...form, grade: e.target.value })}>
|
||||
<option>CE2</option>
|
||||
<option>CM1</option>
|
||||
<option>CM2</option>
|
||||
<option>6e</option>
|
||||
</select>
|
||||
<button type="submit">Créer un élève</button>
|
||||
</form>
|
||||
|
||||
<button onClick={startSession} disabled={!selectedStudentId}>Démarrer la séance</button>
|
||||
<button onClick={fetchAssessment} disabled={!selectedStudentId}>Lancer un mini-test</button>
|
||||
|
||||
<h3>Progression</h3>
|
||||
<div className="stack small-gap">
|
||||
{progress.map((item) => <ProgressCard key={item.code} item={item} />)}
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<main className="main card">
|
||||
<div className="hero">
|
||||
<Avatar speaking={speaking} />
|
||||
<div>
|
||||
<h1>Professeur virtuel</h1>
|
||||
<p>
|
||||
{selectedStudent
|
||||
? `Séance active pour ${selectedStudent.first_name}, ${selectedStudent.grade}`
|
||||
: 'Choisis ou crée un élève pour commencer.'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section className="messages">
|
||||
{messages.length === 0 && <p className="muted">Le dialogue apparaîtra ici.</p>}
|
||||
{messages.map((message) => (
|
||||
<div key={message.id} className={`message ${message.role}`}>
|
||||
<strong>{message.role === 'assistant' ? 'ProfAmi' : 'Élève'}</strong>
|
||||
<p>{message.content}</p>
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
|
||||
{assessment && (
|
||||
<form className="assessment" onSubmit={submitAssessment}>
|
||||
<h3>Mini-test · {assessment.skill_label}</h3>
|
||||
<p>{assessment.question}</p>
|
||||
<input
|
||||
value={assessmentAnswer}
|
||||
onChange={(e) => setAssessmentAnswer(e.target.value)}
|
||||
placeholder="Ta réponse"
|
||||
/>
|
||||
<button type="submit">Valider</button>
|
||||
</form>
|
||||
)}
|
||||
|
||||
<form onSubmit={sendMessage} className="composer">
|
||||
<input
|
||||
value={input}
|
||||
onChange={(e) => setInput(e.target.value)}
|
||||
placeholder="Pose une question ou demande une explication..."
|
||||
/>
|
||||
<button type="button" onClick={startVoiceInput}>🎤 Dicter</button>
|
||||
<button type="submit">Envoyer</button>
|
||||
</form>
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
10
frontend/src/main.jsx
Normal file
10
frontend/src/main.jsx
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom/client'
|
||||
import App from './App'
|
||||
import './styles.css'
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
)
|
||||
141
frontend/src/styles.css
Normal file
141
frontend/src/styles.css
Normal file
@@ -0,0 +1,141 @@
|
||||
:root {
|
||||
font-family: Inter, system-ui, sans-serif;
|
||||
color: #14213d;
|
||||
background: #f5f7fb;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
body { margin: 0; }
|
||||
button, input, select {
|
||||
font: inherit;
|
||||
border-radius: 12px;
|
||||
border: 1px solid #cfd7e6;
|
||||
padding: 0.8rem 1rem;
|
||||
}
|
||||
button {
|
||||
background: #2563eb;
|
||||
color: white;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
|
||||
.layout {
|
||||
display: grid;
|
||||
grid-template-columns: 360px 1fr;
|
||||
min-height: 100vh;
|
||||
gap: 1rem;
|
||||
padding: 1rem;
|
||||
}
|
||||
.card {
|
||||
background: white;
|
||||
border-radius: 24px;
|
||||
box-shadow: 0 10px 30px rgba(20,33,61,0.08);
|
||||
padding: 1rem;
|
||||
}
|
||||
.sidebar, .main { display: flex; flex-direction: column; gap: 1rem; }
|
||||
.stack { display: flex; flex-direction: column; gap: 0.75rem; }
|
||||
.small-gap { gap: 0.5rem; }
|
||||
.hero { display: flex; align-items: center; gap: 1rem; }
|
||||
.messages {
|
||||
flex: 1;
|
||||
min-height: 360px;
|
||||
overflow: auto;
|
||||
background: #f8fafc;
|
||||
border-radius: 20px;
|
||||
padding: 1rem;
|
||||
}
|
||||
.message {
|
||||
max-width: 80%;
|
||||
margin-bottom: 0.75rem;
|
||||
padding: 0.9rem 1rem;
|
||||
border-radius: 18px;
|
||||
}
|
||||
.message.user {
|
||||
margin-left: auto;
|
||||
background: #dbeafe;
|
||||
}
|
||||
.message.assistant {
|
||||
background: #eaf7e7;
|
||||
}
|
||||
.message p { margin: 0.35rem 0 0; white-space: pre-wrap; }
|
||||
.composer {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto auto;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
.assessment {
|
||||
background: #fff7ed;
|
||||
padding: 1rem;
|
||||
border-radius: 18px;
|
||||
}
|
||||
.progress-card {
|
||||
border: 1px solid #e5e7eb;
|
||||
border-radius: 16px;
|
||||
padding: 0.75rem;
|
||||
}
|
||||
.progress-head {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
margin-bottom: 0.4rem;
|
||||
}
|
||||
.progress-bar {
|
||||
height: 10px;
|
||||
background: #e5e7eb;
|
||||
border-radius: 999px;
|
||||
overflow: hidden;
|
||||
margin-bottom: 0.35rem;
|
||||
}
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
background: linear-gradient(90deg, #60a5fa, #2563eb);
|
||||
}
|
||||
.muted { color: #64748b; }
|
||||
.avatar-shell { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; }
|
||||
.avatar {
|
||||
width: 144px;
|
||||
height: 144px;
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(circle at 30% 30%, #fde68a, #f59e0b);
|
||||
display: grid;
|
||||
place-items: center;
|
||||
box-shadow: 0 10px 20px rgba(245, 158, 11, 0.28);
|
||||
}
|
||||
.avatar.speaking { animation: pulse 0.7s infinite alternate; }
|
||||
.face { width: 90px; }
|
||||
.eyes {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 1.2rem;
|
||||
}
|
||||
.eyes span {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
background: #1f2937;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.mouth {
|
||||
width: 44px;
|
||||
height: 10px;
|
||||
background: #7c2d12;
|
||||
border-radius: 999px;
|
||||
margin: 0 auto;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
.mouth-speaking {
|
||||
width: 34px;
|
||||
height: 24px;
|
||||
border-radius: 0 0 999px 999px;
|
||||
}
|
||||
.avatar-caption { font-weight: 700; }
|
||||
|
||||
@keyframes pulse {
|
||||
from { transform: scale(1); }
|
||||
to { transform: scale(1.05); }
|
||||
}
|
||||
|
||||
@media (max-width: 920px) {
|
||||
.layout { grid-template-columns: 1fr; }
|
||||
.composer { grid-template-columns: 1fr; }
|
||||
}
|
||||
10
frontend/vite.config.js
Normal file
10
frontend/vite.config.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
server: {
|
||||
host: true,
|
||||
allowedHosts: ['prof.open-squared.tech']
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user