uyen13 commited on
Commit
d7cb2f0
β€’
1 Parent(s): 58ac363

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -37
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
- # Initialize session state if not already done
110
- if 'past' not in st.session_state:
111
- st.session_state['past'] = ["γƒγƒ£γƒƒγƒˆγ―γ“γ“γ‹γ‚‰"]
112
- if 'generated' not in st.session_state:
113
- st.session_state['generated'] = ["こんにけは!zendo美ε₯³γ§γ™γ€‚δ½•γ‹γŠζŽ’γ—γ§γ™γ‹οΌŸ... πŸ€—"]
114
-
115
- # Create a container for the chat history with a fixed height (half of the body height)
116
- chat_history_container = st.container()
117
- chat_history_container.style.height = '50vh' # Set the height to 50% of the viewport height
118
-
119
- # Create a form for user input
120
- with st.form(key='my_form', clear_on_submit=True):
121
- user_input = st.text_input("ChatBox", placeholder="θ³ͺε•γ‚’γ”θ¨˜ε…₯ください...", key='input')
122
- submit_button = st.form_submit_button(label='Send')
123
-
124
- # Process user input and update chat history
125
- if submit_button and user_input:
126
- output = conversational_chat(user_input)
127
- st.session_state['past'].append(user_input)
128
- st.session_state['generated'].append(output)
129
-
130
- # Display chat history within the container
131
- if st.session_state['generated']:
132
- with chat_history_container:
133
- for i in range(len(st.session_state['generated'])):
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: