Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ load_dotenv()
|
|
| 15 |
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 16 |
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "credentials/botidinamix-g.json"
|
| 17 |
|
| 18 |
-
# Cliente Groq
|
| 19 |
client = Groq(api_key=groq_api_key)
|
| 20 |
|
| 21 |
# Descargar el sonido de notificaci贸n si no existe
|
|
@@ -41,12 +41,10 @@ def obtener_respuesta_groq(pregunta, modelo="llama3-8b-8192", temperatura=0.5):
|
|
| 41 |
{"role": "user", "content": pregunta}
|
| 42 |
],
|
| 43 |
model=modelo,
|
| 44 |
-
temperature=
|
| 45 |
).choices[0].message.content.strip()
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
client_tts = texttospeech.TextToSpeechClient()
|
| 51 |
input_text = texttospeech.SynthesisInput(text=respuesta)
|
| 52 |
voice = texttospeech.VoiceSelectionParams(language_code="es-ES", ssml_gender=texttospeech.SsmlVoiceGender.FEMALE)
|
|
@@ -57,10 +55,12 @@ def obtener_respuesta_groq(pregunta, modelo="llama3-8b-8192", temperatura=0.5):
|
|
| 57 |
"audio_config": audio_config
|
| 58 |
})
|
| 59 |
|
|
|
|
| 60 |
audio_file_path = f'tmp_respuesta_{int(time.time())}.mp3'
|
| 61 |
with open(audio_file_path, 'wb') as audio_file:
|
| 62 |
audio_file.write(response_audio.audio_content)
|
| 63 |
|
|
|
|
| 64 |
with open(audio_file_path, "rb") as audio_file:
|
| 65 |
audio_base64 = base64.b64encode(audio_file.read()).decode()
|
| 66 |
|
|
@@ -103,3 +103,4 @@ if __name__ == "__main__":
|
|
| 103 |
main()
|
| 104 |
|
| 105 |
|
|
|
|
|
|
| 15 |
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 16 |
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "credentials/botidinamix-g.json"
|
| 17 |
|
| 18 |
+
# Cliente Groq (sin pasar proxies)
|
| 19 |
client = Groq(api_key=groq_api_key)
|
| 20 |
|
| 21 |
# Descargar el sonido de notificaci贸n si no existe
|
|
|
|
| 41 |
{"role": "user", "content": pregunta}
|
| 42 |
],
|
| 43 |
model=modelo,
|
| 44 |
+
temperature=temperatura
|
| 45 |
).choices[0].message.content.strip()
|
| 46 |
|
| 47 |
+
# Crear archivo de audio con la respuesta
|
|
|
|
|
|
|
| 48 |
client_tts = texttospeech.TextToSpeechClient()
|
| 49 |
input_text = texttospeech.SynthesisInput(text=respuesta)
|
| 50 |
voice = texttospeech.VoiceSelectionParams(language_code="es-ES", ssml_gender=texttospeech.SsmlVoiceGender.FEMALE)
|
|
|
|
| 55 |
"audio_config": audio_config
|
| 56 |
})
|
| 57 |
|
| 58 |
+
# Guardar audio en un archivo temporal
|
| 59 |
audio_file_path = f'tmp_respuesta_{int(time.time())}.mp3'
|
| 60 |
with open(audio_file_path, 'wb') as audio_file:
|
| 61 |
audio_file.write(response_audio.audio_content)
|
| 62 |
|
| 63 |
+
# Convertir audio a base64
|
| 64 |
with open(audio_file_path, "rb") as audio_file:
|
| 65 |
audio_base64 = base64.b64encode(audio_file.read()).decode()
|
| 66 |
|
|
|
|
| 103 |
main()
|
| 104 |
|
| 105 |
|
| 106 |
+
|