Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,38 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
# Initialize
|
4 |
-
if
|
5 |
-
st.session_state.
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
# Display conversation history
|
15 |
-
for message in st.session_state.messages:
|
16 |
-
st.write(message)
|
17 |
|
18 |
# User input
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
# Call the function to run the chatbot interface
|
35 |
if __name__ == "__main__":
|
36 |
-
|
|
|
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()
|