Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -112,6 +112,11 @@ st.title("Medical Chatbot")
|
|
112 |
if "history" not in st.session_state:
|
113 |
st.session_state.history = []
|
114 |
|
|
|
|
|
|
|
|
|
|
|
115 |
user_input = st.text_input("Ask a question:", key="input")
|
116 |
|
117 |
if st.button("Submit"):
|
@@ -119,8 +124,15 @@ if st.button("Submit"):
|
|
119 |
result = st.session_state.qa_chain(user_input)
|
120 |
answer = result["result"]
|
121 |
st.session_state.history.append({"question": user_input, "answer": answer})
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
if "history" not in st.session_state:
|
113 |
st.session_state.history = []
|
114 |
|
115 |
+
# Display chat history using streamlit-chat
|
116 |
+
for i, chat in enumerate(st.session_state.history):
|
117 |
+
message(chat['question'], is_user=True, key=f"user_{i}")
|
118 |
+
message(chat['answer'], key=f"bot_{i}")
|
119 |
+
|
120 |
user_input = st.text_input("Ask a question:", key="input")
|
121 |
|
122 |
if st.button("Submit"):
|
|
|
124 |
result = st.session_state.qa_chain(user_input)
|
125 |
answer = result["result"]
|
126 |
st.session_state.history.append({"question": user_input, "answer": answer})
|
127 |
+
# Clear input text after submission
|
128 |
+
st.session_state.input = ""
|
129 |
+
|
130 |
+
# Scroll to the bottom to display the latest message
|
131 |
+
st.markdown(
|
132 |
+
"""
|
133 |
+
<script>
|
134 |
+
window.scrollTo(0, document.body.scrollHeight);
|
135 |
+
</script>
|
136 |
+
""",
|
137 |
+
unsafe_allow_html=True,
|
138 |
+
)
|