Spaces:
Runtime error
Runtime error
Commit ·
a5aa13d
1
Parent(s): a83fefd
Update app.py
Browse files
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="
|
| 30 |
)
|
| 31 |
-
reply = chat.choices[0].
|
| 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 |
-
|
|
|
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
if
|
| 46 |
-
st.write("
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Center and enlarge the send button
|
| 51 |
col1, col2, col3 = st.columns([1, 3, 1])
|
| 52 |
with col2:
|
| 53 |
-
|
|
|
|
| 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)
|