Spaces:
Runtime error
Runtime error
lhzstar
commited on
Commit
•
a0194f4
1
Parent(s):
8a521de
new commits
Browse files- app.py +6 -16
- celebbot.py +1 -1
- requirements.txt +1 -2
- run_tts.py +5 -2
app.py
CHANGED
@@ -8,7 +8,7 @@ from utils import *
|
|
8 |
def main():
|
9 |
|
10 |
hide_footer()
|
11 |
-
model_list = ["flan-t5-
|
12 |
celeb_data = get_celeb_data(f'data.json')
|
13 |
|
14 |
st.sidebar.header("CelebChat")
|
@@ -75,29 +75,19 @@ def main():
|
|
75 |
response = st.session_state["celeb_bot"].question_answer()
|
76 |
|
77 |
# disable autoplay to play in HTML
|
78 |
-
|
79 |
md = f"""
|
80 |
<p>{response}</p>
|
|
|
|
|
|
|
|
|
81 |
"""
|
82 |
with dialogue_container:
|
83 |
st.chat_message("assistant").markdown(
|
84 |
md,
|
85 |
unsafe_allow_html=True,
|
86 |
)
|
87 |
-
|
88 |
-
# Play the audio (non-blocking)
|
89 |
-
import sounddevice as sd
|
90 |
-
try:
|
91 |
-
sd.stop()
|
92 |
-
sd.play(wav, sr)
|
93 |
-
time_span = len(wav)//sr + 1
|
94 |
-
time.sleep(time_span)
|
95 |
-
|
96 |
-
except sd.PortAudioError as e:
|
97 |
-
print("\nCaught exception: %s" % repr(e))
|
98 |
-
print("Continuing without audio playback. Suppress this message with the \"--no_sound\" flag.\n")
|
99 |
-
except:
|
100 |
-
raise
|
101 |
# Display assistant response in chat message container
|
102 |
st.session_state["messages"].append({"role": "assistant", "content": response})
|
103 |
|
|
|
8 |
def main():
|
9 |
|
10 |
hide_footer()
|
11 |
+
model_list = ["flan-t5-xl"]
|
12 |
celeb_data = get_celeb_data(f'data.json')
|
13 |
|
14 |
st.sidebar.header("CelebChat")
|
|
|
75 |
response = st.session_state["celeb_bot"].question_answer()
|
76 |
|
77 |
# disable autoplay to play in HTML
|
78 |
+
b64 = st.session_state["celeb_bot"].text_to_speech(autoplay=False)
|
79 |
md = f"""
|
80 |
<p>{response}</p>
|
81 |
+
<audio controls autoplay style="display:none;">
|
82 |
+
<source src="data:audio/wav;base64,{b64}" type="audio/wav">
|
83 |
+
Your browser does not support the audio element.
|
84 |
+
</audio>
|
85 |
"""
|
86 |
with dialogue_container:
|
87 |
st.chat_message("assistant").markdown(
|
88 |
md,
|
89 |
unsafe_allow_html=True,
|
90 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
# Display assistant response in chat message container
|
92 |
st.session_state["messages"].append({"role": "assistant", "content": response})
|
93 |
|
celebbot.py
CHANGED
@@ -108,7 +108,7 @@ class CelebBot():
|
|
108 |
knowledge = self.retrieve_knowledge_assertions()
|
109 |
else:
|
110 |
instruction1 = f'You need to answer the question based on commonsense.'
|
111 |
-
query = f"Context: {instruction1} {knowledge}
|
112 |
input_ids = self.QA_tokenizer(f"{query}", return_tensors="pt").input_ids
|
113 |
outputs = self.QA_model.generate(input_ids, max_length=1024)
|
114 |
self.text = self.QA_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
108 |
knowledge = self.retrieve_knowledge_assertions()
|
109 |
else:
|
110 |
instruction1 = f'You need to answer the question based on commonsense.'
|
111 |
+
query = f"Context: {instruction1} {knowledge} Question: {self.text} Answer:"
|
112 |
input_ids = self.QA_tokenizer(f"{query}", return_tensors="pt").input_ids
|
113 |
outputs = self.QA_model.generate(input_ids, max_length=1024)
|
114 |
self.text = self.QA_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
requirements.txt
CHANGED
@@ -29,5 +29,4 @@ sentence-transformers==2.2.2
|
|
29 |
evaluate==0.4.1
|
30 |
https://huggingface.co/spacy/en_core_web_sm/resolve/main/en_core_web_sm-any-py3-none-any.whl
|
31 |
protobuf==3.20
|
32 |
-
streamlit_mic_recorder==0.0.2
|
33 |
-
pyaudio
|
|
|
29 |
evaluate==0.4.1
|
30 |
https://huggingface.co/spacy/en_core_web_sm/resolve/main/en_core_web_sm-any-py3-none-any.whl
|
31 |
protobuf==3.20
|
32 |
+
streamlit_mic_recorder==0.0.2
|
|
run_tts.py
CHANGED
@@ -109,8 +109,11 @@ def tts(text, embed_name, nlp, autoplay=True):
|
|
109 |
print("Continuing without audio playback. Suppress this message with the \"--no_sound\" flag.\n")
|
110 |
except:
|
111 |
raise
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
114 |
|
115 |
if __name__ == "__main__":
|
116 |
text = "Adkins was raised by a young single mother in various working-class neighbourhoods of London. As a child, she enjoyed singing contemporary pop music and learned to play the guitar and the clarinet. However, it was not until her early teens, when she discovered rhythm-and-blues singer Etta James and other mid-20th-century performers, that she began to consider a musical career. While she honed her talents at a government-funded secondary school for the performing arts, a friend began posting songs Adkins had written and recorded onto the social networking Web site Myspace. Her music eventually caught the attention of record labels, and in 2006, several months after graduating, she signed a contract with XL Recordings."
|
|
|
109 |
print("Continuing without audio playback. Suppress this message with the \"--no_sound\" flag.\n")
|
110 |
except:
|
111 |
raise
|
112 |
+
bytes_wav = bytes()
|
113 |
+
byte_io = io.BytesIO(bytes_wav)
|
114 |
+
write(byte_io, synthesizer.sample_rate, wav.astype(np.float32))
|
115 |
+
result_bytes = byte_io.read()
|
116 |
+
return base64.b64encode(result_bytes).decode()
|
117 |
|
118 |
if __name__ == "__main__":
|
119 |
text = "Adkins was raised by a young single mother in various working-class neighbourhoods of London. As a child, she enjoyed singing contemporary pop music and learned to play the guitar and the clarinet. However, it was not until her early teens, when she discovered rhythm-and-blues singer Etta James and other mid-20th-century performers, that she began to consider a musical career. While she honed her talents at a government-funded secondary school for the performing arts, a friend began posting songs Adkins had written and recorded onto the social networking Web site Myspace. Her music eventually caught the attention of record labels, and in 2006, several months after graduating, she signed a contract with XL Recordings."
|