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