salomonsky commited on
Commit
c015fb0
·
verified ·
1 Parent(s): ce01657

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -21
app.py CHANGED
@@ -29,9 +29,7 @@ def text_to_speech(text, speed=2.0):
29
  tts.save(audio_file_path)
30
  return audio_file_path
31
 
32
- def generate(
33
- user_input, history, temperature=None, max_new_tokens=2048, top_p=0.95, repetition_penalty=1.0,
34
- ):
35
  global system_prompt_sent
36
  temperature = float(temperature) if temperature is not None else 0.9
37
  if temperature < 1e-2:
@@ -60,25 +58,25 @@ def generate(
60
  audio_file = open(audio_file_path, 'rb')
61
  audio_bytes = audio_file.read()
62
 
63
- with st.container():
64
- st.text_area("Salida del Chatbot", value=response, height=200, max_chars=500, disabled=True)
65
 
66
- if "history" not in st.session_state:
67
- st.session_state.history = []
68
 
69
- user_input = st.text_input(label="Usuario", value="Escribe aquí tu mensaje")
70
- output = generate(user_input, history=st.session_state.history)
71
- st.session_state.history.append((user_input, output))
72
 
73
- for user_prompt, bot_response in st.session_state.history:
74
- st.write(f"Usuario: {user_prompt}")
75
- st.write(f"Respuesta: {bot_response}")
76
- st.markdown(
77
- f"""
78
- <audio autoplay="autoplay" controls="controls" src="data:audio/mp3;base64,{base64.b64encode(audio_bytes).decode()}" type="audio/mp3" speed="1.5" id="audio_player"></audio>
79
- """,
80
- unsafe_allow_html=True
81
- )
82
 
83
- if __name__ == "__main__":
84
- generate(user_input="", history=[])
 
 
 
 
 
 
 
 
 
29
  tts.save(audio_file_path)
30
  return audio_file_path
31
 
32
+ def generate(user_input, history, temperature=None, max_new_tokens=2048, top_p=0.95, repetition_penalty=1.0):
 
 
33
  global system_prompt_sent
34
  temperature = float(temperature) if temperature is not None else 0.9
35
  if temperature < 1e-2:
 
58
  audio_file = open(audio_file_path, 'rb')
59
  audio_bytes = audio_file.read()
60
 
61
+ return response, audio_bytes
 
62
 
63
+ if "history" not in st.session_state:
64
+ st.session_state.history = []
65
 
66
+ user_input = st.text_input(label="Usuario", value="")
67
+ output, audio_bytes = generate(user_input, history=st.session_state.history)
68
+ st.session_state.history.append((user_input, output))
69
 
70
+ with st.container():
71
+ st.text_area("Salida del Chatbot", value=output, height=200, max_chars=500, key="output_text", disabled=True)
 
 
 
 
 
 
 
72
 
73
+ for i, (user_prompt, bot_response) in enumerate(st.session_state.history):
74
+ st.write(f"Usuario {i + 1}: {user_prompt}")
75
+ st.write(f"Respuesta {i + 1}: {bot_response}")
76
+
77
+ st.markdown(
78
+ f"""
79
+ <audio autoplay="autoplay" controls="controls" src="data:audio/mp3;base64,{base64.b64encode(audio_bytes).decode()}" type="audio/mp3" speed="1.5" id="audio_player"></audio>
80
+ """,
81
+ unsafe_allow_html=True
82
+ )