fixed some issues, but the pass button will eventually be removed

This commit is contained in:
Didictateur 2026-02-02 19:09:09 +01:00
parent 9d82c861e7
commit b22b7bd37f
3 changed files with 44 additions and 29 deletions

View file

@ -1,5 +1,6 @@
FROM python:3.10-slim
WORKDIR /app
RUN apt-get clean
RUN apt-get update && apt-get install -y build-essential && rm -rf /var/lib/apt/lists/*
COPY . .
RUN pip install --no-cache-dir flask gensim gunicorn numpy

View file

@ -117,17 +117,23 @@ def submit_score():
history.append({'word': guess_word, 'score': score, 'remaining': len(new_word_indexes)})
session['history'] = history
if not new_word_indexes:
return jsonify({'result': 'Plus aucun mot possible. Terminé.', 'history': history})
session['current_guess_idx'] = None
return jsonify({'result': 'Plus aucun mot possible. Terminé.', 'history': history, 'remaining': 0})
else:
session['current_guess_idx'] = new_word_indexes[0]
if len(new_word_indexes) == 1:
return jsonify({'result': f"Plus qu'un seul mot possible: {all_words[new_word_indexes[0]]}", 'history': history})
return jsonify({'result': f"Plus qu'un seul mot possible: {all_words[new_word_indexes[0]]}", 'history': history, 'remaining': 1})
return jsonify({'remaining': len(new_word_indexes), 'history': history})
@app.route('/skip', methods=['POST'])
def skip_word():
word_indexes = session.get('word_indexes', [])
current_guess_idx = session.get('current_guess_idx')
if current_guess_idx is None or not word_indexes:
return jsonify({'error': 'Aucun mot à passer'}), 400
if not word_indexes:
return jsonify({'result': 'Plus aucun mot possible. Terminé.', 'history': session.get('history', [])})
if current_guess_idx is None or current_guess_idx >= len(word_indexes):
# Si aucun mot sélectionné, on prend le premier
current_guess_idx = word_indexes[0]
# Recalculer all_words à partir du modèle et du mot de départ
lang = session.get('lang', 'en')
model_path = session.get('model_path')
@ -143,6 +149,7 @@ def skip_word():
with open("english_words.txt") as f:
valid_words = set(w.strip() for w in f)
all_words = [w for w in model.index_to_key if w != first_word and is_valid_word(w, lang, valid_words)]
# On retire le mot courant de la liste
try:
word_indexes.remove(current_guess_idx)
except ValueError:
@ -151,9 +158,14 @@ def skip_word():
history = session.get('history', [])
history.append({'word': all_words[current_guess_idx], 'score': 'pass', 'remaining': len(word_indexes)})
session['history'] = history
if not word_indexes:
# On avance l'index courant si possible
if word_indexes:
session['current_guess_idx'] = word_indexes[0]
guess = all_words[word_indexes[0]]
return jsonify({'guess': guess, 'remaining': len(word_indexes), 'history': history})
else:
session['current_guess_idx'] = None
return jsonify({'result': 'Plus aucun mot possible. Terminé.', 'history': history})
return jsonify({'remaining': len(word_indexes), 'history': history})
# Servir index.html à la racine
@ -166,5 +178,4 @@ def root():
def static_files(filename):
return send_from_directory('.', filename)
if __name__ == '__main__':
app.run(debug=True)
## Le serveur est lancé par gunicorn dans Docker, ne rien lancer ici

View file

@ -30,8 +30,7 @@
<button id="skipWordBtn" style="margin-left:1em;">Passer</button>
<div id="result"></div>
<div id="remaining"></div>
<h3>Historique</h3>
<ul id="history"></ul>
<!-- Historique supprimé -->
</div>
</div>
<script>
@ -39,15 +38,7 @@
let history = [];
let remaining = 0;
function updateHistory() {
const histElem = document.getElementById('history');
histElem.innerHTML = '';
history.forEach(item => {
const li = document.createElement('li');
li.textContent = `${item.word} : ${item.score} (restants: ${item.remaining})`;
histElem.appendChild(li);
});
}
// Historique supprimé
function updateRemaining() {
document.getElementById('remaining').textContent = `Mots restants : ${remaining}`;
@ -89,11 +80,19 @@
const resp = await fetch('/next', { method: 'POST' });
const data = await resp.json();
if (data.error) {
document.getElementById('word').textContent = 'Fini !';
document.getElementById('word').textContent = '';
document.getElementById('submitScoreBtn').disabled = true;
document.getElementById('skipWordBtn').disabled = true;
return;
}
if (data.result) {
document.getElementById('word').textContent = '';
document.getElementById('result').textContent = data.result;
document.getElementById('submitScoreBtn').disabled = true;
document.getElementById('skipWordBtn').disabled = true;
updateRemaining();
return;
}
currentWord = data.guess;
remaining = data.remaining;
history = data.history || [];
@ -101,7 +100,6 @@
document.getElementById('scoreInput').value = '';
document.getElementById('result').textContent = '';
document.getElementById('scoreInput').focus();
updateHistory();
updateRemaining();
}
@ -127,7 +125,7 @@
}
history = data.history || history;
remaining = data.remaining || remaining;
updateHistory();
// updateHistory supprimé
updateRemaining();
await nextWord();
};
@ -141,12 +139,17 @@
}
if (data.result) {
document.getElementById('result').textContent = data.result;
}
history = data.history || history;
remaining = data.remaining || remaining;
updateHistory();
updateRemaining();
await nextWord();
} else if (data.guess) {
currentWord = data.guess;
remaining = data.remaining;
history = data.history || history;
document.getElementById('word').textContent = currentWord;
document.getElementById('scoreInput').value = '';
document.getElementById('result').textContent = '';
document.getElementById('scoreInput').focus();
updateRemaining();
}
};
</script>
</body>