Spaces:
Paused
Paused
rick
commited on
update patch
Browse files- app.py +89 -2
- ui_lang_support.json +9 -1
app.py
CHANGED
|
@@ -175,8 +175,8 @@ def transcribe_audio(audio_file: IO, language: Optional[str] = None) -> str:
|
|
| 175 |
except IOError as e:
|
| 176 |
st.error(f"Erreur d'entrée/sortie lors de la transcription : {e}")
|
| 177 |
return ""
|
| 178 |
-
except
|
| 179 |
-
st.error(f"Erreur
|
| 180 |
return ""
|
| 181 |
|
| 182 |
# Fonction pour détecter la langue d'un texte donné
|
|
@@ -659,6 +659,93 @@ def main():
|
|
| 659 |
|
| 660 |
|
| 661 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 662 |
# Configuration de la barre latérale
|
| 663 |
with st.sidebar:
|
| 664 |
st.logo("img/logo_2.png", icon_image="img/logo_2.png")
|
|
|
|
| 175 |
except IOError as e:
|
| 176 |
st.error(f"Erreur d'entrée/sortie lors de la transcription : {e}")
|
| 177 |
return ""
|
| 178 |
+
except Exception as e:
|
| 179 |
+
st.error(f"Erreur lors de la transcription : {e}")
|
| 180 |
return ""
|
| 181 |
|
| 182 |
# Fonction pour détecter la langue d'un texte donné
|
|
|
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
+
with st.container(border=True):
|
| 663 |
+
# Interface utilisateur pour l'enregistrement audio
|
| 664 |
+
st.write(f"🗣️ {get_translation('enregistrez_message')}")
|
| 665 |
+
if audio := audiorecorder(
|
| 666 |
+
start_prompt=get_translation("cliquez_enregistrer"),
|
| 667 |
+
stop_prompt=get_translation("cliquez_arreter"),
|
| 668 |
+
pause_prompt=get_translation("cliquez_pause"),
|
| 669 |
+
show_visualizer=True,
|
| 670 |
+
key="vocal_chat_input"
|
| 671 |
+
):
|
| 672 |
+
# Traitement de l'entrée audio de l'utilisateur
|
| 673 |
+
if len(audio) > 0:
|
| 674 |
+
#with st.status(get_translation("transcription_audio_en_cours"), expanded=False) as stt_status:
|
| 675 |
+
#try:
|
| 676 |
+
#stt_status.update(label=get_translation("transcription_audio_en_cours"), state="running", expanded=True)
|
| 677 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_audio:
|
| 678 |
+
audio.export(temp_audio.name, format="wav")
|
| 679 |
+
st.write(f"Frame rate: {audio.frame_rate}, Frame width: {audio.frame_width}, Duration: {audio.duration_seconds} seconds")
|
| 680 |
+
|
| 681 |
+
|
| 682 |
+
# Transcrire l'audio en texte
|
| 683 |
+
transcription = transcribe_audio(temp_audio, language=st.session_state.language_detected)
|
| 684 |
+
# Detecter la langue du texte transcrit (si la langue source n'est pas détectée)
|
| 685 |
+
if st.session_state.language_detected is None:
|
| 686 |
+
st.session_state.language_detected = detect_language(
|
| 687 |
+
input_text=transcription, temperature=0.01
|
| 688 |
+
)
|
| 689 |
+
st.markdown(f"- {get_translation('langue_detectee')} : {convert_iso6391_to_language_name(st.session_state.language_detected)}")
|
| 690 |
+
|
| 691 |
+
st.markdown(f"🎤 {get_translation('transcription_audio')} : {transcription}")
|
| 692 |
+
|
| 693 |
+
|
| 694 |
+
audio_list = []
|
| 695 |
+
for cursor_selected_lang in st.session_state.selected_languages:
|
| 696 |
+
st.session_state.target_language = cursor_selected_lang["iso-639-1"]
|
| 697 |
+
st.session_state.full_response = ""
|
| 698 |
+
# Initialisation du mode de traitement pour la langue cible actuelle
|
| 699 |
+
system_prompt, operation_prompt = init_process_mode()
|
| 700 |
+
with st.chat_message("assistant", avatar="👻"):
|
| 701 |
+
message_placeholder = st.empty()
|
| 702 |
+
response_generator = process_message(
|
| 703 |
+
transcription, operation_prompt, st.session_state.enable_tts_for_input_from_audio_record
|
| 704 |
+
)
|
| 705 |
+
for response_chunk in response_generator:
|
| 706 |
+
message_placeholder.markdown(response_chunk)
|
| 707 |
+
full_response = response_generator.close()
|
| 708 |
+
if st.session_state.full_response != "":
|
| 709 |
+
message_placeholder.markdown(st.session_state.full_response)
|
| 710 |
+
|
| 711 |
+
if st.session_state.enable_tts_for_input_from_audio_record:
|
| 712 |
+
tts_audio, tts_duration = process_tts_message(st.session_state.full_response)
|
| 713 |
+
if tts_audio:
|
| 714 |
+
audio_list.append((tts_audio, tts_duration))
|
| 715 |
+
else:
|
| 716 |
+
pass
|
| 717 |
+
|
| 718 |
+
if audio_list:
|
| 719 |
+
#stt_status.update(label=f"{get_translation('concatenation_audio_en_cours')}", state="running", expanded=True)
|
| 720 |
+
final_audio = concatenate_audio_files(audio_list)
|
| 721 |
+
with st.container(border=True):
|
| 722 |
+
|
| 723 |
+
# Générer un nom de fichier unique
|
| 724 |
+
timestamp = time.strftime("%Y%m%d-%H%M%S")
|
| 725 |
+
langues = "_".join([lang["iso-639-1"] for lang in st.session_state.selected_languages])
|
| 726 |
+
nom_fichier = f"reponse_audio_{langues}_{timestamp}.mp3"
|
| 727 |
+
|
| 728 |
+
st.audio(final_audio, format="audio/mp3", autoplay=st.session_state.autoplay_tts)
|
| 729 |
+
|
| 730 |
+
st.download_button(
|
| 731 |
+
label=f"📥 {get_translation('telecharger_audio')}",
|
| 732 |
+
data=final_audio,
|
| 733 |
+
file_name=nom_fichier,
|
| 734 |
+
mime="audio/mp3",
|
| 735 |
+
use_container_width=True,
|
| 736 |
+
type="primary",
|
| 737 |
+
key=f"download_button_{langues}_{timestamp}",
|
| 738 |
+
)
|
| 739 |
+
|
| 740 |
+
#stt_status.update(label=f"{get_translation('concatenation_audio_terminee')}", state="complete", expanded=True)
|
| 741 |
+
#else:
|
| 742 |
+
#stt_status.update(label=f"{get_translation('erreur_concatenation_audio')}", state="error", expanded=True)
|
| 743 |
+
#except Exception as e:
|
| 744 |
+
# st.error(f"{get_translation('erreur_transcription_audio')} : {str(e)}")
|
| 745 |
+
# stt_status.update(label=f"{get_translation('erreur_transcription_audio')} : {str(e)}", state="error", expanded=True)
|
| 746 |
+
|
| 747 |
+
|
| 748 |
+
|
| 749 |
# Configuration de la barre latérale
|
| 750 |
with st.sidebar:
|
| 751 |
st.logo("img/logo_2.png", icon_image="img/logo_2.png")
|
ui_lang_support.json
CHANGED
|
@@ -44,7 +44,15 @@
|
|
| 44 |
"synthese_vocale_terminee": "Synthèse vocale terminée !",
|
| 45 |
"concatenation_audio_en_cours": "Concaténation audio en cours...",
|
| 46 |
"erreur_concatenation_audio": "Une erreur s'est produite lors de la concaténation audio : {}",
|
| 47 |
-
"concatenation_audio_terminee": "Concaténation audio terminée !"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
},
|
| 49 |
"Afrikaans": {
|
| 50 |
"titre": "DEMORRHA APP - weergawe 1",
|
|
|
|
| 44 |
"synthese_vocale_terminee": "Synthèse vocale terminée !",
|
| 45 |
"concatenation_audio_en_cours": "Concaténation audio en cours...",
|
| 46 |
"erreur_concatenation_audio": "Une erreur s'est produite lors de la concaténation audio : {}",
|
| 47 |
+
"concatenation_audio_terminee": "Concaténation audio terminée !",
|
| 48 |
+
"transcription_audio_en_cours": "Transcription audio en cours...",
|
| 49 |
+
"erreur_transcription_audio": "Une erreur s'est produite lors de la transcription audio : {}",
|
| 50 |
+
"transcription_audio_terminee": "Transcription audio terminée !",
|
| 51 |
+
"detection_langue_en_cours": "Détection de la langue en cours...",
|
| 52 |
+
"erreur_detection_langue": "Une erreur s'est produite lors de la détection de la langue : {}",
|
| 53 |
+
"detection_langue_terminee": "Détection de la langue terminée !",
|
| 54 |
+
"langue_detectee": "Langue détectée : {}",
|
| 55 |
+
"transcription_audio": "Transcription audio : {}"
|
| 56 |
},
|
| 57 |
"Afrikaans": {
|
| 58 |
"titre": "DEMORRHA APP - weergawe 1",
|