samyak152002 commited on
Commit
b76b3d8
1 Parent(s): a24b0c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -3,15 +3,16 @@
3
  import streamlit as st
4
  import base64
5
  from annotations import analyze_pdf
6
- import tempfile
7
- import os
8
 
9
  def display_pdf(pdf_bytes):
10
- """Displays the PDF in the browser using an iframe."""
11
  if pdf_bytes:
 
12
  base64_pdf = base64.b64encode(pdf_bytes).decode('utf-8')
13
- pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="100%" height="800px" type="application/pdf"></iframe>'
14
- st.markdown(pdf_display, unsafe_allow_html=True)
 
 
15
  else:
16
  st.info("No annotated PDF to display.")
17
 
@@ -58,9 +59,12 @@ def main():
58
 
59
  # Option to download the annotated PDF
60
  if annotated_pdf:
61
- b64 = base64.b64encode(annotated_pdf).decode()
62
- href = f'<a href="data:application/pdf;base64,{b64}" download="annotated.pdf">📥 Download Annotated PDF</a>'
63
- st.markdown(href, unsafe_allow_html=True)
 
 
 
64
 
65
  if __name__ == "__main__":
66
  main()
 
3
  import streamlit as st
4
  import base64
5
  from annotations import analyze_pdf
 
 
6
 
7
  def display_pdf(pdf_bytes):
8
+ """Displays the PDF in the browser using an embed tag."""
9
  if pdf_bytes:
10
+ # Encode the PDF to base64
11
  base64_pdf = base64.b64encode(pdf_bytes).decode('utf-8')
12
+ pdf_display = f"""
13
+ <embed src="data:application/pdf;base64,{base64_pdf}" width="100%" height="800px" type="application/pdf">
14
+ """
15
+ st.components.v1.html(pdf_display, height=800, width=700, scrolling=True)
16
  else:
17
  st.info("No annotated PDF to display.")
18
 
 
59
 
60
  # Option to download the annotated PDF
61
  if annotated_pdf:
62
+ st.download_button(
63
+ label="📥 Download Annotated PDF",
64
+ data=annotated_pdf,
65
+ file_name="annotated.pdf",
66
+ mime="application/pdf",
67
+ )
68
 
69
  if __name__ == "__main__":
70
  main()