salomonsky commited on
Commit
68ebbc0
verified
1 Parent(s): cdce861

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import streamlit as st
3
  import base64
4
  import io
@@ -46,16 +45,7 @@ def format_prompt(message, history):
46
  prompt += f"[INST] {message} [/INST]"
47
  return prompt
48
 
49
- def text_to_speech(text, speed=1.3):
50
- tts = gTTS(text=text, lang='es')
51
- audio_fp = io.BytesIO()
52
- tts.write_to_fp(audio_fp)
53
- audio_fp.seek(0)
54
- return audio_fp
55
-
56
  def generate(audio_text, history, temperature=None, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
57
- client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
58
-
59
  temperature = float(temperature) if temperature is not None else 0.9
60
  if temperature < 1e-2:
61
  temperature = 1e-2
@@ -81,18 +71,24 @@ def generate(audio_text, history, temperature=None, max_new_tokens=512, top_p=0.
81
  audio_file = text_to_speech(response, speed=1.3)
82
  return response, audio_file
83
 
84
- def main():
85
- st.title("Grabaci贸n de Audio y Reconocimiento de Voz")
 
 
 
 
86
 
 
 
 
87
  if "history" not in st.session_state:
88
  st.session_state.history = []
89
 
90
- audio_data = audiorecorder("Habla para grabar", "Deteniendo la grabaci贸n...")
91
-
92
  if not audio_data.empty():
93
- st.audio(audio_data.export().read(), format="audio/wav")
94
- audio_data.export("audio.wav", format="wav")
95
- st.write(f"Frame rate: {audio_data.frame_rate}, Frame width: {audio_data.frame_width}, Duration: {audio_data.duration_seconds} seconds")
 
96
 
97
  audio_text = recognize_speech("audio.wav")
98
 
 
 
1
  import streamlit as st
2
  import base64
3
  import io
 
45
  prompt += f"[INST] {message} [/INST]"
46
  return prompt
47
 
 
 
 
 
 
 
 
48
  def generate(audio_text, history, temperature=None, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
 
 
49
  temperature = float(temperature) if temperature is not None else 0.9
50
  if temperature < 1e-2:
51
  temperature = 1e-2
 
71
  audio_file = text_to_speech(response, speed=1.3)
72
  return response, audio_file
73
 
74
+ def text_to_speech(text, speed=1.3):
75
+ tts = gTTS(text=text, lang='es')
76
+ audio_fp = io.BytesIO()
77
+ tts.write_to_fp(audio_fp)
78
+ audio_fp.seek(0)
79
+ return audio_fp
80
 
81
+ def main():
82
+ audio_data = audiorecorder("Habla para grabar", "Deteniendo la grabaci贸n...")
83
+
84
  if "history" not in st.session_state:
85
  st.session_state.history = []
86
 
 
 
87
  if not audio_data.empty():
88
+
89
+ with st.spinner("Procesando..."):
90
+ st.audio(audio_data.export().read(), format="audio/wav")
91
+ audio_data.export("audio.wav", format="wav")
92
 
93
  audio_text = recognize_speech("audio.wav")
94