awacke1 commited on
Commit
6f0f7e9
·
verified ·
1 Parent(s): 9beab36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -3
app.py CHANGED
@@ -200,10 +200,21 @@ def get_download_link(file):
200
  def show_file_content(file_path):
201
  _, file_extension = os.path.splitext(file_path)
202
  try:
 
203
  if file_extension in ['.png', '.jpg', '.jpeg']:
204
- with open(file_path, "rb") as file:
205
- img = Image.open(file)
206
- st.image(img, caption=os.path.basename(file_path))
 
 
 
 
 
 
 
 
 
 
207
  #if file_extension in ['.png', '.jpg', '.jpeg']:
208
  # st.image(file_path)
209
  elif file_extension in ['.md', '.markdown']:
@@ -217,6 +228,11 @@ def show_file_content(file_path):
217
  elif file_extension in ['.html', '.txt']:
218
  with open(file_path, "r") as file:
219
  st.markdown(file.read(), unsafe_allow_html=True)
 
 
 
 
 
220
  except Exception as e:
221
  st.error(f"Error reading file {file_path}: {e}")
222
 
 
200
  def show_file_content(file_path):
201
  _, file_extension = os.path.splitext(file_path)
202
  try:
203
+
204
  if file_extension in ['.png', '.jpg', '.jpeg']:
205
+ image_url = file_path
206
+ # Check if the base_url needs to be prepended
207
+ if base_url and not file_path.startswith(("http://", "https://")):
208
+ image_url = os.path.join(base_url, file_path)
209
+
210
+ # Create a Markdown link to view the image
211
+ markdown_link = f"[![View Image]({image_url})]({image_url})"
212
+ st.markdown(markdown_link, unsafe_allow_html=True)
213
+
214
+ #if file_extension in ['.png', '.jpg', '.jpeg']:
215
+ # with open(file_path, "rb") as file:
216
+ # img = Image.open(file)
217
+ # st.image(img, caption=os.path.basename(file_path))
218
  #if file_extension in ['.png', '.jpg', '.jpeg']:
219
  # st.image(file_path)
220
  elif file_extension in ['.md', '.markdown']:
 
228
  elif file_extension in ['.html', '.txt']:
229
  with open(file_path, "r") as file:
230
  st.markdown(file.read(), unsafe_allow_html=True)
231
+ elif file_extension in ['.pdf']:
232
+ pdf_file = open(file_path, "rb")
233
+ base64_pdf = base64.b64encode(pdf_file.read()).decode('utf-8')
234
+ pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" type="application/pdf"></iframe>'
235
+ st.markdown(pdf_display, unsafe_allow_html=True)
236
  except Exception as e:
237
  st.error(f"Error reading file {file_path}: {e}")
238