SaileshSivan commited on
Commit
acdfe69
·
1 Parent(s): b21a522

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -22
app.py CHANGED
@@ -42,6 +42,11 @@ import os
42
  # ChatOpenAI class
43
  chat = ChatOpenAI(temperature=0.1)
44
 
 
 
 
 
 
45
  if 'flowmessages' not in st.session_state:
46
  st.session_state['flowmessages'] = [
47
  SystemMessage(content="""You are Doctor AI. an AI Doctor assistant.\
@@ -110,30 +115,32 @@ with st.form(key='my_form',clear_on_submit=True):
110
 
111
  input_question = st.text_input("Type here.", key="input")
112
 
113
- submit = st.form_submit_button("Submit")
114
 
115
 
116
 
117
 
118
  # If the "Submit" button is clicked
119
- if submit:
120
- # Display loading message while processing
121
- with st.spinner("Analyzing..."):
122
- st.chat_message(":blue[You]: " + input_question)
123
-
124
- st.header("Doctor AI", divider=True)
125
- response = get_chatmodel_response(input_question)
126
-
127
- if response is not None:
128
- # Initialize messages in session state if not already initialized
129
- if 'messages' not in st.session_state:
130
- st.session_state['messages'] = []
131
-
132
- # Display assistant response in chat message container
133
- st.chat_message("assistant: " + response)
134
-
135
- # Add both user input and assistant response to chat history
136
- st.session_state.messages.append({"role": "user", "content": input_question})
137
- st.session_state.messages.append({"role": "assistant", "content": response})
138
- else:
139
- st.subheader("Error: Unable to get response. Please try again later.")
 
 
 
42
  # ChatOpenAI class
43
  chat = ChatOpenAI(temperature=0.1)
44
 
45
+ # Initialize chat history
46
+ if "messages" not in st.session_state:
47
+ st.session_state.messages = []
48
+
49
+
50
  if 'flowmessages' not in st.session_state:
51
  st.session_state['flowmessages'] = [
52
  SystemMessage(content="""You are Doctor AI. an AI Doctor assistant.\
 
115
 
116
  input_question = st.text_input("Type here.", key="input")
117
 
118
+ submit = st.form_submit_button("Ask Doctor AI")
119
 
120
 
121
 
122
 
123
  # If the "Submit" button is clicked
124
+ if st.button("Ask Doctor AI"):
125
+ # Accept user input
126
+ input_question = st.text_input("Type your question:")
127
+
128
+ # Display user input in chat message container
129
+ with st.chat_message("user"):
130
+ st.markdown(input_question)
131
+
132
+ # Get AI response
133
+ response = get_chatmodel_response(input_question)
134
+
135
+ # Display assistant response in chat message container
136
+ with st.chat_message("assistant"):
137
+ st.markdown(response.content)
138
+
139
+ # Add both user input and assistant response to chat history
140
+ st.session_state.messages.append({"role": "user", "content": input_question})
141
+ st.session_state.messages.append({"role": "assistant", "content": response.content})
142
+
143
+ # Display chat messages from history
144
+ for message in st.session_state.messages:
145
+ with st.chat_message(message["role"]):
146
+ st.markdown(message["content"])