rumaisa1054 commited on
Commit
33cd6d1
·
verified ·
1 Parent(s): 9dc7980

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py CHANGED
@@ -1,6 +1,69 @@
1
  import streamlit as st
2
  from responser import responsr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
 
4
  def main():
5
  # Layout with three columns
6
  col1, col2, col3 = st.columns([3, 1, 1])
@@ -39,3 +102,4 @@ def main():
39
 
40
  if __name__ == "__main__":
41
  main()
 
 
1
  import streamlit as st
2
  from responser import responsr
3
+ import streamlit as st
4
+ from gtts import gTTS
5
+ from io import BytesIO
6
+
7
+ # Function to convert text to speech and return audio file
8
+ def text_to_speech(text):
9
+ tts = gTTS(text)
10
+ audio_file = BytesIO()
11
+ tts.write_to_fp(audio_file)
12
+ audio_file.seek(0)
13
+ return audio_file
14
+
15
+ def main():
16
+ # Layout with three columns
17
+ col1, col2, col3 = st.columns([3, 1, 1])
18
+
19
+ with col1:
20
+ # Title with custom CSS styling for top margin
21
+ st.markdown('<div style="margin-top: -25px;" class="title-wrapper"><h1 style="text-align: center;">Your Health Guide</h1></div>', unsafe_allow_html=True)
22
+
23
+ # Initialize chat history if not already initialized
24
+ if "chat_messages" not in st.session_state:
25
+ st.session_state.chat_messages = []
26
+
27
+ # Display chat history
28
+ for message in st.session_state.chat_messages:
29
+ if message["role"] == "user":
30
+ st.text_area("User:", message["content"], height=40, key=message["content"], disabled=True)
31
+ else:
32
+ st.text_area("AI:", message["content"], height=40, key=message["content"], disabled=True)
33
+ # Display audio in chat interface
34
+ st.audio(message["audio"], format="audio/mp3")
35
+
36
+ # User input
37
+ if prompt := st.chat_input("Welcome - How can I help you?"):
38
+ # Display user's message in chat message container
39
+ with st.chat_message("user"):
40
+ st.markdown(prompt)
41
+
42
+ # Add user message to chat history
43
+ st.session_state.chat_messages.append({"role": "user", "content": prompt})
44
+
45
+ # Get AI response using responsr function
46
+ response = responsr(prompt)
47
+
48
+ # Convert AI response to speech
49
+ audio_file = text_to_speech(response)
50
+
51
+ # Display assistant's response in chat message container
52
+ with st.chat_message("assistant"):
53
+ st.markdown(response)
54
+ st.audio(audio_file, format="audio/mp3")
55
+
56
+ # Add assistant's response and audio to chat history
57
+ st.session_state.chat_messages.append({
58
+ "role": "assistant",
59
+ "content": response,
60
+ "audio": audio_file.getvalue()
61
+ })
62
+
63
+ if __name__ == "__main__":
64
+ main()
65
 
66
+ """
67
  def main():
68
  # Layout with three columns
69
  col1, col2, col3 = st.columns([3, 1, 1])
 
102
 
103
  if __name__ == "__main__":
104
  main()
105
+ """