sdf
parent
7046bb239f
commit
e2073f02cd
|
@ -3,11 +3,11 @@
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="25/12/2024 - 22h30">
|
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="25/12/2024 - 22h30">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Inscription_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/Inscription_mgt.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/GlobalVariable.py" beforeDir="false" afterPath="$PROJECT_DIR$/GlobalVariable.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/attached_file_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/attached_file_mgt.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/attached_file_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/attached_file_mgt.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/ela_user_account.py" beforeDir="false" afterPath="$PROJECT_DIR$/ela_user_account.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/tools_cherif/mysy_openai_file.py" beforeDir="false" afterPath="$PROJECT_DIR$/tools_cherif/mysy_openai_file.py" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
|
|
@ -825,3 +825,9 @@ mysy_voice_instruction_collection_action = {
|
||||||
{"update":"update"} ,
|
{"update":"update"} ,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette variable defini ou les messages vocaux utilisés par le système
|
||||||
|
sont stocké
|
||||||
|
"""
|
||||||
|
SYSTEM_VOICE_MESSAGES_LOCATION = "./admin_voices_messages/"
|
5350
Log/log_file.log
5350
Log/log_file.log
File diff suppressed because it is too large
Load Diff
|
@ -1027,6 +1027,20 @@ def Get_List_object_owner_collection_Stored_Files_With_Filter(diction):
|
||||||
return False, " Le filtre : 'date de fin' n'est pas au format jj/mm/aaaa."
|
return False, " Le filtre : 'date de fin' n'est pas au format jj/mm/aaaa."
|
||||||
|
|
||||||
|
|
||||||
|
# Controle de cohérence des dates
|
||||||
|
if ("date_create_start_date" in diction.keys() and "date_create_end_date" in diction.keys() and
|
||||||
|
datetime.strptime(str(diction['date_create_start_date'])[0:10], '%d/%m/%Y') > datetime.strptime(
|
||||||
|
str(diction['date_create_end_date'])[0:10], '%d/%m/%Y')):
|
||||||
|
mycommon.myprint(
|
||||||
|
str(inspect.stack()[0][
|
||||||
|
3]) + " Filtre de recherche : La date debut " + str(
|
||||||
|
diction['date_create_start_date'])[0:10] +
|
||||||
|
" est postérieure à la date de fin " + str(diction['date_create_end_date'])[0:10])
|
||||||
|
|
||||||
|
return False, " Filtre de recherche : La date debut de début " + str(diction['date_create_start_date'])[0:10] + \
|
||||||
|
" est postérieure à la date de fin " + str(diction['date_create_end_date'])[0:10] + " "
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Gestion du filtre code session.
|
Gestion du filtre code session.
|
||||||
Si ce champs est fourni, voici comment il faut proceder :
|
Si ce champs est fourni, voici comment il faut proceder :
|
||||||
|
|
95
main.py
95
main.py
|
@ -278,6 +278,8 @@ def Get_user_profile():
|
||||||
print(" ### Get_user_profile : payload = ",payload)
|
print(" ### Get_user_profile : payload = ",payload)
|
||||||
status, retval = eua.Get_user_profile(payload)
|
status, retval = eua.Get_user_profile(payload)
|
||||||
return jsonify(status=status, message=retval)
|
return jsonify(status=status, message=retval)
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Cette Api retourne les info d'un user accout identifié par
|
Cette Api retourne les info d'un user accout identifié par
|
||||||
son adresse email.
|
son adresse email.
|
||||||
|
@ -11445,22 +11447,22 @@ API mysy Open AI qui converti un texte en fichier audio (mp3)
|
||||||
def mysy_openai_text_to_voice():
|
def mysy_openai_text_to_voice():
|
||||||
# On recupere le corps (payload) de la requete
|
# On recupere le corps (payload) de la requete
|
||||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||||
print(" ### mysy_openai_voice_to_text payload zzzz = ")
|
print(" ### mysy_openai_text_to_voice payload zzzz = ")
|
||||||
status, retval = mysy_openai_file.mysy_openai_text_to_voice(payload)
|
status, retval = mysy_openai_file.mysy_openai_text_to_voice(payload)
|
||||||
return jsonify(status=status, message=retval)
|
return jsonify(status=status, message=retval)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
API test recuperation fichier blob audio
|
API recuperation fichier blob audio et effectuer la traduction et retourne la demande de confirmation
|
||||||
|
dans un fichier audio.
|
||||||
'''
|
'''
|
||||||
@app.route('/myclass/api/Get_Audio_File/', methods=['POST','GET'])
|
@app.route('/myclass/api/mysy_openai_get_voice_file/', methods=['POST','GET'])
|
||||||
@crossdomain(origin='*')
|
@crossdomain(origin='*')
|
||||||
def Get_Audio_File():
|
def mysy_openai_get_voice_file():
|
||||||
# On recupere le corps (payload) de la requete
|
# On recupere le corps (payload) de la requete
|
||||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||||
print(" ### payload = ",payload)
|
print(" ### payload = ",payload)
|
||||||
print(request.files)
|
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
# Create variable for uploaded file
|
# Create variable for uploaded file
|
||||||
|
@ -11471,12 +11473,76 @@ def Get_Audio_File():
|
||||||
|
|
||||||
new_payload = {}
|
new_payload = {}
|
||||||
new_payload['voice_file'] = "temp_direct/test_audio_pr_IA.mp3"
|
new_payload['voice_file'] = "temp_direct/test_audio_pr_IA.mp3"
|
||||||
status, retval = mysy_openai_file.mysy_openai_voice_to_text(new_payload)
|
status, retval, collection_instruction_id = mysy_openai_file.mysy_openai_voice_to_text(new_payload)
|
||||||
|
|
||||||
|
"""
|
||||||
|
Créer le texte de confirmation.
|
||||||
|
L'idée est de créer un fichier audi de confirmation
|
||||||
|
"""
|
||||||
|
status, audio_file_name = mysy_openai_file.mysy_openai_instruction_collection_confirmation_texte({'_id':str(collection_instruction_id)})
|
||||||
|
|
||||||
|
print(" ### audio_file_name = ", audio_file_name)
|
||||||
|
"""
|
||||||
|
Si le fichier a bien ete recuperé et traduit, alors on revoie un fichier audio de confirmation de l'instruction
|
||||||
|
avant exécution
|
||||||
|
"""
|
||||||
|
if( status ):
|
||||||
|
status, message = mysy_openai_file.mysy_openai_get_voice_file({'audio_file_name':str(audio_file_name)})
|
||||||
|
return jsonify(status=status, message=message, collection_instruction_id=str(collection_instruction_id))
|
||||||
|
|
||||||
|
return jsonify(status=False, message="Impossible de traiter le fichier audio", collection_instruction_id = False)
|
||||||
|
|
||||||
|
|
||||||
status= True
|
|
||||||
|
|
||||||
return jsonify(status=status)
|
'''
|
||||||
|
API recupere la confirmation d'une instruction, effectue les traitement et retoune le resultat sous forme de "succes" ou "ko"
|
||||||
|
dans un fichier vocal.
|
||||||
|
'''
|
||||||
|
@app.route('/myclass/api/mysy_openai_confirme_voice_instruction_api/', methods=['POST','GET'])
|
||||||
|
@crossdomain(origin='*')
|
||||||
|
def mysy_openai_confirme_voice_instruction_api():
|
||||||
|
# On recupere le corps (payload) de la requete
|
||||||
|
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||||
|
print(" ### mysy_openai_confirme_voice_instruction_api payload = ",payload)
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
# Create variable for uploaded file
|
||||||
|
f = request.files['file']
|
||||||
|
|
||||||
|
f.filename = "confirmation_test_audio_pr_IA.mp3"
|
||||||
|
f.save(os.path.join(str("./temp_direct/confirmation_test_audio_pr_IA.mp3")))
|
||||||
|
|
||||||
|
new_payload = {}
|
||||||
|
new_payload['voice_file'] = "temp_direct/confirmation_test_audio_pr_IA.mp3"
|
||||||
|
new_payload['token'] = payload['token']
|
||||||
|
new_payload['instruction_id'] = payload['instruction_id']
|
||||||
|
status, retval = mysy_openai_file.mysy_openai_confirme_voice_instruction(new_payload)
|
||||||
|
|
||||||
|
collection_instruction_id = str(payload['instruction_id'])
|
||||||
|
audio_file_name = retval
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print(" ### audio_file_name = ", retval)
|
||||||
|
print(" ### collection_instruction_id = ", collection_instruction_id)
|
||||||
|
"""
|
||||||
|
Si le fichier a bien ete recuperé et traduit, alors on revoie un fichier audio de confirmation de l'instruction
|
||||||
|
avant exécution
|
||||||
|
"""
|
||||||
|
if( status ):
|
||||||
|
|
||||||
|
new_diction = {}
|
||||||
|
#new_diction['token'] = payload['token']
|
||||||
|
#new_diction['instruction_id'] = str(str(payload['instruction_id']))
|
||||||
|
new_diction['audio_file_name'] = str(audio_file_name)
|
||||||
|
|
||||||
|
print(" ### new_diction = ", new_diction)
|
||||||
|
|
||||||
|
status, message = mysy_openai_file.mysy_openai_get_voice_file(new_diction)
|
||||||
|
return jsonify(status=status, message=message, collection_instruction_id="")
|
||||||
|
|
||||||
|
return jsonify(status=False, message="Impossible de traiter le fichier audio", collection_instruction_id = False)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -11531,16 +11597,19 @@ def mysy_openai_summarize_text():
|
||||||
return jsonify(status=status, message=retval)
|
return jsonify(status=status, message=retval)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
API qui permet d'envoyer le fichier audio créer par l'ia de mysy
|
API qui permet d'envoyer le fichier audio créer par l'ia de mysy vers front.
|
||||||
|
ex : Le message audio "Confirmez-vous la creation de la formation xxxx"
|
||||||
"""
|
"""
|
||||||
@app.route('/myclass/api/send_mysy_openai_to_voice_file/', methods=['POST','GET'])
|
|
||||||
|
@app.route('/myclass/api/mysy_openai_get_voice_file/', methods=['POST','GET'])
|
||||||
@crossdomain(origin='*')
|
@crossdomain(origin='*')
|
||||||
def send_mysy_openai_to_voice_file():
|
def send_mysy_openai_to_voice_file_v2():
|
||||||
# On recupere le corps (payload) de la requete
|
# On recupere le corps (payload) de la requete
|
||||||
payload = mycommon.strip_dictionary(request.form.to_dict())
|
payload = mycommon.strip_dictionary(request.form.to_dict())
|
||||||
payload = {}
|
payload = {}
|
||||||
print(" ### payload Send_mysy_openai_to_voice_file = ", payload)
|
print(" ### payload mysy_openai_get_voice_file_v2 = ", payload)
|
||||||
return mysy_openai_file.send_mysy_openai_to_voice_file(payload)
|
status, message = mysy_openai_file.mysy_openai_get_voice_file(payload)
|
||||||
|
return jsonify(status=status, message=message)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import ast
|
import ast
|
||||||
|
import base64
|
||||||
|
|
||||||
import pymongo
|
import pymongo
|
||||||
import zeep
|
import zeep
|
||||||
|
@ -23,6 +24,8 @@ import email_mgt as email
|
||||||
from validate_email import validate_email
|
from validate_email import validate_email
|
||||||
import jinja2
|
import jinja2
|
||||||
|
|
||||||
|
import class_mgt as class_mgt
|
||||||
|
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
#openai.api_key = MYSY_GV.OPENAI_KEY
|
#openai.api_key = MYSY_GV.OPENAI_KEY
|
||||||
client = OpenAI(
|
client = OpenAI(
|
||||||
|
@ -85,18 +88,95 @@ def mysy_openai(diction):
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Test openai voice to text mysy
|
Cette fonction prends l'_id d'une instruction (collection : voice_instruction)
|
||||||
|
et retourne le texte de confirmation (format text)
|
||||||
|
"""
|
||||||
|
def mysy_openai_instruction_collection_confirmation_texte(diction):
|
||||||
|
try:
|
||||||
|
|
||||||
|
"""
|
||||||
|
Recuperer les elements de l'instruction depuis la collection : voice_instruction
|
||||||
|
la clé est _id fourni en argument à la fonction
|
||||||
|
"""
|
||||||
|
voice_instruction_count = MYSY_GV.dbname['voice_instruction'].count_documents({'_id':ObjectId(diction['_id']),
|
||||||
|
'valide':'1', 'locked':'0'})
|
||||||
|
|
||||||
|
if( voice_instruction_count != 1 ):
|
||||||
|
mycommon.myprint(str(
|
||||||
|
inspect.stack()[0][3]) + " L'identifiant de l'instruction est invalide ")
|
||||||
|
return False, " L'identifiant de l'instruction est invalide"
|
||||||
|
|
||||||
|
voice_instruction_data = MYSY_GV.dbname['voice_instruction'].find_one({'_id': ObjectId(diction['_id']),
|
||||||
|
'valide': '1', 'locked': '0'})
|
||||||
|
|
||||||
|
action_a_realiser = ""
|
||||||
|
if( "related_object" in voice_instruction_data.keys() and voice_instruction_data['related_object'] == "myclass"):
|
||||||
|
# L'instruction concerne les formations
|
||||||
|
action_data = MYSY_GV.mysy_voice_instruction_collection_action['myclass']
|
||||||
|
for val in action_data:
|
||||||
|
for key in val:
|
||||||
|
if( str(key) in voice_instruction_data['instruction'] and action_a_realiser == ""):
|
||||||
|
action_a_realiser = val[key]
|
||||||
|
|
||||||
|
elif ("related_object" in voice_instruction_data.keys() and voice_instruction_data[ 'related_object'] == "session_formation"):
|
||||||
|
# L'instruction concerne les session de formation
|
||||||
|
action_data = MYSY_GV.mysy_voice_instruction_collection_action['session_formation']
|
||||||
|
for val in action_data:
|
||||||
|
for key in val:
|
||||||
|
if (str(key) in voice_instruction_data['instruction'] and action_a_realiser == ""):
|
||||||
|
action_a_realiser = val[key]
|
||||||
|
|
||||||
|
"""
|
||||||
|
Convertion des actions à realiser pour le texte audio
|
||||||
|
"""
|
||||||
|
if( str(action_a_realiser) == "create"):
|
||||||
|
action_a_realiser = " Création "
|
||||||
|
outpufile_name = str(MYSY_GV.SYSTEM_VOICE_MESSAGES_LOCATION)+"mysy_create_class_cherif_voice.mp3"
|
||||||
|
elif( str(action_a_realiser) == "update"):
|
||||||
|
action_a_realiser = " Mise à jour "
|
||||||
|
outpufile_name = str(MYSY_GV.SYSTEM_VOICE_MESSAGES_LOCATION) + "mysy_update_class_cherif_voice.mp3"
|
||||||
|
|
||||||
|
"""
|
||||||
|
Convertion des actions à realiser pour le texte audio
|
||||||
|
"" "
|
||||||
|
type_objet = ""
|
||||||
|
if (str(voice_instruction_data[ 'related_object']) == "myclass"):
|
||||||
|
type_objet = " Une Formation "
|
||||||
|
elif (str(voice_instruction_data[ 'related_object']) == "session_formation"):
|
||||||
|
action_a_realiser = " Une Session de formation "
|
||||||
|
|
||||||
|
|
||||||
|
print(" #### INSTRUCTION SYNTHESE : Object = ", voice_instruction_data[ 'related_object'], " ### ACTION = ", action_a_realiser)
|
||||||
|
|
||||||
|
if(action_a_realiser and type_objet ):
|
||||||
|
text_a_retourner = " Confirmez : l'action de "+str(action_a_realiser)+". Pour "+str(type_objet)
|
||||||
|
else:
|
||||||
|
text_a_retourner = " Instruction inconnue"
|
||||||
|
|
||||||
|
print(" ### text_a_retourner = ", text_a_retourner)
|
||||||
|
|
||||||
|
local_status, outpufile_name = mysy_openai_text_to_voice({'text':str(text_a_retourner)})
|
||||||
|
"""
|
||||||
|
|
||||||
|
return True, outpufile_name
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
||||||
|
return False, " Impossible de traiter : mysy_openai_voice_to_text"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette fonction prend un fichier audio et le converti en fichier texte
|
||||||
"""
|
"""
|
||||||
def mysy_openai_voice_to_text(diction):
|
def mysy_openai_voice_to_text(diction):
|
||||||
try:
|
try:
|
||||||
print(" ### diction = ", diction)
|
|
||||||
file_name = "temp_direct/mysy_test_voice_mp3.mp3"
|
file_name = "temp_direct/mysy_test_voice_mp3.mp3"
|
||||||
if( "voice_file" in diction.keys() and diction['voice_file'] ):
|
if( "voice_file" in diction.keys() and diction['voice_file'] ):
|
||||||
file_name = diction['voice_file']
|
file_name = diction['voice_file']
|
||||||
|
|
||||||
print(" ### Traitement du fichier audio : ", file_name)
|
"""
|
||||||
|
|
||||||
"""
|
|
||||||
audio_file = open(file_name, "rb")
|
audio_file = open(file_name, "rb")
|
||||||
transcription = client.audio.transcriptions.create(
|
transcription = client.audio.transcriptions.create(
|
||||||
model="whisper-1",
|
model="whisper-1",
|
||||||
|
@ -108,16 +188,17 @@ def mysy_openai_voice_to_text(diction):
|
||||||
"""
|
"""
|
||||||
requestion_response = "OK, Missy, crée la formation avec le titre Je vais à la plage, stop. Description, comment aller à la plage, stop."
|
requestion_response = "OK, Missy, crée la formation avec le titre Je vais à la plage, stop. Description, comment aller à la plage, stop."
|
||||||
print(" ### AFFICHAGE GPT RESPONSE - mysy_openai_voice_to_text")
|
print(" ### AFFICHAGE GPT RESPONSE - mysy_openai_voice_to_text")
|
||||||
|
|
||||||
print(requestion_response)
|
print(requestion_response)
|
||||||
|
|
||||||
status, retval = mysy_openai_voice_to_text_traitement_1(requestion_response)
|
status, retval, collection_instruction_id = mysy_openai_voice_to_text_traitement_1(requestion_response)
|
||||||
|
|
||||||
return True,requestion_response
|
return True, requestion_response, collection_instruction_id
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
||||||
return False, " Impossible de traiter : mysy_openai_voice_to_text"
|
return False, " Impossible de traiter : mysy_openai_voice_to_text", False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -167,7 +248,7 @@ def mysy_openai_text_to_voice(diction):
|
||||||
|
|
||||||
response.stream_to_file(out_file_name)
|
response.stream_to_file(out_file_name)
|
||||||
|
|
||||||
return True, "Ok"
|
return True, str(out_file_name)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
|
@ -175,15 +256,19 @@ def mysy_openai_text_to_voice(diction):
|
||||||
return False, " Impossible de traiter : mysy_openai_text_to_voice"
|
return False, " Impossible de traiter : mysy_openai_text_to_voice"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Cette fonction permet d'envoyer un fichier audio sur le front
|
Cette fonction permet d'envoyer un fichier audio sur le front
|
||||||
"""
|
"""
|
||||||
def send_mysy_openai_to_voice_file(diction):
|
|
||||||
|
def mysy_openai_get_voice_file(diction):
|
||||||
try:
|
try:
|
||||||
"""
|
"""
|
||||||
Verification des input acceptés
|
Verification des input acceptés
|
||||||
"""
|
"""
|
||||||
field_list = ['text', ]
|
field_list = ['text', 'audio_file_name']
|
||||||
|
|
||||||
|
RetObject = []
|
||||||
|
|
||||||
incom_keys = diction.keys()
|
incom_keys = diction.keys()
|
||||||
for val in incom_keys:
|
for val in incom_keys:
|
||||||
|
@ -194,10 +279,20 @@ def send_mysy_openai_to_voice_file(diction):
|
||||||
|
|
||||||
out_file_name = "temp_direct/mysy_text_to_voice_89.mp3"
|
out_file_name = "temp_direct/mysy_text_to_voice_89.mp3"
|
||||||
|
|
||||||
if os.path.exists(out_file_name):
|
if( "audio_file_name" in diction.keys() and diction['audio_file_name']):
|
||||||
path = str(out_file_name)
|
out_file_name = diction['audio_file_name']
|
||||||
print("path == ", path)
|
|
||||||
return send_file(path, as_attachment=True)
|
print(" ### mysy_openai_get_voice_file fichier a traiter = ", out_file_name);
|
||||||
|
|
||||||
|
with open(out_file_name, 'rb') as binary_file:
|
||||||
|
binary_file_data = binary_file.read()
|
||||||
|
base64_encoded_data = base64.b64encode(binary_file_data)
|
||||||
|
base64_output = base64_encoded_data.decode('utf-8')
|
||||||
|
|
||||||
|
retval = {}
|
||||||
|
retval['document_mp3'] = base64_output
|
||||||
|
RetObject.append(mycommon.JSONEncoder().encode(retval))
|
||||||
|
return True, RetObject
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
|
@ -205,8 +300,6 @@ def send_mysy_openai_to_voice_file(diction):
|
||||||
return False, " Impossible de traiter : send_mysy_openai_to_voice_file"
|
return False, " Impossible de traiter : send_mysy_openai_to_voice_file"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_mysy_openai_voice_to_text(diction):
|
def test_mysy_openai_voice_to_text(diction):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
@ -257,11 +350,11 @@ def mysy_openai_voice_to_text_traitement_1(voice_text):
|
||||||
new_diction['related_object'] = "myclass"
|
new_diction['related_object'] = "myclass"
|
||||||
new_diction['related_collection_recid'] = "dqsqddd0ed"
|
new_diction['related_collection_recid'] = "dqsqddd0ed"
|
||||||
|
|
||||||
local_status, local_retval_message, local_retval_id = mysy_openai_insert_voice_to_collection(new_diction)
|
local_status, local_retval_message, local_collection_instruction_id = mysy_openai_insert_voice_to_collection(new_diction)
|
||||||
print(" || == > Texte Final = ", voice_text_work, " ## ID message = ", local_retval_id)
|
print(" || == > Texte Final = ", voice_text_work, " ## ID message = ", local_collection_instruction_id)
|
||||||
print("\n")
|
print("\n")
|
||||||
|
|
||||||
return local_status, local_retval_message, local_retval_id
|
return local_status, local_retval_message, local_collection_instruction_id
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -344,7 +437,6 @@ def mysy_openai_insert_voice_to_collection(diction):
|
||||||
voice_text_work = str(diction['text']).strip().lower().replace("[instruction] ", '')
|
voice_text_work = str(diction['text']).strip().lower().replace("[instruction] ", '')
|
||||||
voice_text_work = str(voice_text_work).strip().lower().replace("[instruction], ", '')
|
voice_text_work = str(voice_text_work).strip().lower().replace("[instruction], ", '')
|
||||||
|
|
||||||
|
|
||||||
local_data = {}
|
local_data = {}
|
||||||
local_data['text'] = str(voice_text_work)
|
local_data['text'] = str(voice_text_work)
|
||||||
local_data['related_collection'] = "myclass"
|
local_data['related_collection'] = "myclass"
|
||||||
|
@ -513,3 +605,190 @@ def mysy_openai_assistant(diction):
|
||||||
return False, " Impossible de traiter : mysy_openai_assistant"
|
return False, " Impossible de traiter : mysy_openai_assistant"
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette fonction prend l'_id d'une instruction en cours et effectue le traitement
|
||||||
|
"""
|
||||||
|
def mysy_openai_confirme_voice_instruction(diction):
|
||||||
|
try:
|
||||||
|
|
||||||
|
voice_erreur_text = ""
|
||||||
|
# Dictionnaire des champs utilisables
|
||||||
|
field_list = ['token', 'voice_file', 'instruction_id']
|
||||||
|
incom_keys = diction.keys()
|
||||||
|
for val in incom_keys:
|
||||||
|
if val not in field_list and val.startswith('my_') is False:
|
||||||
|
mycommon.myprint(
|
||||||
|
str(inspect.stack()[0][3]) + " - Le champ '" + val + "' n'existe pas, requete annulée")
|
||||||
|
voice_erreur_text = "Erreur technique 1 : Instruction invalide "
|
||||||
|
#return False, " Impossible de récupérer les informations"
|
||||||
|
|
||||||
|
'''
|
||||||
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
||||||
|
On controle que les champs obligatoires sont presents dans la liste
|
||||||
|
'''
|
||||||
|
field_list_obligatoire = ['token', 'voice_file', 'instruction_id']
|
||||||
|
for val in field_list_obligatoire:
|
||||||
|
if val not in diction:
|
||||||
|
mycommon.myprint(
|
||||||
|
str(inspect.stack()[0][3]) + " - : La valeur '" + val + "' n'est pas presente dans liste ")
|
||||||
|
voice_erreur_text = "Erreur technique 2 : Instruction invalide "
|
||||||
|
#return False, " Impossible de récupérer les informations"
|
||||||
|
|
||||||
|
|
||||||
|
file_name = ""
|
||||||
|
if( "voice_file" in diction.keys() and diction['voice_file'] ):
|
||||||
|
file_name = diction['voice_file']
|
||||||
|
else:
|
||||||
|
mycommon.myprint(
|
||||||
|
str(inspect.stack()[0][3]) + " Aucune instruction à traiter. Processus annulé. ")
|
||||||
|
voice_erreur_text = "Erreur technique 3 : Instruction invalide "
|
||||||
|
return False, " Aucune instruction à traiter. Processus annulé. "
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Verifier la validité de l'instruction_id
|
||||||
|
"""
|
||||||
|
is_valide_instruction_id_count = MYSY_GV.dbname['voice_instruction'].count_documents({'_id':ObjectId(str(diction['instruction_id'])),
|
||||||
|
'valide':'1', 'locked':'0'})
|
||||||
|
|
||||||
|
if( is_valide_instruction_id_count != 1):
|
||||||
|
mycommon.myprint(
|
||||||
|
str(inspect.stack()[0][3]) + " L'identifiant de l'instruction est invalide ")
|
||||||
|
voice_erreur_text = "L'identifiant de l'instruction est invalide "
|
||||||
|
|
||||||
|
|
||||||
|
if( voice_erreur_text and len(str(voice_erreur_text)) > 5):
|
||||||
|
return False, voice_erreur_text
|
||||||
|
|
||||||
|
|
||||||
|
audio_file = open(file_name, "rb")
|
||||||
|
transcription = client.audio.transcriptions.create(
|
||||||
|
model="whisper-1",
|
||||||
|
file=audio_file,
|
||||||
|
#response_format = "text"
|
||||||
|
)
|
||||||
|
|
||||||
|
requestion_response = transcription.text
|
||||||
|
"""
|
||||||
|
requestion_response = "OK, Missy, crée la formation avec le titre Je vais à la plage, stop. Description, comment aller à la plage, stop."
|
||||||
|
print(" ### AFFICHAGE GPT RESPONSE - mysy_openai_voice_to_text")
|
||||||
|
"""
|
||||||
|
print(" ### mysy_openai_confirme_voice_instruction = ", requestion_response)
|
||||||
|
|
||||||
|
new_diction = {}
|
||||||
|
new_diction['token'] = diction['token']
|
||||||
|
new_diction['instruction_id'] = diction['instruction_id']
|
||||||
|
|
||||||
|
print(" GRRR new_diction = ", new_diction)
|
||||||
|
|
||||||
|
local_status, local_retval = voice_instruction_make_instruction(new_diction)
|
||||||
|
if( local_status is False ):
|
||||||
|
after_intruction_text = " Erreur - " + str(local_retval)
|
||||||
|
else:
|
||||||
|
after_intruction_text = " L'opération a été réalisée avec succès "
|
||||||
|
|
||||||
|
print(" ### mysy_openai_confirme_voice_instruction text_a_retourner = ", after_intruction_text)
|
||||||
|
|
||||||
|
local_status, outpufile_name = mysy_openai_text_to_voice({'text': str(after_intruction_text)})
|
||||||
|
|
||||||
|
print(" le fichier audio de confirmation est : ", outpufile_name)
|
||||||
|
|
||||||
|
|
||||||
|
return True, outpufile_name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
||||||
|
return False, " Impossible de traiter : mysy_openai_voice_to_text"
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette fonction prends une voice_instruction_id, puis effectue l'operation concernée
|
||||||
|
"""
|
||||||
|
def voice_instruction_make_instruction(diction):
|
||||||
|
try:
|
||||||
|
diction = mycommon.strip_dictionary(diction)
|
||||||
|
|
||||||
|
print(" voice_instruction_make_instruction diction == ", diction)
|
||||||
|
"""
|
||||||
|
Verification des input acceptés
|
||||||
|
"""
|
||||||
|
field_list = ['token', 'instruction_id', ]
|
||||||
|
|
||||||
|
incom_keys = diction.keys()
|
||||||
|
for val in incom_keys:
|
||||||
|
if val not in field_list and val.startswith('my_') is False:
|
||||||
|
mycommon.myprint(str(
|
||||||
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||||
|
return False, " Les informations fournies sont incorrectes"
|
||||||
|
|
||||||
|
"""
|
||||||
|
Verification des champs obligatoires
|
||||||
|
"""
|
||||||
|
field_list_obligatoire = ['token', 'instruction_id', ]
|
||||||
|
|
||||||
|
for val in field_list_obligatoire:
|
||||||
|
if val not in diction:
|
||||||
|
mycommon.myprint(
|
||||||
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||||
|
return False, " Les informations fournies sont incorrectes"
|
||||||
|
|
||||||
|
"""
|
||||||
|
Verification de l'identité et autorisation de l'entité qui
|
||||||
|
appelle cette API
|
||||||
|
"""
|
||||||
|
token = ""
|
||||||
|
if ("token" in diction.keys()):
|
||||||
|
if diction['token']:
|
||||||
|
token = diction['token']
|
||||||
|
|
||||||
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||||
|
if (local_status is not True):
|
||||||
|
return local_status, my_partner
|
||||||
|
|
||||||
|
"""
|
||||||
|
Verifier la validité de l'instruction_id
|
||||||
|
"""
|
||||||
|
is_valide_instruction_id_count = MYSY_GV.dbname['voice_instruction'].count_documents(
|
||||||
|
{'_id': ObjectId(str(diction['instruction_id'])),
|
||||||
|
'valide': '1', 'locked': '0'})
|
||||||
|
|
||||||
|
if (is_valide_instruction_id_count != 1):
|
||||||
|
mycommon.myprint(
|
||||||
|
str(inspect.stack()[0][3]) + " L'identifiant de l'instruction est invalide ")
|
||||||
|
voice_erreur_text = "L'identifiant de l'instruction est invalide "
|
||||||
|
|
||||||
|
instruction_id_data = MYSY_GV.dbname['voice_instruction'].find_one(
|
||||||
|
{'_id': ObjectId(str(diction['instruction_id'])),
|
||||||
|
'valide': '1', 'locked': '0'})
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Traitement pour les formations
|
||||||
|
"""
|
||||||
|
if( instruction_id_data['related_object'] == "myclass"):
|
||||||
|
new_class_data = {}
|
||||||
|
for mydata in instruction_id_data['data']:
|
||||||
|
new_class_data[str(mydata['field']).strip().lower()] = mydata['value']
|
||||||
|
|
||||||
|
"""
|
||||||
|
Normalisation de certains clés. par exemple 'titre' devient 'title' ==> a faire
|
||||||
|
"""
|
||||||
|
|
||||||
|
print(" ### new_class_data = ", new_class_data)
|
||||||
|
if( instruction_id_data['action'] == "create"):
|
||||||
|
local_status, local_retval = class_mgt.add_class(new_class_data)
|
||||||
|
|
||||||
|
if (local_status is False):
|
||||||
|
return local_status, local_retval
|
||||||
|
|
||||||
|
|
||||||
|
return True, " OK "
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||||
|
return False, " Impossible de réaliser : 'voice_instruction_make_instruction' "
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue