Spaces:
Sleeping
Sleeping
File size: 1,106 Bytes
a202b6d 1c007bb a202b6d 1c007bb a202b6d 1c007bb a202b6d 1c007bb a202b6d 1c007bb a202b6d 1c007bb a202b6d 1c007bb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
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)
|