Spaces:
Sleeping
Sleeping
Commit
·
acdfe69
1
Parent(s):
b21a522
Update app.py
Browse files
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("
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
# If the "Submit" button is clicked
|
| 119 |
-
if
|
| 120 |
-
#
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
| 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"])
|