zakerytclarke commited on
Commit
e04907a
·
verified ·
1 Parent(s): 968f358

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -321,28 +321,40 @@ def main():
321
  choice2 = random.choice(list2)
322
  choice3 = random.choice(list3)
323
 
324
- s1, s2, s3 = st.columns([1, 1, 1])
 
 
 
325
 
326
- user_suggested_input = None
 
327
 
 
328
  with s1:
329
  if st.button(choice1, use_container_width=True):
330
- user_suggested_input = choice1
331
 
332
  with s2:
333
  if st.button(choice2, use_container_width=True):
334
- user_suggested_input = choice2
335
 
336
  with s3:
337
  if st.button(choice3, use_container_width=True):
338
- user_suggested_input = choice3
339
 
 
340
  user_input = st.chat_input("Ask me anything")
341
-
342
- if user_input:
 
343
  with st.spinner('Generating Response...'):
344
- response = handle_chat(user_prompt, user_suggested_input or user_input, teapot_ai)
345
-
 
 
 
 
 
346
 
347
  if __name__ == "__main__":
348
  main()
 
321
  choice2 = random.choice(list2)
322
  choice3 = random.choice(list3)
323
 
324
+
325
+ # Initialize user_suggested_input in session_state if it doesn't exist
326
+ if 'user_suggested_input' not in st.session_state:
327
+ st.session_state.user_suggested_input = None
328
 
329
+ # Define columns
330
+ s1, s2, s3 = st.columns([1, 1, 1])
331
 
332
+ # Button click handling
333
  with s1:
334
  if st.button(choice1, use_container_width=True):
335
+ st.session_state.user_suggested_input = choice1
336
 
337
  with s2:
338
  if st.button(choice2, use_container_width=True):
339
+ st.session_state.user_suggested_input = choice2
340
 
341
  with s3:
342
  if st.button(choice3, use_container_width=True):
343
+ st.session_state.user_suggested_input = choice3
344
 
345
+ # Input field for chat
346
  user_input = st.chat_input("Ask me anything")
347
+
348
+ # Handle chat input and button selection
349
+ if user_input or st.session_state.user_suggested_input:
350
  with st.spinner('Generating Response...'):
351
+ response = handle_chat(user_prompt, st.session_state.user_suggested_input or user_input, teapot_ai)
352
+ st.write(response)
353
+
354
+ # Reset the input field after generating the response if needed
355
+ if user_input or st.session_state.user_suggested_input:
356
+ st.session_state.user_suggested_input = None # Reset suggested input after processing
357
+
358
 
359
  if __name__ == "__main__":
360
  main()