Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Add new request that select a random word from the vocabulary
Browse files- api_rest/api.py +11 -1
    	
        api_rest/api.py
    CHANGED
    
    | @@ -1,3 +1,4 @@ | |
|  | |
| 1 | 
             
            from a3c.play import get_play_model_path, play
         | 
| 2 | 
             
            from flask import Flask, request, jsonify
         | 
| 3 | 
             
            from flask_cors import cross_origin
         | 
| @@ -18,7 +19,7 @@ def validate_goal_word(word): | |
| 18 | 
             
            @app.route('/play_word', methods=['GET'])
         | 
| 19 | 
             
            @cross_origin(origin='*', headers=['Content-Type', 'Authorization'])
         | 
| 20 | 
             
            def get_play():
         | 
| 21 | 
            -
                # Get the  | 
| 22 | 
             
                word = request.args.get('goal_word')
         | 
| 23 |  | 
| 24 | 
             
                error, msge = validate_goal_word(word)
         | 
| @@ -33,5 +34,14 @@ def get_play(): | |
| 33 | 
             
                return jsonify({'attempts': attempts, 'won': won})
         | 
| 34 |  | 
| 35 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 36 | 
             
            if __name__ == '__main__':
         | 
| 37 | 
             
                app.run(debug=True)
         | 
|  | |
| 1 | 
            +
            import random
         | 
| 2 | 
             
            from a3c.play import get_play_model_path, play
         | 
| 3 | 
             
            from flask import Flask, request, jsonify
         | 
| 4 | 
             
            from flask_cors import cross_origin
         | 
|  | |
| 19 | 
             
            @app.route('/play_word', methods=['GET'])
         | 
| 20 | 
             
            @cross_origin(origin='*', headers=['Content-Type', 'Authorization'])
         | 
| 21 | 
             
            def get_play():
         | 
| 22 | 
            +
                # Get the goal word from the request
         | 
| 23 | 
             
                word = request.args.get('goal_word')
         | 
| 24 |  | 
| 25 | 
             
                error, msge = validate_goal_word(word)
         | 
|  | |
| 34 | 
             
                return jsonify({'attempts': attempts, 'won': won})
         | 
| 35 |  | 
| 36 |  | 
| 37 | 
            +
            @app.route('/word', methods=['GET'])
         | 
| 38 | 
            +
            @cross_origin(origin='*', headers=['Content-Type', 'Authorization'])
         | 
| 39 | 
            +
            def get_word():
         | 
| 40 | 
            +
                # Get the list of words and list of number strings from the request
         | 
| 41 | 
            +
                word = random.choice(target_vocabulary)
         | 
| 42 | 
            +
                word = word.upper()
         | 
| 43 | 
            +
                return jsonify({'word': word})
         | 
| 44 | 
            +
             | 
| 45 | 
            +
             | 
| 46 | 
             
            if __name__ == '__main__':
         | 
| 47 | 
             
                app.run(debug=True)
         | 
