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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -28
app.py CHANGED
@@ -302,13 +302,7 @@ def main():
302
 
303
  teapot_ai = TeapotAI(documents=[], settings=TeapotAISettings(rag_num_results=3, log_level="debug"))
304
 
305
-
306
- if "messages" not in st.session_state:
307
- st.session_state.messages = [{"role": "assistant", "content": "Hi, I am Teapot AI, how can I help you?"}]
308
-
309
- for message in st.session_state.messages:
310
- with st.chat_message(message["role"]):
311
- st.markdown(message["content"])
312
 
313
  list1 = ["Tell me about teapotllm", "What is Teapot AI?","What devices can Teapot run on?","Who are you?"]
314
  list2 = ["Who invented quantum mechanics?", "Who are the authors of attention is all you need", "Tell me about popular places to travel in France","Summarize the book irobot", "Explain artificial intelligence","what are the key ingredients of bouillabaisse"]
@@ -321,40 +315,35 @@ def 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()
 
302
 
303
  teapot_ai = TeapotAI(documents=[], settings=TeapotAISettings(rag_num_results=3, log_level="debug"))
304
 
305
+
 
 
 
 
 
 
306
 
307
  list1 = ["Tell me about teapotllm", "What is Teapot AI?","What devices can Teapot run on?","Who are you?"]
308
  list2 = ["Who invented quantum mechanics?", "Who are the authors of attention is all you need", "Tell me about popular places to travel in France","Summarize the book irobot", "Explain artificial intelligence","what are the key ingredients of bouillabaisse"]
 
315
  choice2 = random.choice(list2)
316
  choice3 = random.choice(list3)
317
 
 
 
 
 
 
 
318
  s1, s2, s3 = st.columns([1, 1, 1])
319
 
320
+ user_suggested_input = None
321
+
322
  with s1:
323
  if st.button(choice1, use_container_width=True):
324
+ user_suggested_input = choice1
325
 
326
  with s2:
327
  if st.button(choice2, use_container_width=True):
328
+ user_suggested_input = choice2
329
 
330
  with s3:
331
  if st.button(choice3, use_container_width=True):
332
+ user_suggested_input = choice3
333
+
334
+ if "messages" not in st.session_state:
335
+ st.session_state.messages = [{"role": "assistant", "content": "Hi, I am Teapot AI, how can I help you?"}]
336
 
337
+ for message in st.session_state.messages:
338
+ with st.chat_message(message["role"]):
339
+ st.markdown(message["content"])
340
 
341
+ user_input = st.chat_input("Ask me anything")
342
+
343
+ if user_input:
344
  with st.spinner('Generating Response...'):
345
+ response = handle_chat(user_prompt, user_suggested_input or user_input, teapot_ai)
346
+
 
 
 
 
 
347
 
348
  if __name__ == "__main__":
349
  main()