Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
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 |
-
|
88 |
-
|
89 |
-
if
|
90 |
-
st.
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|