Skip to content

Commit

Permalink
allow rendering options using the streamlit-pdf-viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
lfoppiano committed Jan 29, 2024
1 parent 5882371 commit c234c07
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
if 'pdf' not in st.session_state:
st.session_state['pdf'] = None

if 'pdf_rendering' not in st.session_state:
st.session_state['pdf_rendering'] = None

st.set_page_config(
page_title="Scientific Document Insights Q/A",
page_icon="📝",
Expand Down Expand Up @@ -302,9 +305,15 @@ def play_old_messages():

with st.sidebar:
st.header("Settings")
mode = st.radio("Query mode", ("LLM", "Embeddings"), disabled=not uploaded_file, index=0, horizontal=True,
help="LLM will respond the question, Embedding will show the "
"paragraphs relevant to the question in the paper.")
mode = st.radio(
"Query mode",
("LLM", "Embeddings"),
disabled=not uploaded_file,
index=0,
horizontal=True,
help="LLM will respond the question, Embedding will show the "
"paragraphs relevant to the question in the paper."
)

# Add a checkbox for showing annotations
# st.session_state['show_annotations'] = st.checkbox("Show annotations", value=True)
Expand All @@ -327,6 +336,12 @@ def play_old_messages():
'The LLM responses undergo post-processing to extract <span style="color:orange">physical quantities, measurements</span>, and <span style="color:green">materials</span> mentions.',
unsafe_allow_html=True)

st.session_state['pdf_rendering'] = st.radio(
"PDF rendering mode",
{"PDF.JS", "Native browser engine"},
disabled=not uploaded_file,
)

st.divider()

st.header("Documentation")
Expand Down Expand Up @@ -462,15 +477,11 @@ def generate_color_gradient(num_elements):

with left_column:
if st.session_state['binary']:
# if st.session_state['should_show_annotations']:
pdf_viewer(input=st.session_state['binary'],
width=600,
height=800,
annotation_outline_size=2,
annotations=st.session_state['annotations'])
# else:
# pdf_viewer(input=st.session_state['binary'],
# width=600,
# height=800,
# annotation_outline_size=2
# )
pdf_viewer(
input=st.session_state['binary'],
width=600,
height=800,
annotation_outline_size=2,
annotations=st.session_state['annotations'],
rendering='unwrap' if st.session_state['pdf_rendering'] == 'PDF.JS' else 'legacy_embed'
)

0 comments on commit c234c07

Please sign in to comment.