salomonsky commited on
Commit
644763d
·
verified ·
1 Parent(s): 395957b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -16,14 +16,12 @@ def recognize_speech(audio_data, show_messages=False):
16
  try:
17
  audio_text = recognizer.recognize_google(audio, language="es-ES")
18
  if show_messages:
19
- st.subheader("Texto Reconocido:")
20
- st.write(audio_text)
21
  st.success("Reconocimiento de voz completado.")
22
  except sr.UnknownValueError:
23
  st.warning("No se pudo reconocer el audio. ¿Intentaste grabar algo?")
24
  audio_text = ""
25
  except sr.RequestError:
26
- st.error("Error en la solicitud de reconocimiento. Por favor, inténtalo de nuevo.")
27
  audio_text = ""
28
 
29
  return audio_text
@@ -74,7 +72,6 @@ def text_to_speech(text, speed=1.3):
74
  return audio_fp
75
 
76
  def main():
77
-
78
  if "history" not in st.session_state:
79
  st.session_state.history = []
80
 
@@ -84,13 +81,18 @@ def main():
84
  st.audio(audio_data.export().read(), format="audio/wav")
85
  audio_data.export("audio.wav", format="wav")
86
  audio_text = recognize_speech("audio.wav")
 
 
 
 
 
87
 
88
  if audio_text:
89
  output, audio_file = generate(audio_text, history=st.session_state.history)
90
-
91
  if audio_text:
92
  st.session_state.history.append((audio_text, output))
93
-
94
  if audio_file is not None:
95
  st.markdown(
96
  f"""
 
16
  try:
17
  audio_text = recognizer.recognize_google(audio, language="es-ES")
18
  if show_messages:
 
 
19
  st.success("Reconocimiento de voz completado.")
20
  except sr.UnknownValueError:
21
  st.warning("No se pudo reconocer el audio. ¿Intentaste grabar algo?")
22
  audio_text = ""
23
  except sr.RequestError:
24
+ st.error("Aún no has grabado nada. Por favor, inténtalo de nuevo.")
25
  audio_text = ""
26
 
27
  return audio_text
 
72
  return audio_fp
73
 
74
  def main():
 
75
  if "history" not in st.session_state:
76
  st.session_state.history = []
77
 
 
81
  st.audio(audio_data.export().read(), format="audio/wav")
82
  audio_data.export("audio.wav", format="wav")
83
  audio_text = recognize_speech("audio.wav")
84
+
85
+ if not st.session_state.history:
86
+ pre_prompt = "Te Llamarás Chaman 4.0 y tus respuestas serán sumamente breves."
87
+ output, _ = generate(pre_prompt, history=st.session_state.history, show_messages=False)
88
+ st.session_state.history.append((pre_prompt, output))
89
 
90
  if audio_text:
91
  output, audio_file = generate(audio_text, history=st.session_state.history)
92
+
93
  if audio_text:
94
  st.session_state.history.append((audio_text, output))
95
+
96
  if audio_file is not None:
97
  st.markdown(
98
  f"""