Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
from huggingface_hub import InferenceClient
|
3 |
from gtts import gTTS
|
|
|
4 |
import os
|
5 |
|
6 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
@@ -26,25 +27,34 @@ def generate_response(message, system_message, max_tokens, temperature, top_p):
|
|
26 |
tts.save(audio_file)
|
27 |
return response, audio_file
|
28 |
|
29 |
-
|
|
|
|
|
|
|
30 |
|
31 |
-
|
32 |
-
submit = st.button("Generate Response")
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
|
|
40 |
response, audio_file = generate_response(message, system_message, max_tokens, temperature, top_p)
|
41 |
st.write(response)
|
42 |
|
43 |
-
#
|
|
|
|
|
|
|
44 |
audio_html = f"""
|
45 |
-
<audio autoplay>
|
46 |
-
<source src="data:audio/
|
47 |
Your browser does not support the audio element.
|
48 |
</audio>
|
49 |
"""
|
50 |
st.markdown(audio_html, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from huggingface_hub import InferenceClient
|
3 |
from gtts import gTTS
|
4 |
+
import base64
|
5 |
import os
|
6 |
|
7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
|
|
27 |
tts.save(audio_file)
|
28 |
return response, audio_file
|
29 |
|
30 |
+
def get_base64_audio(audio_file):
|
31 |
+
with open(audio_file, "rb") as f:
|
32 |
+
audio_data = f.read()
|
33 |
+
return base64.b64encode(audio_data).decode()
|
34 |
|
35 |
+
st.title("Hugging Face Chatbot with Voice Response")
|
|
|
36 |
|
37 |
+
message = st.text_input("Enter your message:")
|
38 |
+
system_message = st.text_input("System message:", value="You are a friendly Chatbot.")
|
39 |
+
max_tokens = st.slider("Max new tokens", 1, 2048, 512)
|
40 |
+
temperature = st.slider("Temperature", 0.1, 4.0, 0.7, step=0.1)
|
41 |
+
top_p = st.slider("Top-p (nucleus sampling)", 0.1, 1.0, 0.95, step=0.05)
|
42 |
|
43 |
+
if st.button("Generate Response"):
|
44 |
response, audio_file = generate_response(message, system_message, max_tokens, temperature, top_p)
|
45 |
st.write(response)
|
46 |
|
47 |
+
# Get base64 encoded audio data
|
48 |
+
audio_base64 = get_base64_audio(audio_file)
|
49 |
+
|
50 |
+
# HTML to autoplay the audio
|
51 |
audio_html = f"""
|
52 |
+
<audio controls autoplay>
|
53 |
+
<source src="data:audio/mp3;base64,{audio_base64}" type="audio/mp3">
|
54 |
Your browser does not support the audio element.
|
55 |
</audio>
|
56 |
"""
|
57 |
st.markdown(audio_html, unsafe_allow_html=True)
|
58 |
+
|
59 |
+
# Clean up the audio file
|
60 |
+
os.remove(audio_file)
|