Spaces:
Sleeping
Sleeping
Logeswaransr
commited on
Commit
•
b791812
1
Parent(s):
33c6f10
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ Created on Thu Sep 21 22:17:43 2023
|
|
8 |
import streamlit as st
|
9 |
import sentencepiece
|
10 |
from gtts import gTTS
|
11 |
-
|
12 |
from transformers import pipeline, T5Tokenizer, T5ForConditionalGeneration
|
13 |
|
14 |
model=T5ForConditionalGeneration.from_pretrained("Logeswaransr/T5_MineAI_Prototype").to("cpu")
|
@@ -27,6 +27,8 @@ if 'messages' not in st.session_state:
|
|
27 |
|
28 |
st.subheader("Mine AI")
|
29 |
|
|
|
|
|
30 |
for message in st.session_state.messages:
|
31 |
with st.chat_message(message['role']):
|
32 |
st.markdown(message['content'])
|
@@ -38,9 +40,13 @@ if st.session_state.messages==[]:
|
|
38 |
with st.chat_message("assistant"):
|
39 |
st.markdown(gr)
|
40 |
|
41 |
-
tts=gTTS(
|
42 |
-
tts.
|
43 |
-
|
|
|
|
|
|
|
|
|
44 |
|
45 |
st.session_state.messages.append({
|
46 |
'role':'assistant',
|
@@ -62,9 +68,13 @@ if prompt:=st.chat_input("Enter your query"):
|
|
62 |
with st.chat_message("assistant"):
|
63 |
st.markdown(response)
|
64 |
|
65 |
-
tts=gTTS(
|
66 |
-
tts.
|
67 |
-
|
|
|
|
|
|
|
|
|
68 |
|
69 |
st.session_state.messages.append({
|
70 |
'role':'assistant',
|
|
|
8 |
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")
|
|
|
27 |
|
28 |
st.subheader("Mine AI")
|
29 |
|
30 |
+
audio_stream=r"sample_audio.mp3"
|
31 |
+
|
32 |
for message in st.session_state.messages:
|
33 |
with st.chat_message(message['role']):
|
34 |
st.markdown(message['content'])
|
|
|
40 |
with st.chat_message("assistant"):
|
41 |
st.markdown(gr)
|
42 |
|
43 |
+
tts=gTTS(prompt)
|
44 |
+
tts.save(audio_stream)
|
45 |
+
with open(audio_stream, 'rb') as file:
|
46 |
+
audio_data=file.read()
|
47 |
+
audio_base64 = base64.b64encode(audio_data).decode('utf-8')
|
48 |
+
audio_tag = f'<audio autoplay="true" src="data:audio/mp3;base64,{audio_base64}">'
|
49 |
+
st.markdown(audio_tag, unsafe_allow_html=True)
|
50 |
|
51 |
st.session_state.messages.append({
|
52 |
'role':'assistant',
|
|
|
68 |
with st.chat_message("assistant"):
|
69 |
st.markdown(response)
|
70 |
|
71 |
+
tts=gTTS(prompt)
|
72 |
+
tts.save(audio_stream)
|
73 |
+
with open(audio_stream, 'rb') as file:
|
74 |
+
audio_data=file.read()
|
75 |
+
audio_base64 = base64.b64encode(audio_data).decode('utf-8')
|
76 |
+
audio_tag = f'<audio autoplay="true" src="data:audio/mp3;base64,{audio_base64}">'
|
77 |
+
st.markdown(audio_tag, unsafe_allow_html=True)
|
78 |
|
79 |
st.session_state.messages.append({
|
80 |
'role':'assistant',
|