diff --git a/ia/trained_model.pth b/ia/trained_model.pth index cfb30aa..5b2780b 100644 Binary files a/ia/trained_model.pth and b/ia/trained_model.pth differ diff --git a/intents/entertainement/__init__.py b/intents/entertainement/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/intents/entertainement/jokes/__init__.py b/intents/entertainement/jokes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/intents/entertainement/jokes/info.json b/intents/entertainement/jokes/info.json new file mode 100644 index 0000000..a55b85f --- /dev/null +++ b/intents/entertainement/jokes/info.json @@ -0,0 +1,10 @@ +{ + "name": "Jokes", + "languages": [ + "FR-FR", + "EN-EN" + ], + "intents": [ + "tell_me_a_joke" + ] +} \ No newline at end of file diff --git a/intents/entertainement/jokes/intent.py b/intents/entertainement/jokes/intent.py new file mode 100644 index 0000000..e54a015 --- /dev/null +++ b/intents/entertainement/jokes/intent.py @@ -0,0 +1,36 @@ +import requests as requests + +from utils import config_utils + + +def tell_me_a_joke(): + tag = 'tell_me_a_joke' + # response = intents_utils.get_response(tag) + + # french jokes + if config_utils.get_in_config("LANGUAGE").startswith("fr-"): + # the token used might be revoked at any time, please register on www.blagues-api.fr and replace it + response = requests.get( + 'https://www.blagues-api.fr/api/random', + headers={ + 'Authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNzA4OTcyNzQwOTQ5ODM1ODI2IiwibGltaXQiOjEwMCwia2V5IjoiYmZlUVBSb2xuY2FleHBHc2taRU90VkdKOGxhdWZsZVRSMFJadnR3QXV3c056djdpYlkiLCJjcmVhdGVkX2F0IjoiMjAyMS0wNS0yOVQxNDoyMjo0MCswMDowMCIsImlhdCI6MTYyMjI5ODE2MH0.6VxH_dTdJSddhHoYOtdQl0j9WC3lzXjUujUio5U09Jg' + } + ) + + data = response.json() + joke = data['joke'] + answer = data['answer'] + + return joke + " /pause:2s/ " + answer + + # english jokes + elif config_utils.get_in_config("LANGUAGE").startswith("en-"): + response = requests.get('https://v2.jokeapi.dev/joke/Any?type=twopart') + data = response.json() + + joke = data['setup'] + answer = data['delivery'] + + return joke + " /pause:2s/ " + answer + else: + return "I don't know any jokes in your language..." diff --git a/intents/entertainement/jokes/lang/en-en.json b/intents/entertainement/jokes/lang/en-en.json new file mode 100644 index 0000000..16520c2 --- /dev/null +++ b/intents/entertainement/jokes/lang/en-en.json @@ -0,0 +1,11 @@ +{ + "tell_me_a_joke": { + "patterns": [ + "Tell me a joke", + "Make me laugh", + "Brighten my day" + ], + "responses": [ + ] + } +} \ No newline at end of file diff --git a/intents/entertainement/jokes/lang/fr-fr.json b/intents/entertainement/jokes/lang/fr-fr.json new file mode 100644 index 0000000..a4aec2e --- /dev/null +++ b/intents/entertainement/jokes/lang/fr-fr.json @@ -0,0 +1,14 @@ +{ + "tell_me_a_joke": { + "patterns": [ + "raconte moi-voir une blague", + "dis moi une blague", + "raconte une blague", + "fait moi rire", + "donne une bonne blague", + "raconte moi une blagounette" + ], + "responses": [ + ] + } +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 878d0a3..4096be3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ flask~=2.0.1 Unidecode~=1.2.0 nltk~=3.6.2 torch~=1.9.0 -numpy~=1.21.1 \ No newline at end of file +numpy~=1.21.1 +requests~=2.26.0 \ No newline at end of file diff --git a/utils/client_utils.py b/utils/client_utils.py new file mode 100644 index 0000000..2c89998 --- /dev/null +++ b/utils/client_utils.py @@ -0,0 +1,61 @@ +import json + +import requests +from requests.structures import CaseInsensitiveDict + +from utils import config_utils + +client_url = config_utils.get_in_config("CLIENT_URL") + + +def ask_for_microphone_output(record_for_seconds, speech_before_input): + data = { + 'record_for_seconds': record_for_seconds, + 'speech_before_input': speech_before_input + } + + call_client_api("POST", "/record", json.dumps(data)) + + +def ask_for_input(listen_for_seconds, speech_before_input): + data = { + 'listen_for_seconds': listen_for_seconds, + 'speech_before_input': speech_before_input + } + + call_client_api("POST", "/input", json.dumps(data)) + + +def speak(speech): + data = { + 'speech': speech + } + call_client_api("POST", "/speak", data) + + +def sound(sound_name): + data = { + 'sound_name': sound_name + } + call_client_api("POST", "/sound", data) + + +def call_client_api(method, url, json_data=None): + if json_data is None: + json_data = {} + + try: + url_service = client_url + url + + headers = CaseInsensitiveDict() + headers["Authorization"] = config_utils.get_in_config("API_KEY") + headers["Content-Type"] = "application/json; charset=utf8" + + if method == 'GET': + return json.loads(requests.get(url_service, headers=headers).content.decode("utf-8")) + elif method == 'POST': + json_data = json.dumps(json_data) + return json.loads( + requests.post(url_service, headers=headers, data=json_data.encode("utf8")).content.decode("utf-8")) + except: + print("Error when calling the client API")