2021-07-26 18:23:32 +02:00
|
|
|
import flask
|
2021-07-29 23:03:01 +02:00
|
|
|
import lingua_franca
|
2021-07-26 18:23:32 +02:00
|
|
|
from flask import Flask, request, jsonify, Response
|
|
|
|
|
2021-07-27 23:10:01 +02:00
|
|
|
from jarvis.skills import intent_manager
|
2021-07-30 12:54:25 +02:00
|
|
|
from jarvis.skills.entertainement.jokes import JokesSkill
|
2021-07-29 12:35:07 +02:00
|
|
|
from jarvis.skills.entertainement.spotify import SpotifySkill
|
2021-07-30 12:54:25 +02:00
|
|
|
from jarvis.skills.research.wikipedia import WikipediaSkill
|
2021-07-29 23:03:01 +02:00
|
|
|
from jarvis.utils import languages_utils
|
2021-07-30 14:10:35 +02:00
|
|
|
from utils import config_utils, flask_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-30 14:10:35 +02:00
|
|
|
return jsonify(intent_manager.recognise(sentence=data['sentence']))
|
2021-07-26 18:23:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-07-29 23:03:01 +02:00
|
|
|
# Load lingua franca in the memory
|
|
|
|
# Supported : English French German Hungarian Italian Portuguese Swedish
|
2021-07-30 21:12:13 +02:00
|
|
|
lingua_franca.load_language(lang=languages_utils.get_language_only_country())
|
2021-07-29 23:03:01 +02:00
|
|
|
|
2021-07-27 23:10:01 +02:00
|
|
|
# Tests
|
2021-07-30 12:54:25 +02:00
|
|
|
WikipediaSkill().register()
|
|
|
|
JokesSkill().register()
|
2021-07-29 12:35:07 +02:00
|
|
|
SpotifySkill().register()
|
2021-07-28 19:31:47 +02:00
|
|
|
|
2021-07-30 14:10:35 +02:00
|
|
|
intent_manager.load_all_skills()
|
2021-07-28 19:31:47 +02:00
|
|
|
|
2021-07-31 11:18:16 +02:00
|
|
|
# intent_manager.recognise("cherche Elon Musk sur wikipédia") # WORKING
|
2021-07-29 23:29:53 +02:00
|
|
|
# intent_manager.recognise("raconte moi une blague") # WORKING
|
|
|
|
# intent_manager.recognise("joue le morceau crazy crazy nights de KISS sur spotify") # WORKING
|
|
|
|
# intent_manager.recognise("coupe la musique") # WORKING
|
2021-07-30 12:54:25 +02:00
|
|
|
# intent_manager.recognise("c'est quoi le nom de cette chanson ?") # WORKING
|
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)
|