salomonsky commited on
Commit
b967b64
·
verified ·
1 Parent(s): 376b54f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -17
app.py CHANGED
@@ -68,11 +68,16 @@ def generate(audio_text, history, temperature=None, max_new_tokens=512, top_p=0.
68
  formatted_prompt = format_prompt(audio_text, history)
69
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
70
  response = ""
 
 
71
 
72
  for response_token in stream:
73
- response += response_token.token.text
74
-
75
- response = ' '.join(response.split()).replace('</s>', '')
 
 
 
76
  audio_file = text_to_speech(response)
77
  return response, audio_file
78
 
@@ -84,20 +89,28 @@ def text_to_speech(text):
84
  return audio_fp
85
 
86
  def main():
87
- audio_data = audiorecorder.audiorecorder("Push to Talk", "Stop Recording...")
88
-
89
- if not audio_data.empty():
90
- st.audio(audio_data.export().read(), format="audio/wav")
91
- audio_data.export("audio.wav", format="wav")
92
- audio_text = recognize_speech("audio.wav")
93
-
94
- if audio_text:
95
- output, audio_file = generate(audio_text, history=st.session_state.history)
96
-
97
- if audio_file is not None:
98
- st.markdown(
99
- f"""<audio autoplay="autoplay" controls="controls" src="data:audio/mp3;base64,{base64.b64encode(audio_file.read()).decode()}" type="audio/mp3" id="audio_player"></audio>""",
100
- unsafe_allow_html=True)
 
 
 
 
 
 
 
 
101
 
102
  if __name__ == "__main__":
103
  main()
 
68
  formatted_prompt = format_prompt(audio_text, history)
69
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
70
  response = ""
71
+ response_tokens = []
72
+ total_tokens = 0
73
 
74
  for response_token in stream:
75
+ total_tokens += len(response_token.token.text)
76
+ response_tokens.append(response_token.token.text)
77
+ response = ' '.join(response_tokens).replace('</s>', '')
78
+ progress = total_tokens / max_new_tokens
79
+ st.progress(progress)
80
+
81
  audio_file = text_to_speech(response)
82
  return response, audio_file
83
 
 
89
  return audio_fp
90
 
91
  def main():
92
+ option = st.radio("Select Input Method:", ("Text", "Voice"))
93
+
94
+ if option == "Text":
95
+ prompt = st.text_area("Enter your prompt here:")
96
+ else:
97
+ st.write("Push and hold the button to record.")
98
+ audio_data = audiorecorder.audiorecorder("Push to Talk", "Stop Recording...")
99
+
100
+ if not audio_data.empty():
101
+ st.audio(audio_data.export().read(), format="audio/wav")
102
+ audio_data.export("audio.wav", format="wav")
103
+ prompt = recognize_speech("audio.wav")
104
+ st.text("Recognized prompt:")
105
+ st.write(prompt)
106
+
107
+ if prompt:
108
+ output, audio_file = generate(prompt, history=st.session_state.history)
109
+
110
+ if audio_file is not None:
111
+ st.markdown(
112
+ f"""<audio autoplay="autoplay" controls="controls" src="data:audio/mp3;base64,{base64.b64encode(audio_file.read()).decode()}" type="audio/mp3" id="audio_player"></audio>""",
113
+ unsafe_allow_html=True)
114
 
115
  if __name__ == "__main__":
116
  main()