uyen13 commited on
Commit
43be515
β€’
1 Parent(s): d7cb2f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -42
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.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:
138
- # st.session_state['history'] = []
139
-
140
- # # Initialize messages
141
- # if 'generated' not in st.session_state:
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)