Anne31415 commited on
Commit
a407d5b
·
1 Parent(s): 074eefc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -44
app.py CHANGED
@@ -177,41 +177,36 @@ def main():
177
 
178
  if "chat_history" not in st.session_state:
179
  st.session_state['chat_history'] = []
 
 
 
180
 
181
  if "button_clicked" not in st.session_state:
182
  st.session_state['button_clicked'] = None
183
 
184
  display_chat_history(st.session_state['chat_history'])
 
185
 
186
- st.write("<!-- Start Spacer -->", unsafe_allow_html=True)
187
- st.write("<div style='flex: 1;'></div>", unsafe_allow_html=True)
188
- st.write("<!-- End Spacer -->", unsafe_allow_html=True)
189
-
190
- new_messages_placeholder = st.empty()
191
-
192
- if pdf_path is not None:
193
- query = st.text_input("Ask questions about your PDF file (in any preferred language):")
194
-
195
- # Define your cloud buttons with associated queries
196
- cloud_buttons = [
197
- ("Was genau ist ein Belegarzt?", "Was genau ist ein Belegarzt?", "1"),
198
- ("Wofür wird die Alpha-ID verwendet?", "Wofür wird die Alpha-ID verwendet?", "2"),
199
- # Add more buttons as needed
200
- ]
201
-
202
- # Create cloud buttons
203
- for label, query, color in cloud_buttons:
204
- cloud_button(label, query, color=color)
205
-
206
- # Check if a button was clicked
207
- if st.session_state['button_clicked']:
208
- query = st.session_state['button_clicked']['query']
209
- st.session_state['chat_history'].append(("User", query, "new"))
210
- st.session_state['button_clicked'] = None
211
-
212
- if st.button("Ask") or (not st.session_state['chat_history'] and query) or (st.session_state['chat_history'] and query != st.session_state['chat_history'][-1][1]):
213
  st.session_state['chat_history'].append(("User", query, "new"))
214
-
215
  loading_message = st.empty()
216
  loading_message.text('Bot is thinking...')
217
 
@@ -222,24 +217,10 @@ def main():
222
  response = chain.run(input_documents=docs, question=query)
223
 
224
  st.session_state['chat_history'].append(("Bot", response, "new"))
225
-
226
- new_messages = st.session_state['chat_history'][-2:]
227
- for chat in new_messages:
228
- background_color = "#FFA07A" if chat[2] == "new" else "#acf" if chat[0] == "User" else "#caf"
229
- new_messages_placeholder.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
230
-
231
- st.write("<script>document.getElementById('response').scrollIntoView();</script>", unsafe_allow_html=True)
232
-
233
  loading_message.empty()
234
  query = ""
235
 
236
- st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
237
-
238
-
239
- def display_chat_history(chat_history):
240
- for chat in chat_history:
241
- background_color = "#FFA07A" if chat[2] == "new" else "#acf" if chat[0] == "User" else "#caf"
242
- st.markdown(f"<div style='background-color: {background_color}; padding: 10px; border-radius: 10px; margin: 10px;'>{chat[0]}: {chat[1]}</div>", unsafe_allow_html=True)
243
 
244
  if __name__ == "__main__":
245
- main()
 
177
 
178
  if "chat_history" not in st.session_state:
179
  st.session_state['chat_history'] = []
180
+
181
+
182
+
183
 
184
  if "button_clicked" not in st.session_state:
185
  st.session_state['button_clicked'] = None
186
 
187
  display_chat_history(st.session_state['chat_history'])
188
+ display_chat_history(st.session_state['chat_history'])
189
 
190
+ query = st.text_input("Ask questions about your PDF file (in any preferred language):")
191
+
192
+ # Define your cloud buttons with associated queries
193
+ cloud_buttons = [
194
+ ("Was genau ist ein Belegarzt?", "Was genau ist ein Belegarzt?"),
195
+ ("Wofür wird die Alpha-ID verwendet?", "Wofür wird die Alpha-ID verwendet?"),
196
+ # Add more buttons as needed
197
+ ]
198
+
199
+ # Create cloud buttons
200
+ button_clicked = False
201
+ for label, button_query in cloud_buttons:
202
+ if st.button(label):
203
+ st.session_state['chat_history'].append(("User", button_query, "new"))
204
+ query = button_query
205
+ button_clicked = True
206
+
207
+ if st.button("Ask") or button_clicked:
208
+ if query:
 
 
 
 
 
 
 
 
209
  st.session_state['chat_history'].append(("User", query, "new"))
 
210
  loading_message = st.empty()
211
  loading_message.text('Bot is thinking...')
212
 
 
217
  response = chain.run(input_documents=docs, question=query)
218
 
219
  st.session_state['chat_history'].append(("Bot", response, "new"))
 
 
 
 
 
 
 
 
220
  loading_message.empty()
221
  query = ""
222
 
223
+ st.session_state['chat_history'] = [(sender, msg, "old") for sender, msg, _ in st.session_state['chat_history']]
 
 
 
 
 
 
224
 
225
  if __name__ == "__main__":
226
+ main()