Update app.py
Browse files
app.py
CHANGED
@@ -104,45 +104,34 @@ def conversational_chat(query):
|
|
104 |
result = chain({"question": query, "chat_history": st.session_state['history']})
|
105 |
st.session_state['history'].append((query, result["answer"]))
|
106 |
return result["answer"]
|
|
|
107 |
if 'history' not in st.session_state:
|
108 |
st.session_state['history'] = []
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
#
|
125 |
-
if
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
message(st.session_state["past"][i], is_user=True, key=str(i) + '_user', avatar_style="big-smile")
|
135 |
-
message(st.session_state["generated"][i], key=str(i), avatar_style="thumbs")
|
136 |
-
|
137 |
-
# Ensure chat history is always scrollable
|
138 |
-
st.markdown("""
|
139 |
-
<style>
|
140 |
-
.stText {
|
141 |
-
overflow-y: auto;
|
142 |
-
height: 100%; /* Ensure the chat history container takes up full available height */
|
143 |
-
}
|
144 |
-
</style>
|
145 |
-
""", unsafe_allow_html=True)
|
146 |
|
147 |
# Initialize chat history
|
148 |
# if 'history' not in st.session_state:
|
|
|
104 |
result = chain({"question": query, "chat_history": st.session_state['history']})
|
105 |
st.session_state['history'].append((query, result["answer"]))
|
106 |
return result["answer"]
|
107 |
+
# Initialize chat history
|
108 |
if 'history' not in st.session_state:
|
109 |
st.session_state['history'] = []
|
110 |
+
|
111 |
+
# Create containers for chat history and user input
|
112 |
+
response_container = st.container()
|
113 |
+
container = st.container()
|
114 |
+
|
115 |
+
# User input form
|
116 |
+
with container:
|
117 |
+
with st.form(key='my_form', clear_on_submit=True):
|
118 |
+
user_input = st.text_area("ChatBox", height=100, placeholder="θ³ͺεγγθ¨ε
₯γγ γγ...")
|
119 |
+
submit_button = st.form_submit_button(label='Send')
|
120 |
+
|
121 |
+
if submit_button and user_input:
|
122 |
+
output = conversational_chat(user_input)
|
123 |
+
st.session_state['history'].append((user_input, output))
|
124 |
+
|
125 |
+
# Display chat history
|
126 |
+
if st.session_state['history']:
|
127 |
+
with response_container:
|
128 |
+
chat_history = ""
|
129 |
+
for user_query, response in st.session_state['history']:
|
130 |
+
chat_history += f"**User:** {user_query}\n"
|
131 |
+
chat_history += f"**AI:** {response}\n\n"
|
132 |
+
|
133 |
+
# Add a scrollbar to the chat history
|
134 |
+
st.write(chat_history, markdown=True, height=400)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
# Initialize chat history
|
137 |
# if 'history' not in st.session_state:
|