Solshine commited on
Commit
4180345
1 Parent(s): 8ea553d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -32
app.py CHANGED
@@ -97,7 +97,7 @@ def launch_bot():
97
  #st.write("reroute to LLM")
98
  #call in Mistral
99
  prompt3 = master_prompt + prompt2 + "context:" + response
100
- print("Called in Mistral")
101
  # ADD IN LLM
102
  # st.write("Mistral:" ) #Needs finishing
103
  # else:
@@ -106,46 +106,48 @@ def launch_bot():
106
  st.session_state.messages.append(message)
107
 
108
  # If assistant has most recently reaponded create audio of response
109
- if st.session_state.messages[-1]["role"] == "assistant":
110
- audio_result = st.button("Convert to Audio 🔊")
111
- if audio_result:
112
- st.session_state.messages.append({"role": "assistant", "content": prompt})
113
- with st.chat_message("text-to-speech (may take a few minutes"):
114
- #text-to-speech
115
- print("Calling in Text-to-speech via suno/bark-small")
116
 
117
- synthesiser = pipeline("text-to-speech", "suno/bark-small")
118
 
119
- speech = synthesiser(response, forward_params={"do_sample": True})
120
 
121
- # write to temp file: the scipy wav write bark_out.wav
122
- fp.write(scipy.io.wavfile.write("bark_out.wav", rate=speech["sampling_rate"], data=speech["audio"]))
123
 
124
- # ST interface for audio
125
- print("Now we try to display the audio file in the app")
126
-
127
- # Temp file access
128
- fp.seek(0)
129
- audio_file = fp.read('bark_out.wav', 'rb')
130
 
131
- audio_bytes = audio_file.read()
132
-
133
- audio_convert = st.audio(audio_bytes, format='audio/wav')
134
- st.session_state.messages.append(audio_convert)
135
- sample_rate = 44100 # 44100 samples per second
136
- seconds = 2 # Note duration of 2 seconds
 
 
137
 
138
- frequency_la = 440 # Our played note will be 440 Hz
139
 
140
- # Generate array with seconds*sample_rate steps, ranging between 0 and seconds
141
- t = np.linspace(0, seconds, seconds * sample_rate, False)
142
 
143
- # Generate a 440 Hz sine wave
144
- note_la = np.sin(frequency_la * t * 2 * np.pi)
145
- st.audio(note_la, sample_rate=sample_rate)
146
 
147
- # Close and delete temp file
148
- fp.close()
149
 
150
  if __name__ == "__main__":
151
  launch_bot()
 
97
  #st.write("reroute to LLM")
98
  #call in Mistral
99
  prompt3 = master_prompt + prompt2 + "context:" + response
100
+ print("Here's where we would call in Mistral")
101
  # ADD IN LLM
102
  # st.write("Mistral:" ) #Needs finishing
103
  # else:
 
106
  st.session_state.messages.append(message)
107
 
108
  # If assistant has most recently reaponded create audio of response
109
+ if st.session_state.messages[-1]["role"] == "assistant":
110
+ audio_result = st.button("Convert to Audio 🔊")
111
+ if audio_result:
112
+ st.session_state.messages.append({"role": "assistant", "content": prompt})
113
+ with st.chat_message("text-to-speech (may take a few minutes"):
114
+ #text-to-speech
115
+ print("Calling in Text-to-speech via suno/bark-small")
116
 
117
+ synthesiser = pipeline("text-to-speech", "suno/bark-small")
118
 
119
+ speech = synthesiser(response, forward_params={"do_sample": True})
120
 
121
+ # write to temp file: the scipy wav write bark_out.wav
122
+ fp.write(scipy.io.wavfile.write("bark_out.wav", rate=speech["sampling_rate"], data=speech["audio"]))
123
 
124
+ # ST interface for audio
125
+ print("Now we try to display the audio file in the app")
126
+
127
+ # Temp file access
128
+ fp.seek(0)
129
+ audio_file = fp.read('bark_out.wav', 'rb')
130
 
131
+ audio_bytes = audio_file.read()
132
+
133
+ st.audio(audio_bytes, format='audio/wav')
134
+
135
+ #audio_convert = st.audio(audio_bytes, format='audio/wav')
136
+ #st.session_state.messages.append(audio_convert)
137
+ #sample_rate = 44100 # 44100 samples per second
138
+ #seconds = 2 # Note duration of 2 seconds
139
 
140
+ #frequency_la = 440 # Our played note will be 440 Hz
141
 
142
+ # Generate array with seconds*sample_rate steps, ranging between 0 and seconds
143
+ #t = np.linspace(0, seconds, seconds * sample_rate, False)
144
 
145
+ # Generate a 440 Hz sine wave
146
+ #note_la = np.sin(frequency_la * t * 2 * np.pi)
147
+ #st.audio(note_la, sample_rate=sample_rate)
148
 
149
+ # Close and delete temp file
150
+ fp.close()
151
 
152
  if __name__ == "__main__":
153
  launch_bot()