Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -173,33 +173,33 @@ if img_file:
|
|
173 |
openai.api_key = ""
|
174 |
|
175 |
if "openai_model" not in st.session_state:
|
176 |
-
|
177 |
|
178 |
if "messages" not in st.session_state:
|
179 |
-
|
180 |
|
181 |
for message in st.session_state.messages:
|
182 |
-
|
183 |
-
|
184 |
|
185 |
if prompt := st.chat_input("How can I help?"):
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
|
|
|
173 |
openai.api_key = ""
|
174 |
|
175 |
if "openai_model" not in st.session_state:
|
176 |
+
st.session_state["openai_model"] = "gpt-3.5-turbo"
|
177 |
|
178 |
if "messages" not in st.session_state:
|
179 |
+
st.session_state.messages = []
|
180 |
|
181 |
for message in st.session_state.messages:
|
182 |
+
with st.chat_message(message["role"]):
|
183 |
+
st.markdown(message["content"])
|
184 |
|
185 |
if prompt := st.chat_input("How can I help?"):
|
186 |
+
st.session_state.messages.append({"role": "user", "content": ocr_text+ prompt})
|
187 |
+
with st.chat_message("user"):
|
188 |
+
st.markdown(prompt)
|
189 |
|
190 |
+
with st.chat_message("assistant"):
|
191 |
+
message_placeholder = st.empty()
|
192 |
+
full_response = ""
|
193 |
+
for response in openai.ChatCompletion.create(
|
194 |
+
model=st.session_state["openai_model"],
|
195 |
+
messages=[
|
196 |
+
{"role": m["role"], "content": m["content"]}
|
197 |
+
for m in st.session_state.messages
|
198 |
+
],
|
199 |
+
stream=True,
|
200 |
+
):
|
201 |
+
full_response += response.choices[0].delta.get("content", "")
|
202 |
+
message_placeholder.markdown(full_response + "▌")
|
203 |
+
message_placeholder.markdown(full_response)
|
204 |
+
st.session_state.messages.append({"role": "assistant", "content": full_response})
|
205 |
|