Update app.py
Browse files
app.py
CHANGED
|
@@ -7,8 +7,7 @@ from datetime import datetime, timedelta
|
|
| 7 |
from streamlit_autorefresh import st_autorefresh
|
| 8 |
import requests
|
| 9 |
import base64
|
| 10 |
-
|
| 11 |
-
# import groq # Este es un ejemplo, sustituye 'groq' por el nombre del SDK real
|
| 12 |
|
| 13 |
# Configurar la página de Streamlit
|
| 14 |
st.set_page_config(page_title="Galatea Asistente - OMARDENT", layout="wide")
|
|
@@ -54,27 +53,37 @@ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "credentials/botidinamix-g.json"
|
|
| 54 |
if not groq_api_key:
|
| 55 |
st.error("No API key provided for Groq. Please set your API key in the .env file.")
|
| 56 |
|
| 57 |
-
# Configurar
|
| 58 |
-
|
| 59 |
|
| 60 |
# Función para obtener respuesta de Groq y generar audio con Google TTS
|
| 61 |
-
def obtener_respuesta_groq(pregunta, contexto="", modelo="
|
| 62 |
if not pregunta:
|
| 63 |
st.error("La pregunta no puede estar vacía.")
|
| 64 |
return "Lo siento, la pregunta no puede estar vacía."
|
| 65 |
|
| 66 |
try:
|
| 67 |
with st.spinner('Evaluando su respuesta...'):
|
| 68 |
-
#
|
| 69 |
-
# Como un ejemplo genérico, esto se reemplaza con una respuesta fija.
|
| 70 |
-
# Ajusta esto según el método específico del SDK de Groq.
|
| 71 |
contexto = "Actúas como Galatea, la asistente virtual de la clínica odontológica Omardent..."
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
# Configurar la solicitud de síntesis de voz (Google TTS)
|
| 77 |
-
|
| 78 |
input_text = texttospeech.SynthesisInput(text=respuesta)
|
| 79 |
voice = texttospeech.VoiceSelectionParams(
|
| 80 |
language_code="es-ES", ssml_gender=texttospeech.SsmlVoiceGender.FEMALE
|
|
@@ -84,7 +93,7 @@ def obtener_respuesta_groq(pregunta, contexto="", modelo="gpt-3.5-turbo", temper
|
|
| 84 |
)
|
| 85 |
|
| 86 |
# Realizar la solicitud de síntesis de voz
|
| 87 |
-
response_audio =
|
| 88 |
input=input_text, voice=voice, audio_config=audio_config
|
| 89 |
)
|
| 90 |
|
|
|
|
| 7 |
from streamlit_autorefresh import st_autorefresh
|
| 8 |
import requests
|
| 9 |
import base64
|
| 10 |
+
from groq import Groq # Importamos Groq como mencionaste
|
|
|
|
| 11 |
|
| 12 |
# Configurar la página de Streamlit
|
| 13 |
st.set_page_config(page_title="Galatea Asistente - OMARDENT", layout="wide")
|
|
|
|
| 53 |
if not groq_api_key:
|
| 54 |
st.error("No API key provided for Groq. Please set your API key in the .env file.")
|
| 55 |
|
| 56 |
+
# Configurar el cliente de Groq
|
| 57 |
+
client = Groq(api_key=groq_api_key)
|
| 58 |
|
| 59 |
# Función para obtener respuesta de Groq y generar audio con Google TTS
|
| 60 |
+
def obtener_respuesta_groq(pregunta, contexto="", modelo="llama3-8b-8192", temperatura=0.5):
|
| 61 |
if not pregunta:
|
| 62 |
st.error("La pregunta no puede estar vacía.")
|
| 63 |
return "Lo siento, la pregunta no puede estar vacía."
|
| 64 |
|
| 65 |
try:
|
| 66 |
with st.spinner('Evaluando su respuesta...'):
|
| 67 |
+
# Llamada a la API de Groq utilizando el cliente creado
|
|
|
|
|
|
|
| 68 |
contexto = "Actúas como Galatea, la asistente virtual de la clínica odontológica Omardent..."
|
| 69 |
+
chat_completion = client.chat.completions.create(
|
| 70 |
+
messages=[
|
| 71 |
+
{"role": "system", "content": contexto},
|
| 72 |
+
{"role": "user", "content": pregunta}
|
| 73 |
+
],
|
| 74 |
+
model=modelo,
|
| 75 |
+
temperature=temperatura,
|
| 76 |
+
max_tokens=1024,
|
| 77 |
+
top_p=1,
|
| 78 |
+
stop=None,
|
| 79 |
+
stream=False,
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
# Acceder al contenido de la respuesta de Groq
|
| 83 |
+
respuesta = chat_completion.choices[0].message.content.strip()
|
| 84 |
|
| 85 |
# Configurar la solicitud de síntesis de voz (Google TTS)
|
| 86 |
+
client_tts = texttospeech.TextToSpeechClient()
|
| 87 |
input_text = texttospeech.SynthesisInput(text=respuesta)
|
| 88 |
voice = texttospeech.VoiceSelectionParams(
|
| 89 |
language_code="es-ES", ssml_gender=texttospeech.SsmlVoiceGender.FEMALE
|
|
|
|
| 93 |
)
|
| 94 |
|
| 95 |
# Realizar la solicitud de síntesis de voz
|
| 96 |
+
response_audio = client_tts.synthesize_speech(
|
| 97 |
input=input_text, voice=voice, audio_config=audio_config
|
| 98 |
)
|
| 99 |
|