Update app.py
Browse files
app.py
CHANGED
@@ -104,10 +104,19 @@ 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 |
# 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()
|
@@ -115,53 +124,26 @@ container = st.container()
|
|
115 |
# User input form
|
116 |
with container:
|
117 |
with st.form(key='my_form', clear_on_submit=True):
|
118 |
-
user_input = st.
|
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['
|
|
|
124 |
|
125 |
# Display chat history
|
126 |
-
if st.session_state['
|
127 |
with response_container:
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
chat_history += f"**AI:** {response}\n\n"
|
132 |
-
|
133 |
# Add a scrollbar to the chat history
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
# st.session_state['generated'] = ["γγγ«γ‘γ―οΌzendoηΎε₯³γ§γγδ½γγζ’γγ§γγοΌ... π€"]
|
143 |
-
|
144 |
-
# if 'past' not in st.session_state:
|
145 |
-
# st.session_state['past'] = ["γγ£γγγ―γγγγ"]
|
146 |
-
|
147 |
-
# # Create containers for chat history and user input
|
148 |
-
# response_container = st.container()
|
149 |
-
# container = st.container()
|
150 |
-
|
151 |
-
# # User input form
|
152 |
-
# with container:
|
153 |
-
# with st.form(key='my_form', clear_on_submit=True):
|
154 |
-
# user_input = st.text_input("ChatBox", placeholder="θ³ͺεγγθ¨ε
₯γγ γγ... ", key='input')
|
155 |
-
# submit_button = st.form_submit_button(label='Send')
|
156 |
-
|
157 |
-
# if submit_button and user_input:
|
158 |
-
# output = conversational_chat(user_input)
|
159 |
-
# st.session_state['past'].append(user_input)
|
160 |
-
# st.session_state['generated'].append(output)
|
161 |
-
|
162 |
-
# # Display chat history
|
163 |
-
# if st.session_state['generated']:
|
164 |
-
# with response_container:
|
165 |
-
# for i in range(len(st.session_state['generated'])):
|
166 |
-
# message(st.session_state["past"][i], is_user=True, key=str(i) + '_user', avatar_style="big-smile")
|
167 |
-
# message(st.session_state["generated"][i], key=str(i), avatar_style="thumbs")
|
|
|
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 |
+
|
108 |
+
|
109 |
# Initialize chat history
|
110 |
if 'history' not in st.session_state:
|
111 |
st.session_state['history'] = []
|
112 |
|
113 |
+
# Initialize messages
|
114 |
+
if 'generated' not in st.session_state:
|
115 |
+
st.session_state['generated'] = ["γγγ«γ‘γ―οΌzendoηΎε₯³γ§γγδ½γγζ’γγ§γγοΌ... π€"]
|
116 |
+
|
117 |
+
if 'past' not in st.session_state:
|
118 |
+
st.session_state['past'] = ["γγ£γγγ―γγγγ"]
|
119 |
+
|
120 |
# Create containers for chat history and user input
|
121 |
response_container = st.container()
|
122 |
container = st.container()
|
|
|
124 |
# User input form
|
125 |
with container:
|
126 |
with st.form(key='my_form', clear_on_submit=True):
|
127 |
+
user_input = st.text_input("ChatBox", placeholder="θ³ͺεγγθ¨ε
₯γγ γγ... ", key='input')
|
128 |
submit_button = st.form_submit_button(label='Send')
|
129 |
|
130 |
if submit_button and user_input:
|
131 |
output = conversational_chat(user_input)
|
132 |
+
st.session_state['past'].append(user_input)
|
133 |
+
st.session_state['generated'].append(output)
|
134 |
|
135 |
# Display chat history
|
136 |
+
if st.session_state['generated']:
|
137 |
with response_container:
|
138 |
+
for i in range(len(st.session_state['generated'])):
|
139 |
+
message(st.session_state["past"][i], is_user=True, key=str(i) + '_user', avatar_style="big-smile")
|
140 |
+
message(st.session_state["generated"][i], key=str(i), avatar_style="thumbs")
|
|
|
|
|
141 |
# Add a scrollbar to the chat history
|
142 |
+
st.markdown("""
|
143 |
+
<style>
|
144 |
+
.stText {
|
145 |
+
overflow-y: auto;
|
146 |
+
height: 100%; /* Ensure the chat history container takes up full available height */
|
147 |
+
}
|
148 |
+
</style>
|
149 |
+
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|