gagan3012 commited on
Commit
d6d51bb
·
1 Parent(s): 45a336c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -32
app.py CHANGED
@@ -170,36 +170,36 @@ if img_file:
170
  text_file = BytesIO(ocr_text.encode())
171
  st.download_button('Download Text', text_file, file_name='ocr_text.txt')
172
 
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
 
 
170
  text_file = BytesIO(ocr_text.encode())
171
  st.download_button('Download Text', text_file, file_name='ocr_text.txt')
172
 
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