2021-07-26 18:23:32 +02:00
|
|
|
import flask
|
|
|
|
from flask import Flask, request, jsonify, Response
|
|
|
|
|
2021-07-27 23:10:01 +02:00
|
|
|
from jarvis.ia import process
|
|
|
|
from jarvis.skills import intent_manager
|
2021-07-29 12:35:07 +02:00
|
|
|
from jarvis.skills.entertainement.spotify import SpotifySkill
|
2021-07-26 21:50:14 +02:00
|
|
|
from utils import config_utils, flask_utils, intents_utils, utils
|
2021-07-26 18:23:32 +02:00
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/process", methods=['POST'])
|
|
|
|
def process_request():
|
|
|
|
data = flask_utils.get_data_in_request(request)
|
|
|
|
|
2021-07-26 19:52:20 +02:00
|
|
|
if 'sentence' not in data or not data['sentence']:
|
|
|
|
flask.abort(Response('You must provide a \'sentence\' parameter (not empty aswell)!'))
|
2021-07-26 18:23:32 +02:00
|
|
|
|
2021-07-26 19:52:20 +02:00
|
|
|
sentence = data['sentence']
|
2021-07-27 23:10:01 +02:00
|
|
|
tag_for_request = process.get_tag_for_sentence(sentence)
|
2021-07-26 19:52:20 +02:00
|
|
|
|
|
|
|
print("SENTENCE : " + sentence + " /// TAG : " + tag_for_request)
|
|
|
|
|
2021-07-26 21:50:14 +02:00
|
|
|
# stop here if the sentence isn't understood
|
|
|
|
if tag_for_request == 'dont_understand':
|
|
|
|
return jsonify("I didn't get that.")
|
|
|
|
|
|
|
|
path_of_intent = intents_utils.get_path(tag_for_request)
|
2021-07-27 12:37:09 +02:00
|
|
|
path_of_intent = path_of_intent.split('/skills/')[1].replace('/', '.')
|
|
|
|
path_of_intent = "skills." + path_of_intent + "intent"
|
2021-07-26 21:50:14 +02:00
|
|
|
|
|
|
|
method = utils.import_method_from_string(path_of_intent, tag_for_request)
|
|
|
|
return jsonify(method())
|
2021-07-26 18:23:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-07-27 23:10:01 +02:00
|
|
|
# Tests
|
2021-07-29 12:35:07 +02:00
|
|
|
# WikipediaSkill().register()
|
|
|
|
# JokesSkill().register()
|
|
|
|
SpotifySkill().register()
|
2021-07-28 19:31:47 +02:00
|
|
|
|
|
|
|
intent_manager.process_handlers()
|
|
|
|
|
2021-07-29 12:35:07 +02:00
|
|
|
# intent_manager.recognise("cherche sur wikipedia Elon Musk")
|
|
|
|
# intent_manager.recognise("raconte moi une blague")
|
|
|
|
intent_manager.recognise("joue le morceau crazy crazy nights de KISS sur spotify")
|
2021-07-27 23:10:01 +02:00
|
|
|
|
2021-07-26 18:23:32 +02:00
|
|
|
# start the flask server
|
|
|
|
app.config['JSON_AS_ASCII'] = False
|
2021-07-26 21:50:14 +02:00
|
|
|
app.run(port=config_utils.get_in_config("PORT"), debug=False, host='0.0.0.0', threaded=True)
|