Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,7 +37,7 @@ def transcribe_audio(audio_file):
|
|
| 37 |
def text_to_speech(text):
|
| 38 |
response = client.audio.speech.create(
|
| 39 |
model="tts-1",
|
| 40 |
-
voice="
|
| 41 |
input=text
|
| 42 |
)
|
| 43 |
|
|
@@ -51,8 +51,10 @@ def text_to_speech(text):
|
|
| 51 |
|
| 52 |
return audio_bytes
|
| 53 |
|
| 54 |
-
def process_message(message, is_audio_input=False):
|
| 55 |
-
|
|
|
|
|
|
|
| 56 |
with st.chat_message("user"):
|
| 57 |
st.markdown(message)
|
| 58 |
|
|
@@ -73,7 +75,7 @@ def process_message(message, is_audio_input=False):
|
|
| 73 |
|
| 74 |
if is_audio_input:
|
| 75 |
tts_audio = text_to_speech(full_response)
|
| 76 |
-
st.audio(tts_audio, format="audio/mp3")
|
| 77 |
|
| 78 |
def main():
|
| 79 |
st.title("Application de Chat avec GPT-4")
|
|
@@ -91,19 +93,20 @@ def main():
|
|
| 91 |
|
| 92 |
# Interface utilisateur pour le chat
|
| 93 |
user_input = st.chat_input("Entrez votre message ici:")
|
|
|
|
| 94 |
|
| 95 |
# Ajout de l'enregistreur audio
|
| 96 |
st.write("Ou enregistrez votre message audio :")
|
| 97 |
audio = audiorecorder("Cliquez pour enregistrer", "Cliquez pour arrêter l'enregistrement")
|
| 98 |
|
| 99 |
if user_input:
|
| 100 |
-
process_message(user_input)
|
| 101 |
|
| 102 |
if len(audio) > 0:
|
| 103 |
-
st.audio(audio.export().read())
|
| 104 |
transcription = transcribe_audio(audio)
|
| 105 |
st.write(f"Transcription : {transcription}")
|
| 106 |
-
process_message(transcription, is_audio_input=True)
|
| 107 |
|
| 108 |
st.sidebar.markdown("## À propos")
|
| 109 |
st.sidebar.info("Cette application utilise Streamlit et OpenAI GPT-4 pour créer un chat interactif avec un modèle de langage avancé.")
|
|
|
|
| 37 |
def text_to_speech(text):
|
| 38 |
response = client.audio.speech.create(
|
| 39 |
model="tts-1",
|
| 40 |
+
voice="onyx",
|
| 41 |
input=text
|
| 42 |
)
|
| 43 |
|
|
|
|
| 51 |
|
| 52 |
return audio_bytes
|
| 53 |
|
| 54 |
+
def process_message(message, operation_prompt="", is_audio_input=False):
|
| 55 |
+
payload_content = f'{operation_prompt} :\n\"\"\"\n{message}\n\"\"\"'
|
| 56 |
+
|
| 57 |
+
st.session_state.messages.append({"role": "user", "content": payload_content})
|
| 58 |
with st.chat_message("user"):
|
| 59 |
st.markdown(message)
|
| 60 |
|
|
|
|
| 75 |
|
| 76 |
if is_audio_input:
|
| 77 |
tts_audio = text_to_speech(full_response)
|
| 78 |
+
st.audio(tts_audio, format="audio/mp3", autoplay=True)
|
| 79 |
|
| 80 |
def main():
|
| 81 |
st.title("Application de Chat avec GPT-4")
|
|
|
|
| 93 |
|
| 94 |
# Interface utilisateur pour le chat
|
| 95 |
user_input = st.chat_input("Entrez votre message ici:")
|
| 96 |
+
OP_PROMPT = "`fr_FR` to `en_US`"
|
| 97 |
|
| 98 |
# Ajout de l'enregistreur audio
|
| 99 |
st.write("Ou enregistrez votre message audio :")
|
| 100 |
audio = audiorecorder("Cliquez pour enregistrer", "Cliquez pour arrêter l'enregistrement")
|
| 101 |
|
| 102 |
if user_input:
|
| 103 |
+
process_message(user_input, operation_prompt=f"{OP_PROMPT}")
|
| 104 |
|
| 105 |
if len(audio) > 0:
|
| 106 |
+
# st.audio(audio.export().read(), autoplay=False)
|
| 107 |
transcription = transcribe_audio(audio)
|
| 108 |
st.write(f"Transcription : {transcription}")
|
| 109 |
+
process_message(transcription, operation_prompt=f"{OP_PROMPT}", is_audio_input=True)
|
| 110 |
|
| 111 |
st.sidebar.markdown("## À propos")
|
| 112 |
st.sidebar.info("Cette application utilise Streamlit et OpenAI GPT-4 pour créer un chat interactif avec un modèle de langage avancé.")
|