Spaces:
Runtime error
Runtime error
Added checkbox for OpenAI integration
Browse files
app.py
CHANGED
@@ -120,7 +120,7 @@ def launch_bot():
|
|
120 |
# with st.chat_message("user"):
|
121 |
# st.write("Convert to Audio ๐")
|
122 |
text = " :blue[Convert to Audio ] ๐ "
|
123 |
-
|
124 |
with st.expander(text, expanded=False):
|
125 |
sound_file = BytesIO()
|
126 |
tts = gTTS(response, lang='en')
|
@@ -128,24 +128,27 @@ def launch_bot():
|
|
128 |
|
129 |
st.audio(sound_file)
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
134 |
# Change this to include OpenAI_API key
|
135 |
# Function to get the assistant's response
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
|
150 |
|
151 |
if __name__ == "__main__":
|
|
|
120 |
# with st.chat_message("user"):
|
121 |
# st.write("Convert to Audio ๐")
|
122 |
text = " :blue[Convert to Audio ] ๐ "
|
123 |
+
# Converts Response to Audio
|
124 |
with st.expander(text, expanded=False):
|
125 |
sound_file = BytesIO()
|
126 |
tts = gTTS(response, lang='en')
|
|
|
128 |
|
129 |
st.audio(sound_file)
|
130 |
|
131 |
+
agree = st.checkbox('Escalate this response to Premium')
|
132 |
+
|
133 |
+
if agree:
|
134 |
+
Print('OpenAI, Oh Great!')
|
135 |
+
with st.chat_message("assistant"):
|
136 |
+
with st.spinner("Thinking..."):
|
137 |
# Change this to include OpenAI_API key
|
138 |
# Function to get the assistant's response
|
139 |
+
completion = openai.ChatCompletion.create(
|
140 |
+
model="gpt-3.5-turbo",
|
141 |
+
messages=[
|
142 |
+
{"role": "system", "content": "You are a helpful Natural Farming assistant with extensive experience in accessible science and technical writing, and the heart of a teacher."},
|
143 |
+
{"role": "user", "content": prompt3}
|
144 |
+
]
|
145 |
+
)
|
146 |
+
|
147 |
+
response = completion.choices[0].message
|
148 |
+
st.write(response)
|
149 |
+
|
150 |
+
message = {"role": "assistant", "content": response}
|
151 |
+
st.session_state.messages.append(message)
|
152 |
|
153 |
|
154 |
if __name__ == "__main__":
|