rumaisa1054 commited on
Commit
5a25d9b
·
verified ·
1 Parent(s): 834f3d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -31
app.py CHANGED
@@ -1,36 +1,38 @@
1
- import streamlit as st
2
- def chatbot_interface():
3
- # Initialize session state for conversation history
4
- if 'messages' not in st.session_state:
5
- st.session_state.messages = []
6
 
7
- # Function to generate a response (placeholder)
8
- def generate_response(user_input):
9
- return f"You said: {user_input}"
10
-
11
- # Streamlit app layout
12
- st.title("Chatbot Interface")
13
-
14
- # Display conversation history
15
- for message in st.session_state.messages:
16
- st.write(message)
17
 
18
  # User input
19
- user_input = st.text_input("You:", "")
20
-
21
- # Submit button
22
- if st.button("Send"):
23
- if user_input:
24
- # Append user message to session state
25
- st.session_state.messages.append(f"You: {user_input}")
26
-
27
- # Generate and append bot response to session state
28
- bot_response = "generate_response(user_input)"
29
- st.session_state.messages.append(f"Bot: {bot_response}")
30
-
31
- # Clear the input box
32
- st.experimental_rerun()
 
 
 
 
 
 
 
33
 
34
- # Call the function to run the chatbot interface
35
  if __name__ == "__main__":
36
- chatbot_interface()
 
1
+ def main():
2
+ st.title("Doctor Chatbot")
3
+ # Initialize chat history if not already initialized
4
+ if "chat_messages" not in st.session_state:
5
+ st.session_state.chat_messages = []
6
 
7
+ # Display chat history
8
+ for message in st.session_state.chat_messages:
9
+ if message["role"] == "user":
10
+ st.text_area("User:", message["content"], height=40, key=message["content"], disabled=True)
11
+ else:
12
+ st.text_area("AI:", message["content"], height=40, key=message["content"], disabled=True)
 
 
 
 
13
 
14
  # User input
15
+ if prompt := st.chat_input("Welcome - How can I help you?"):
16
+ # Display user's message in chat message container
17
+ with st.chat_message("user"):
18
+ st.markdown(prompt)
19
+
20
+ # Add user message to chat history
21
+ st.session_state.chat_messages.append({"role": "user", "content": prompt})
22
+
23
+ # Get AI response using responsr function
24
+ response = responsr(prompt)
25
+
26
+
27
+ # Display assistant's response in chat message container
28
+ with st.chat_message("assistant"):
29
+ st.markdown(response)
30
+
31
+ # Add assistant's response and audio to chat history
32
+ st.session_state.chat_messages.append({
33
+ "role": "assistant",
34
+ "content": response,
35
+ })
36
 
 
37
  if __name__ == "__main__":
38
+ main()