Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement % resize #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ beautifulsoup4
lxml
grobid-client-python
watchdog
streamlit-pdf-viewer==0.0.20
streamlit-pdf-viewer==0.0.21-rc0
55 changes: 40 additions & 15 deletions streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
if 'page_selection' not in st.session_state:
st.session_state['page_selection'] = []

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

st.set_page_config(
page_title="Structure vision",
page_icon="",
Expand Down Expand Up @@ -88,8 +91,14 @@

st.header("Height and width")
resolution_boost = st.slider(label="Resolution boost", min_value=1, max_value=10, value=1)
width = st.slider(label="PDF width", min_value=100, max_value=1000, value=700)
height = st.slider(label="PDF height", min_value=-1, max_value=10000, value=-1)
st.session_state['size_in_pixel'] = st.toggle('Size in pixels', value=True,
disabled=not st.session_state['uploaded'])
if st.session_state['size_in_pixel']:
width = st.slider(label="PDF width", min_value=100, max_value=1000, value=700)
height = st.slider(label="PDF height", min_value=-1, max_value=10000, value=-1)
else:
width = st.slider(label="PDF width", min_value=-1, max_value=100, value=100)
width = str(width) + "%"

st.header("Page Selection")
placeholder = st.empty()
Expand Down Expand Up @@ -154,6 +163,7 @@ def init_grobid():
'affiliation': 'Affiliation'
}


def my_custom_annotation_handler(annotation):
output_json = {
"Index": annotation['index'],
Expand All @@ -163,6 +173,7 @@ def my_custom_annotation_handler(annotation):

annotations_component.json(output_json)


def get_file_hash(fname):
hash_md5 = blake2b()
with open(fname, "rb") as f:
Expand Down Expand Up @@ -245,19 +256,33 @@ def get_file_hash(fname):
if not highlight_affiliations:
annotations = list(filter(lambda a: a['type'] != 'affiliation', annotations))

if height > -1:
pdf_viewer(
input=st.session_state['binary'],
width=width,
height=height,
annotations=annotations,
pages_vertical_spacing=pages_vertical_spacing,
annotation_outline_size=annotation_thickness,
pages_to_render=st.session_state['page_selection'],
render_text=enable_text,
resolution_boost=resolution_boost,
on_annotation_click=my_custom_annotation_handler
)
if st.session_state['size_in_pixel']:
if height > -1:
pdf_viewer(
input=st.session_state['binary'],
width=width,
height=height,
annotations=annotations,
pages_vertical_spacing=pages_vertical_spacing,
annotation_outline_size=annotation_thickness,
pages_to_render=st.session_state['page_selection'],
render_text=enable_text,
resolution_boost=resolution_boost,
on_annotation_click=my_custom_annotation_handler
)
else:
pdf_viewer(
input=st.session_state['binary'],
width=width,
annotations=annotations,
pages_vertical_spacing=pages_vertical_spacing,
annotation_outline_size=annotation_thickness,
pages_to_render=st.session_state['page_selection'],
render_text=enable_text,
resolution_boost=resolution_boost,
on_annotation_click=my_custom_annotation_handler
)

else:
pdf_viewer(
input=st.session_state['binary'],
Expand Down
Loading