diff --git a/Dockerfile b/Dockerfile index 8c59992..10a1548 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/cemantle_api.py b/cemantle_api.py index 4786b00..8392fad 100644 --- a/cemantle_api.py +++ b/cemantle_api.py @@ -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}) - 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({'remaining': len(new_word_indexes), '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, '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 diff --git a/index.html b/index.html index b9a0efb..e4bf99d 100644 --- a/index.html +++ b/index.html @@ -30,8 +30,7 @@
-

Historique

- +