Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from huggingface_hub import InferenceClient
|
| 3 |
-
from gtts import gTTS
|
| 4 |
-
import base64
|
| 5 |
import speech_recognition as sr
|
| 6 |
from pydub import AudioSegment
|
| 7 |
from pydub.playback import play
|
| 8 |
-
import pyaudio
|
| 9 |
from io import BytesIO
|
| 10 |
from time import sleep
|
| 11 |
|
|
@@ -62,7 +58,6 @@ def generate_with_progress(
|
|
| 62 |
response += response_token.token.text
|
| 63 |
total_tokens += 1
|
| 64 |
|
| 65 |
-
# Actualizar la barra de progreso
|
| 66 |
st.subheader("Generando respuesta...")
|
| 67 |
st.progress(total_tokens / max_new_tokens)
|
| 68 |
|
|
@@ -70,56 +65,37 @@ def generate_with_progress(
|
|
| 70 |
|
| 71 |
return response
|
| 72 |
|
| 73 |
-
# Configuraci贸n para la entrada de voz
|
| 74 |
-
with st.form("voice_input_form"):
|
| 75 |
-
st.write("Haz clic en el bot贸n para iniciar la grabaci贸n de voz:")
|
| 76 |
-
start_recording_button = st.form_submit_button("Iniciar Grabaci贸n")
|
| 77 |
-
|
| 78 |
-
# Inicializar historial si no existe
|
| 79 |
if "history" not in st.session_state:
|
| 80 |
st.session_state.history = []
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
st.subheader("Reproduciendo respuesta...")
|
| 115 |
-
audio_file_path = text_to_speech(output)
|
| 116 |
-
play(audio_file_path)
|
| 117 |
-
|
| 118 |
-
for progress_value in range(0, 101, 10):
|
| 119 |
-
st.progress(progress_value / 100)
|
| 120 |
-
sleep(0.5)
|
| 121 |
-
|
| 122 |
-
except sr.UnknownValueError:
|
| 123 |
-
st.warning("No se pudo reconocer el habla.")
|
| 124 |
-
except sr.RequestError as e:
|
| 125 |
-
st.error(f"Error en la solicitud al servicio de reconocimiento de voz: {e}")
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 2 |
import speech_recognition as sr
|
| 3 |
from pydub import AudioSegment
|
| 4 |
from pydub.playback import play
|
|
|
|
| 5 |
from io import BytesIO
|
| 6 |
from time import sleep
|
| 7 |
|
|
|
|
| 58 |
response += response_token.token.text
|
| 59 |
total_tokens += 1
|
| 60 |
|
|
|
|
| 61 |
st.subheader("Generando respuesta...")
|
| 62 |
st.progress(total_tokens / max_new_tokens)
|
| 63 |
|
|
|
|
| 65 |
|
| 66 |
return response
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
if "history" not in st.session_state:
|
| 69 |
st.session_state.history = []
|
| 70 |
|
| 71 |
+
recognizer = sr.Recognizer()
|
| 72 |
+
|
| 73 |
+
while True:
|
| 74 |
+
with st.spinner("Escuchando..."):
|
| 75 |
+
try:
|
| 76 |
+
with sr.Microphone() as source:
|
| 77 |
+
audio_data = recognizer.listen(source, timeout=5)
|
| 78 |
+
st.success("Audio capturado con 茅xito.")
|
| 79 |
+
|
| 80 |
+
text = recognizer.recognize_google(audio_data, language="es-ES")
|
| 81 |
+
st.success(f"Texto reconocido: {text}")
|
| 82 |
+
|
| 83 |
+
st.subheader("Generando respuesta...")
|
| 84 |
+
st.progress(0.0)
|
| 85 |
+
output = generate_with_progress(text, history=st.session_state.history)
|
| 86 |
+
st.session_state.history.append((text, output))
|
| 87 |
+
st.success("Respuesta generada con 茅xito.")
|
| 88 |
+
|
| 89 |
+
st.subheader("Reproduciendo respuesta...")
|
| 90 |
+
audio_file_path = text_to_speech(output)
|
| 91 |
+
play(audio_file_path)
|
| 92 |
+
|
| 93 |
+
for progress_value in range(0, 101, 10):
|
| 94 |
+
st.progress(progress_value / 100)
|
| 95 |
+
sleep(0.5)
|
| 96 |
+
|
| 97 |
+
except sr.UnknownValueError:
|
| 98 |
+
st.warning("No se pudo reconocer el habla.")
|
| 99 |
+
except sr.RequestError as e:
|
| 100 |
+
st.error(f"Error en la solicitud al servicio de reconocimiento de voz: {e}")
|
| 101 |
+
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|