Theodore1211 commited on
Commit
a5aa13d
·
1 Parent(s): a83fefd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -9
app.py CHANGED
@@ -26,9 +26,9 @@ def chatbot(input):
26
  if input:
27
  messages.append({"role": "user", "content": input})
28
  chat = openai.ChatCompletion.create(
29
- model="gpt-3.5-turbo", messages=messages
30
  )
31
- reply = chat.choices[0].message.content
32
  messages.append({"role": "assistant", "content": reply})
33
  return reply
34
 
@@ -39,19 +39,31 @@ st.markdown("<h1 style='text-align: center; font-size: 36px;'>Ask me about food
39
 
40
  # Create an expander for the chat content
41
  with st.expander("Chat"):
42
- input_text = st.text_input("Type your question or select a suggestion below:", key="input")
 
43
 
44
- # Display suggested questions when the user clicks on the input text field
45
- if not input_text:
46
- st.write("Suggested Questions:")
47
- for question in suggested_questions:
48
- st.write("- " + question)
 
 
 
 
49
 
50
  # Center and enlarge the send button
51
  col1, col2, col3 = st.columns([1, 3, 1])
52
  with col2:
53
- send = st.button("Send", key="send")
 
54
 
55
  if send:
56
  response = chatbot(input_text)
57
  st.write(response)
 
 
 
 
 
 
 
26
  if input:
27
  messages.append({"role": "user", "content": input})
28
  chat = openai.ChatCompletion.create(
29
+ model="text-davinci-002", messages=messages
30
  )
31
+ reply = chat.choices[0].text
32
  messages.append({"role": "assistant", "content": reply})
33
  return reply
34
 
 
39
 
40
  # Create an expander for the chat content
41
  with st.expander("Chat"):
42
+ # Create a selectbox for suggested questions
43
+ question = st.selectbox("Select a suggested question or enter a new question", [""] + suggested_questions)
44
 
45
+ # If user selects a suggested question, show the question and disable text input
46
+ if question:
47
+ st.write(f"You selected: {question}")
48
+ input_text = question
49
+ text_input_disabled = True
50
+ else:
51
+ # If user enters a new question, enable text input
52
+ input_text = st.text_input("Enter your question here", key="input")
53
+ text_input_disabled = False
54
 
55
  # Center and enlarge the send button
56
  col1, col2, col3 = st.columns([1, 3, 1])
57
  with col2:
58
+ # Disable send button if no input is given
59
+ send = st.button("Send", key="send", disabled=(not input_text))
60
 
61
  if send:
62
  response = chatbot(input_text)
63
  st.write(response)
64
+
65
+ # Disable suggested questions if user enters a new question
66
+ if not text_input_disabled:
67
+ st.write("Suggested Questions:")
68
+ for question in suggested_questions:
69
+ st.write("- " + question)