lfoppiano commited on
Commit
c234c07
1 Parent(s): 5882371

allow rendering options using the streamlit-pdf-viewer

Browse files
Files changed (1) hide show
  1. streamlit_app.py +26 -15
streamlit_app.py CHANGED
@@ -79,6 +79,9 @@ if 'should_show_annotations' not in st.session_state:
79
  if 'pdf' not in st.session_state:
80
  st.session_state['pdf'] = None
81
 
 
 
 
82
  st.set_page_config(
83
  page_title="Scientific Document Insights Q/A",
84
  page_icon="📝",
@@ -302,9 +305,15 @@ question = st.chat_input(
302
 
303
  with st.sidebar:
304
  st.header("Settings")
305
- mode = st.radio("Query mode", ("LLM", "Embeddings"), disabled=not uploaded_file, index=0, horizontal=True,
306
- help="LLM will respond the question, Embedding will show the "
307
- "paragraphs relevant to the question in the paper.")
 
 
 
 
 
 
308
 
309
  # Add a checkbox for showing annotations
310
  # st.session_state['show_annotations'] = st.checkbox("Show annotations", value=True)
@@ -327,6 +336,12 @@ with st.sidebar:
327
  'The LLM responses undergo post-processing to extract <span style="color:orange">physical quantities, measurements</span>, and <span style="color:green">materials</span> mentions.',
328
  unsafe_allow_html=True)
329
 
 
 
 
 
 
 
330
  st.divider()
331
 
332
  st.header("Documentation")
@@ -462,15 +477,11 @@ with right_column:
462
 
463
  with left_column:
464
  if st.session_state['binary']:
465
- # if st.session_state['should_show_annotations']:
466
- pdf_viewer(input=st.session_state['binary'],
467
- width=600,
468
- height=800,
469
- annotation_outline_size=2,
470
- annotations=st.session_state['annotations'])
471
- # else:
472
- # pdf_viewer(input=st.session_state['binary'],
473
- # width=600,
474
- # height=800,
475
- # annotation_outline_size=2
476
- # )
 
79
  if 'pdf' not in st.session_state:
80
  st.session_state['pdf'] = None
81
 
82
+ if 'pdf_rendering' not in st.session_state:
83
+ st.session_state['pdf_rendering'] = None
84
+
85
  st.set_page_config(
86
  page_title="Scientific Document Insights Q/A",
87
  page_icon="📝",
 
305
 
306
  with st.sidebar:
307
  st.header("Settings")
308
+ mode = st.radio(
309
+ "Query mode",
310
+ ("LLM", "Embeddings"),
311
+ disabled=not uploaded_file,
312
+ index=0,
313
+ horizontal=True,
314
+ help="LLM will respond the question, Embedding will show the "
315
+ "paragraphs relevant to the question in the paper."
316
+ )
317
 
318
  # Add a checkbox for showing annotations
319
  # st.session_state['show_annotations'] = st.checkbox("Show annotations", value=True)
 
336
  'The LLM responses undergo post-processing to extract <span style="color:orange">physical quantities, measurements</span>, and <span style="color:green">materials</span> mentions.',
337
  unsafe_allow_html=True)
338
 
339
+ st.session_state['pdf_rendering'] = st.radio(
340
+ "PDF rendering mode",
341
+ {"PDF.JS", "Native browser engine"},
342
+ disabled=not uploaded_file,
343
+ )
344
+
345
  st.divider()
346
 
347
  st.header("Documentation")
 
477
 
478
  with left_column:
479
  if st.session_state['binary']:
480
+ pdf_viewer(
481
+ input=st.session_state['binary'],
482
+ width=600,
483
+ height=800,
484
+ annotation_outline_size=2,
485
+ annotations=st.session_state['annotations'],
486
+ rendering='unwrap' if st.session_state['pdf_rendering'] == 'PDF.JS' else 'legacy_embed'
487
+ )