vishwask commited on
Commit
4471a1a
1 Parent(s): dfd0a9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -25
app.py CHANGED
@@ -116,10 +116,7 @@ st.session_state["llm_model"] = model_name_or_path
116
 
117
  if "messages" not in st.session_state:
118
  st.session_state.messages = []
119
- if "image_displayed" not in st.session_state:
120
- st.session_state.image_displayed = False
121
- if "sound_played" not in st.session_state:
122
- st.session_state.sound_played = False
123
 
124
  for message in st.session_state.messages:
125
  with st.chat_message(message["role"]):
@@ -171,11 +168,8 @@ if prompt := st.chat_input("How can I help you today?"):
171
  pix.save(output_image, "png")
172
  pdf_document.close()
173
  pdf_page_to_image('/home/user/app/pdf2image/output.pdf', page_number, '/home/user/app/pdf2image/output.png')
174
- # image = Image.open('/home/user/app/pdf2image/output.png')
175
- # st.image(image)
176
- # st.session_state.image_displayed = True
177
- path = '/home/user/app/pdf2image/output.png'
178
- return path
179
 
180
  def generate_audio():
181
  sound_file = BytesIO()
@@ -190,25 +184,11 @@ if prompt := st.chat_input("How can I help you today?"):
190
  message_placeholder.markdown(full_response + "▌")
191
  message_placeholder.markdown(full_response)
192
 
193
- def display_image(image_path):
194
- """Displays an image at the given path."""
195
- st.image(image_path)
196
-
197
-
198
- # Create a button to display the image.
199
- if st.button("Display Image"):
200
- # Get the image path from the session state dictionary.
201
- image_path = st.session_state.get("image_path")
202
 
203
- # If the image path is not set, set it to the default image path.
204
- if image_path is None:
205
- image_path = generate_pdf()
206
 
207
- # Display the image.
208
- display_image(image_path)
209
 
210
- # Store the image path in the session state dictionary.
211
- st.session_state["image_path"] = image_path
212
 
213
  st.session_state.messages.append({"role": "assistant", "content": full_response})
214
 
 
116
 
117
  if "messages" not in st.session_state:
118
  st.session_state.messages = []
119
+
 
 
 
120
 
121
  for message in st.session_state.messages:
122
  with st.chat_message(message["role"]):
 
168
  pix.save(output_image, "png")
169
  pdf_document.close()
170
  pdf_page_to_image('/home/user/app/pdf2image/output.pdf', page_number, '/home/user/app/pdf2image/output.png')
171
+ image = Image.open('/home/user/app/pdf2image/output.png')
172
+ st.image(image)
 
 
 
173
 
174
  def generate_audio():
175
  sound_file = BytesIO()
 
184
  message_placeholder.markdown(full_response + "▌")
185
  message_placeholder.markdown(full_response)
186
 
187
+ st.button('Reference',on_click=generate_pdf)
188
+ st.button(':speaker:',on_click=generate_audio)
 
 
 
 
 
 
 
189
 
 
 
 
190
 
 
 
191
 
 
 
192
 
193
  st.session_state.messages.append({"role": "assistant", "content": full_response})
194