Spaces:
Sleeping
Sleeping
Commit
·
5e32016
1
Parent(s):
467e663
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ import streamlit as st
|
|
| 9 |
import sentencepiece
|
| 10 |
from gtts import gTTS
|
| 11 |
import base64
|
|
|
|
| 12 |
from transformers import pipeline, T5Tokenizer, T5ForConditionalGeneration
|
| 13 |
|
| 14 |
model=T5ForConditionalGeneration.from_pretrained("Logeswaransr/T5_MineAI_Prototype").to("cpu")
|
|
@@ -32,6 +33,13 @@ for message in st.session_state.messages:
|
|
| 32 |
st.markdown(message['content'])
|
| 33 |
|
| 34 |
## messages element format: {'role':'user', 'content':'<user prompt>'}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
if st.session_state.messages==[]:
|
| 37 |
for gr in greetings:
|
|
@@ -45,6 +53,7 @@ if st.session_state.messages==[]:
|
|
| 45 |
audio_base64 = base64.b64encode(audio_data).decode('utf-8')
|
| 46 |
audio_tag = f'<audio autoplay="true" src="data:audio/mp3;base64,{audio_base64}">'
|
| 47 |
st.markdown(audio_tag, unsafe_allow_html=True)
|
|
|
|
| 48 |
|
| 49 |
st.session_state.messages.append({
|
| 50 |
'role':'assistant',
|
|
@@ -66,12 +75,6 @@ if prompt:=st.chat_input("Enter your query"):
|
|
| 66 |
with st.chat_message("assistant"):
|
| 67 |
st.markdown(response)
|
| 68 |
|
| 69 |
-
tts=gTTS(response)
|
| 70 |
-
tts.save(audio_stream)
|
| 71 |
-
with open(audio_stream, 'rb') as file:
|
| 72 |
-
audio_data=file.read()
|
| 73 |
-
audio_base64 = base64.b64encode(audio_data).decode('utf-8')
|
| 74 |
-
audio_tag = f'<audio autoplay="true" src="data:audio/mp3;base64,{audio_base64}">'
|
| 75 |
st.markdown(audio_tag, unsafe_allow_html=True)
|
| 76 |
|
| 77 |
st.session_state.messages.append({
|
|
|
|
| 9 |
import sentencepiece
|
| 10 |
from gtts import gTTS
|
| 11 |
import base64
|
| 12 |
+
import time
|
| 13 |
from transformers import pipeline, T5Tokenizer, T5ForConditionalGeneration
|
| 14 |
|
| 15 |
model=T5ForConditionalGeneration.from_pretrained("Logeswaransr/T5_MineAI_Prototype").to("cpu")
|
|
|
|
| 33 |
st.markdown(message['content'])
|
| 34 |
|
| 35 |
## messages element format: {'role':'user', 'content':'<user prompt>'}
|
| 36 |
+
|
| 37 |
+
tts=gTTS("Here is your answer")
|
| 38 |
+
tts.save(audio_stream)
|
| 39 |
+
with open(audio_stream, 'rb') as file:
|
| 40 |
+
audio_data=file.read()
|
| 41 |
+
audio_base64 = base64.b64encode(audio_data).decode('utf-8')
|
| 42 |
+
audio_tag = f'<audio autoplay="true" src="data:audio/mp3;base64,{audio_base64}">'
|
| 43 |
|
| 44 |
if st.session_state.messages==[]:
|
| 45 |
for gr in greetings:
|
|
|
|
| 53 |
audio_base64 = base64.b64encode(audio_data).decode('utf-8')
|
| 54 |
audio_tag = f'<audio autoplay="true" src="data:audio/mp3;base64,{audio_base64}">'
|
| 55 |
st.markdown(audio_tag, unsafe_allow_html=True)
|
| 56 |
+
time.sleep(5)
|
| 57 |
|
| 58 |
st.session_state.messages.append({
|
| 59 |
'role':'assistant',
|
|
|
|
| 75 |
with st.chat_message("assistant"):
|
| 76 |
st.markdown(response)
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
st.markdown(audio_tag, unsafe_allow_html=True)
|
| 79 |
|
| 80 |
st.session_state.messages.append({
|