Spaces:
Paused
Paused
rick
commited on
update UI/UX...
Browse files
app.py
CHANGED
|
@@ -23,11 +23,11 @@ from openai import OpenAI
|
|
| 23 |
from pydub import AudioSegment
|
| 24 |
|
| 25 |
|
| 26 |
-
__version__ = "
|
| 27 |
|
| 28 |
# Au début du fichier, après les imports
|
| 29 |
st.set_page_config(
|
| 30 |
-
page_title=f"DEMORRHA - ({__version__})",
|
| 31 |
page_icon="👹",
|
| 32 |
layout="wide",
|
| 33 |
initial_sidebar_state="collapsed"
|
|
@@ -507,7 +507,6 @@ def init_process_mode() -> Tuple[str, str]:
|
|
| 507 |
# Fonction principale de l'application
|
| 508 |
def main():
|
| 509 |
"""Fonction principale qui configure et exécute l'application Streamlit."""
|
| 510 |
-
st.title("------- DEMORRHA -------")
|
| 511 |
|
| 512 |
# Initialisation des variables d'état de session
|
| 513 |
if "ui_loaded" not in st.session_state:
|
|
@@ -599,66 +598,65 @@ def main():
|
|
| 599 |
except Exception as e:
|
| 600 |
st.error(f"Erreur lors de la concaténation des fichiers audio : {str(e)}")
|
| 601 |
|
| 602 |
-
with st.container():
|
| 603 |
# Interface utilisateur pour l'enregistrement audio
|
| 604 |
-
st.write(get_translation(
|
| 605 |
-
audio
|
| 606 |
start_prompt=get_translation("cliquez_enregistrer"),
|
| 607 |
stop_prompt=get_translation("cliquez_arreter"),
|
| 608 |
pause_prompt=get_translation("cliquez_pause"),
|
| 609 |
show_visualizer=True,
|
| 610 |
key="vocal_chat_input"
|
| 611 |
-
)
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
if len(audio) > 0:
|
| 615 |
-
try:
|
| 616 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_audio:
|
| 617 |
-
audio.export(temp_audio.name, format="wav")
|
| 618 |
-
transcription = transcribe_audio(temp_audio, language=st.session_state.language_detected)
|
| 619 |
-
os.unlink(temp_audio.name) # Suppression du fichier temporaire
|
| 620 |
-
if st.session_state.language_detected is None:
|
| 621 |
-
st.session_state.language_detected = detect_language(
|
| 622 |
-
input_text=transcription, temperature=0.01
|
| 623 |
-
)
|
| 624 |
-
st.write(get_translation("langue_detectee").format(st.session_state.language_detected))
|
| 625 |
-
|
| 626 |
-
#st.write(get_translation("transcription").format(transcription))
|
| 627 |
-
|
| 628 |
-
audio_list = []
|
| 629 |
-
for cursor_selected_lang in st.session_state.selected_languages:
|
| 630 |
-
st.session_state.target_language = cursor_selected_lang["iso-639-1"]
|
| 631 |
-
|
| 632 |
-
# Initialisation du mode de traitement pour la langue cible actuelle
|
| 633 |
-
system_prompt, operation_prompt = init_process_mode()
|
| 634 |
-
|
| 635 |
-
# Traitement du message utilisateur pour la langue cible actuelle
|
| 636 |
try:
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
except Exception as e:
|
| 645 |
-
st.error(f"Erreur lors du traitement du message audio : {str(e)}")
|
| 646 |
-
if audio_list:
|
| 647 |
-
try:
|
| 648 |
-
final_audio = concatenate_audio_files(audio_list)
|
| 649 |
-
with st.container(border=True):
|
| 650 |
-
st.audio(final_audio, format="audio/mp3", autoplay=True)
|
| 651 |
-
# Ajout d'un bouton de téléchargement pour l'audio final
|
| 652 |
-
st.download_button(
|
| 653 |
-
label=f"📥 {get_translation('telecharger_audio')}",
|
| 654 |
-
data=final_audio,
|
| 655 |
-
file_name="audio_concatene.mp3",
|
| 656 |
-
mime="audio/mp3"
|
| 657 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 658 |
except Exception as e:
|
| 659 |
-
st.error(f"Erreur lors
|
| 660 |
-
except Exception as e:
|
| 661 |
-
st.error(f"Erreur lors du traitement de l'audio : {str(e)}")
|
| 662 |
|
| 663 |
# Configuration de la barre latérale
|
| 664 |
with st.sidebar:
|
|
@@ -666,6 +664,7 @@ def main():
|
|
| 666 |
st.header(get_translation("sidebar_titre"))
|
| 667 |
|
| 668 |
with st.expander(f"{get_translation('a_propos')}", expanded=False, icon="ℹ️"):
|
|
|
|
| 669 |
st.info(get_translation("info_app"))
|
| 670 |
|
| 671 |
with st.container(border=True):
|
|
@@ -682,9 +681,8 @@ def main():
|
|
| 682 |
)
|
| 683 |
)
|
| 684 |
|
| 685 |
-
with st.
|
| 686 |
# Conteneur pour la sélection de langue
|
| 687 |
-
st.markdown(f"## 🌐 {get_translation('selection_langue')}")
|
| 688 |
|
| 689 |
# Sélection multiple des langues de destination
|
| 690 |
st.multiselect(
|
|
@@ -697,8 +695,7 @@ def main():
|
|
| 697 |
on_change=on_languages_change
|
| 698 |
)
|
| 699 |
|
| 700 |
-
with st.
|
| 701 |
-
st.markdown(f"## 🔊 {get_translation('parametres_tts')}")
|
| 702 |
st.selectbox(
|
| 703 |
get_translation("choix_voix_tts"),
|
| 704 |
options=["alloy", "echo", "fable", "onyx", "nova", "shimmer"],
|
|
|
|
| 23 |
from pydub import AudioSegment
|
| 24 |
|
| 25 |
|
| 26 |
+
__version__ = "1.1.2"
|
| 27 |
|
| 28 |
# Au début du fichier, après les imports
|
| 29 |
st.set_page_config(
|
| 30 |
+
page_title=f"DEMORRHA - (v{__version__})",
|
| 31 |
page_icon="👹",
|
| 32 |
layout="wide",
|
| 33 |
initial_sidebar_state="collapsed"
|
|
|
|
| 507 |
# Fonction principale de l'application
|
| 508 |
def main():
|
| 509 |
"""Fonction principale qui configure et exécute l'application Streamlit."""
|
|
|
|
| 510 |
|
| 511 |
# Initialisation des variables d'état de session
|
| 512 |
if "ui_loaded" not in st.session_state:
|
|
|
|
| 598 |
except Exception as e:
|
| 599 |
st.error(f"Erreur lors de la concaténation des fichiers audio : {str(e)}")
|
| 600 |
|
| 601 |
+
with st.container(border=True):
|
| 602 |
# Interface utilisateur pour l'enregistrement audio
|
| 603 |
+
st.write(f"🗣️ {get_translation('enregistrez_message')}")
|
| 604 |
+
if audio := audiorecorder(
|
| 605 |
start_prompt=get_translation("cliquez_enregistrer"),
|
| 606 |
stop_prompt=get_translation("cliquez_arreter"),
|
| 607 |
pause_prompt=get_translation("cliquez_pause"),
|
| 608 |
show_visualizer=True,
|
| 609 |
key="vocal_chat_input"
|
| 610 |
+
):
|
| 611 |
+
# Traitement de l'entrée audio de l'utilisateur
|
| 612 |
+
if len(audio) > 0:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 613 |
try:
|
| 614 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_audio:
|
| 615 |
+
audio.export(temp_audio.name, format="wav")
|
| 616 |
+
transcription = transcribe_audio(temp_audio, language=st.session_state.language_detected)
|
| 617 |
+
os.unlink(temp_audio.name) # Suppression du fichier temporaire
|
| 618 |
+
if st.session_state.language_detected is None:
|
| 619 |
+
st.session_state.language_detected = detect_language(
|
| 620 |
+
input_text=transcription, temperature=0.01
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 621 |
)
|
| 622 |
+
st.write(get_translation("langue_detectee").format(st.session_state.language_detected))
|
| 623 |
+
|
| 624 |
+
#st.write(get_translation("transcription").format(transcription))
|
| 625 |
+
|
| 626 |
+
audio_list = []
|
| 627 |
+
for cursor_selected_lang in st.session_state.selected_languages:
|
| 628 |
+
st.session_state.target_language = cursor_selected_lang["iso-639-1"]
|
| 629 |
+
|
| 630 |
+
# Initialisation du mode de traitement pour la langue cible actuelle
|
| 631 |
+
system_prompt, operation_prompt = init_process_mode()
|
| 632 |
+
|
| 633 |
+
# Traitement du message utilisateur pour la langue cible actuelle
|
| 634 |
+
try:
|
| 635 |
+
tts_audio, tts_duration = process_message(
|
| 636 |
+
transcription,
|
| 637 |
+
operation_prompt=f"{operation_prompt}",
|
| 638 |
+
tts_enabled=st.session_state.enable_tts_for_input_from_audio_record
|
| 639 |
+
)
|
| 640 |
+
if tts_audio is not None:
|
| 641 |
+
audio_list.append((tts_audio, tts_duration))
|
| 642 |
+
except Exception as e:
|
| 643 |
+
st.error(f"Erreur lors du traitement du message audio : {str(e)}")
|
| 644 |
+
if audio_list:
|
| 645 |
+
try:
|
| 646 |
+
final_audio = concatenate_audio_files(audio_list)
|
| 647 |
+
with st.container(border=True):
|
| 648 |
+
st.audio(final_audio, format="audio/mp3", autoplay=True)
|
| 649 |
+
# Ajout d'un bouton de téléchargement pour l'audio final
|
| 650 |
+
st.download_button(
|
| 651 |
+
label=f"📥 {get_translation('telecharger_audio')}",
|
| 652 |
+
data=final_audio,
|
| 653 |
+
file_name="audio_concatene.mp3",
|
| 654 |
+
mime="audio/mp3"
|
| 655 |
+
)
|
| 656 |
+
except Exception as e:
|
| 657 |
+
st.error(f"Erreur lors de la concaténation des fichiers audio : {str(e)}")
|
| 658 |
except Exception as e:
|
| 659 |
+
st.error(f"Erreur lors du traitement de l'audio : {str(e)}")
|
|
|
|
|
|
|
| 660 |
|
| 661 |
# Configuration de la barre latérale
|
| 662 |
with st.sidebar:
|
|
|
|
| 664 |
st.header(get_translation("sidebar_titre"))
|
| 665 |
|
| 666 |
with st.expander(f"{get_translation('a_propos')}", expanded=False, icon="ℹ️"):
|
| 667 |
+
st.subheader(f"version: {__version__}")
|
| 668 |
st.info(get_translation("info_app"))
|
| 669 |
|
| 670 |
with st.container(border=True):
|
|
|
|
| 681 |
)
|
| 682 |
)
|
| 683 |
|
| 684 |
+
with st.expander(f"{get_translation('selection_langue')}", expanded=True, icon="🌐"):
|
| 685 |
# Conteneur pour la sélection de langue
|
|
|
|
| 686 |
|
| 687 |
# Sélection multiple des langues de destination
|
| 688 |
st.multiselect(
|
|
|
|
| 695 |
on_change=on_languages_change
|
| 696 |
)
|
| 697 |
|
| 698 |
+
with st.expander(f"{get_translation('parametres_tts')}", expanded=True, icon="🔊"):
|
|
|
|
| 699 |
st.selectbox(
|
| 700 |
get_translation("choix_voix_tts"),
|
| 701 |
options=["alloy", "echo", "fable", "onyx", "nova", "shimmer"],
|