Spaces:
Sleeping
Sleeping
File size: 1,364 Bytes
7d9d14f 8504cf9 7d9d14f 8504cf9 7d9d14f |
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 39 40 41 42 43 44 45 46 47 48 |
from flask import Flask, jsonify, request
from gameload import upload_game_docs
import chat
import os
import dotenv
import os
app = Flask(__name__)
dotenv.load_dotenv('.env')
host = os.getenv('HOST')
port = os.getenv('PORT')
@app.route('/initialize_game', methods=['GET'])
def initialize_game():
inputs = request.args.to_dict()
user_id = inputs['user_id']
game_id = inputs['game_id']
result = chat.initialize_game(user_id, game_id)
response = {'role': 'assistant', 'content': result}
return jsonify(response)
@app.route('/start_game', methods=['GET'])
def start_game():
inputs = request.args.to_dict()
user_id = inputs['user_id']
game_id = inputs['game_id']
user_input = inputs['user_input']
gpt_output = chat.start_game(game_id, user_id, user_input)
response = {'role': 'assistant', 'content': gpt_output}
return jsonify(response)
@app.route('/health_check', methods=['GET'])
def health_check():
response = {'message': 'Site is healthy'}
return jsonify(response)
@app.route('/load_game', methods=['GET'])
def load_game():
upload_game_docs()
response = {'message': 'Game loaded'}
return jsonify(response)
if __name__ == '__main__':
host = '0.0.0.0' # Replace with your desired host IP
port = 8080 # Replace with your desired port number
app.run(host=host, port=port)
|