File size: 1,566 Bytes
ff59ed9
 
b63226a
ff59ed9
 
 
 
b63226a
ff59ed9
 
de89b73
ff59ed9
a14013e
 
 
 
a56dc07
 
 
 
 
ff59ed9
b63226a
 
 
 
 
 
 
de89b73
ff59ed9
b63226a
 
 
 
 
a763d93
b63226a
 
 
 
ff59ed9
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import streamlit as st
import os
import base64

# Title of the page
st.title("Physics Test Sets")

# Create a column layout for displaying links and PDFs
col1, col2, col3 = st.columns(3)

# Function to display a clickable download link for the PDF
def create_pdf_link(pdf_name, file_path):
    # Ensure the file name ends with '.pdf'
    if not pdf_name.endswith(".pdf"):
        pdf_name += ".pdf"
    
    if os.path.exists(file_path):
        with open(file_path, "rb") as f:
            st.download_button(label=pdf_name, data=f, file_name=pdf_name, mime="application/pdf")
    else:
        st.error(f"File {pdf_name} not found!")

# Function to display the PDF in the Streamlit page
def display_pdf(pdf_file):
    with open(pdf_file, "rb") as f:
        base64_pdf = base64.b64encode(f.read()).decode('utf-8')
    pdf_display = f'<iframe src="data:application/pdf;base64,{base64_pdf}" width="700" height="900" type="application/pdf"></iframe>'
    st.markdown(pdf_display, unsafe_allow_html=True)

# Display the first PDF link as a clickable download button in the first column
with col1:
    pdf_path_1 = os.path.join("psets", "eJackson_set1.pdf")
    create_pdf_link("Electrodynamics Test Set 1", pdf_path_1)
    if st.button("View Electrodynamics Test Set 1"):
        display_pdf(pdf_path_1)

with col2:
    pdf_path_2 = os.path.join("psets", "Griffiths_Example.pdf")
    create_pdf_link("Griffiths Example", pdf_path_2)
    if st.button("View Griffiths Example"):
        display_pdf(pdf_path_2)

# Add more columns and rows as needed for additional PDFs