from a3c.play import get_play_model_path, play from flask import Flask, request, jsonify from flask_cors import cross_origin from wordle_env.words import target_vocabulary from wordle_env.wordle import get_env app = Flask(__name__) def validate_goal_word(word): if not word: return True, 'Goal word not provided' if word.upper() not in target_vocabulary: return True, 'Goal word not in vocabulary' return False, '' @app.route('/play_word', methods=['GET']) @cross_origin(origin='*', headers=['Content-Type', 'Authorization']) def get_play(): # Get the list of words and list of number strings from the request word = request.args.get('goal_word') error, msge = validate_goal_word(word) if error: return jsonify({'error': msge}), 400 word = word.upper() env = get_env() model_path = get_play_model_path() # Call the suggest function with the input lists and return the result won, attempts = play(env, model_path, word) return jsonify({'attempts': attempts, 'won': won}) if __name__ == '__main__': app.run(debug=True)