Logeswaransr commited on
Commit
58c29f7
1 Parent(s): b2c635f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -20
app.py CHANGED
@@ -26,14 +26,31 @@ if 'messages' not in st.session_state:
26
 
27
  st.subheader("Mine AI")
28
 
29
- audio_stream=r"sample_audio.mp3"
30
-
31
  for message in st.session_state.messages:
32
  with st.chat_message(message['role']):
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:
@@ -62,21 +79,3 @@ if prompt:=st.chat_input("Enter your query"):
62
  st.session_state.messages.append({
63
  'role':'assistant',
64
  'content': response})
65
-
66
- if st.session_state.messages==[]:
67
- for gr in greetings:
68
- with st.chat_message("assistant"):
69
- st.markdown(gr)
70
-
71
- tts=gTTS(gr)
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
- time.sleep(10)
79
-
80
- st.session_state.messages.append({
81
- 'role':'assistant',
82
- 'content': gr})
 
26
 
27
  st.subheader("Mine AI")
28
 
 
 
29
  for message in st.session_state.messages:
30
  with st.chat_message(message['role']):
31
  st.markdown(message['content'])
32
 
33
  ## messages element format: {'role':'user', 'content':'<user prompt>'}
34
 
35
+ if st.session_state.messages==[]:
36
+ for gr in greetings:
37
+ with st.chat_message("assistant"):
38
+ st.markdown(gr)
39
+
40
+ if gr==greetings[1]:
41
+ tts=gTTS(gr)
42
+ tts.save('greeting_audio.mp3')
43
+ with open('greeting_audio.mp3', 'rb') as file:
44
+ greeting_audio_data=file.read()
45
+ greeting_audio_base64 = base64.b64encode(greeting_audio_data).decode('utf-8')
46
+ greeting_audio_tag = f'<audio autoplay="true" src="data:audio/mp3;base64,{greeting_audio_base64}">'
47
+ st.markdown(greeting_audio_tag, unsafe_allow_html=True)
48
+
49
+ st.session_state.messages.append({
50
+ 'role':'assistant',
51
+ 'content': gr})
52
+
53
+ audio_stream="response_audio.mp3"
54
  tts=gTTS("Here is your answer")
55
  tts.save(audio_stream)
56
  with open(audio_stream, 'rb') as file:
 
79
  st.session_state.messages.append({
80
  'role':'assistant',
81
  'content': response})