Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import groq
|
| 3 |
from google.cloud import texttospeech_v1 as texttospeech
|
| 4 |
import streamlit as st
|
| 5 |
from dotenv import load_dotenv
|
| 6 |
import speech_recognition as sr
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Configurar la p谩gina de Streamlit
|
| 9 |
st.set_page_config(page_title="Galatea Asistente - OMARDENT", layout="wide")
|
|
@@ -79,6 +82,9 @@ def mostrar_galatea_asistente():
|
|
| 79 |
# Entrada de texto para la pregunta del usuario
|
| 80 |
pregunta_usuario = st.text_input("Escribe tu pregunta aqu铆:")
|
| 81 |
|
|
|
|
|
|
|
|
|
|
| 82 |
# Grabar y transcribir audio
|
| 83 |
if st.button("Grabar y Transcribir Audio"):
|
| 84 |
recognizer = sr.Recognizer()
|
|
@@ -95,17 +101,31 @@ def mostrar_galatea_asistente():
|
|
| 95 |
except sr.RequestError:
|
| 96 |
st.error("Error al solicitar el servicio de reconocimiento de voz")
|
| 97 |
|
| 98 |
-
#
|
| 99 |
-
if st.button("
|
| 100 |
if pregunta_usuario:
|
| 101 |
# Guardar la pregunta en el historial
|
| 102 |
st.session_state['mensajes_chat'].append({"role": "user", "content": pregunta_usuario})
|
| 103 |
|
| 104 |
-
#
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
#
|
| 108 |
-
|
| 109 |
|
| 110 |
# Funci贸n principal
|
| 111 |
def main():
|
|
|
|
| 1 |
import os
|
| 2 |
+
import time
|
| 3 |
import groq
|
| 4 |
from google.cloud import texttospeech_v1 as texttospeech
|
| 5 |
import streamlit as st
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
import speech_recognition as sr
|
| 8 |
+
from threading import Timer
|
| 9 |
+
from datetime import datetime, timedelta
|
| 10 |
|
| 11 |
# Configurar la p谩gina de Streamlit
|
| 12 |
st.set_page_config(page_title="Galatea Asistente - OMARDENT", layout="wide")
|
|
|
|
| 82 |
# Entrada de texto para la pregunta del usuario
|
| 83 |
pregunta_usuario = st.text_input("Escribe tu pregunta aqu铆:")
|
| 84 |
|
| 85 |
+
# Selector de intervalo de tiempo
|
| 86 |
+
intervalo = st.selectbox("Selecciona el intervalo de tiempo (minutos)", [1, 2, 5, 10, 15, 30, 60])
|
| 87 |
+
|
| 88 |
# Grabar y transcribir audio
|
| 89 |
if st.button("Grabar y Transcribir Audio"):
|
| 90 |
recognizer = sr.Recognizer()
|
|
|
|
| 101 |
except sr.RequestError:
|
| 102 |
st.error("Error al solicitar el servicio de reconocimiento de voz")
|
| 103 |
|
| 104 |
+
# Programar la pregunta para ser respondida despu茅s del intervalo de tiempo seleccionado
|
| 105 |
+
if st.button("Programar Respuesta"):
|
| 106 |
if pregunta_usuario:
|
| 107 |
# Guardar la pregunta en el historial
|
| 108 |
st.session_state['mensajes_chat'].append({"role": "user", "content": pregunta_usuario})
|
| 109 |
|
| 110 |
+
# Funci贸n para ejecutar la respuesta despu茅s del tiempo seleccionado
|
| 111 |
+
def ejecutar_respuesta():
|
| 112 |
+
respuesta = obtener_respuesta_groq(pregunta_usuario)
|
| 113 |
+
|
| 114 |
+
# Guardar la respuesta en el historial
|
| 115 |
+
st.session_state['mensajes_chat'].append({"role": "assistant", "content": respuesta})
|
| 116 |
+
|
| 117 |
+
# Mostrar la respuesta
|
| 118 |
+
st.write(f"**Respuesta:** {respuesta}")
|
| 119 |
+
|
| 120 |
+
# Calcular el tiempo en segundos
|
| 121 |
+
tiempo_en_segundos = intervalo * 60
|
| 122 |
+
|
| 123 |
+
# Mostrar un mensaje con la hora programada
|
| 124 |
+
tiempo_ejecucion = datetime.now() + timedelta(minutes=intervalo)
|
| 125 |
+
st.success(f"La respuesta se generar谩 a las {tiempo_ejecucion.strftime('%H:%M:%S')}")
|
| 126 |
|
| 127 |
+
# Programar la ejecuci贸n
|
| 128 |
+
Timer(tiempo_en_segundos, ejecutar_respuesta).start()
|
| 129 |
|
| 130 |
# Funci贸n principal
|
| 131 |
def main():
|