lvwerra HF Staff commited on
Commit
157b326
·
1 Parent(s): 26a719e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ PDF_WIDTH = 700
4
+ PDF_HEIGHT = 1000
5
+ PDF_PATH = "./some_pdf.pdf"
6
+
7
+ def display_pdf(file):
8
+ # Opening file from file path
9
+ with open(file, "rb") as f:
10
+ base64_pdf = base64.b64encode(f.read()).decode('utf-8')
11
+
12
+ # Embedding PDF in HTML
13
+ pdf_display = F'<iframe src="data:application/pdf;base64,{base64_pdf}" width="{PDF_WIDTH}" height="{PDF_HEIGHT}" type="application/pdf"></iframe>'
14
+
15
+ # Displaying File
16
+ st.markdown(pdf_display, unsafe_allow_html=True)
17
+
18
+ st.title("Welcome to PDF viewer 2000!")
19
+
20
+ st.markdown("## This is a markdown title")
21
+
22
+ st.markdown("I want to display the _best_ PDF of my **collection**!")
23
+
24
+ st.markdown("Learn more what a pdf is [here](https://en.wikipedia.org/wiki/PDF).")
25
+
26
+ st.sidebar.markdown("_Hint_: you can also display things on the sidebar.")
27
+
28
+ display_pdf(PDF_PATH)