lfoppiano / streamlit-pdf-viewer

Streamlit PDF viewer
https://structure-vision.streamlit.app/
Apache License 2.0
62 stars 3 forks source link

[wip] Show annotations #13

Closed t29mato closed 6 months ago

t29mato commented 6 months ago

https://github.com/lfoppiano/streamlit-pdf-viewer/issues/3

t29mato commented 6 months ago

@lfoppiano

image

Code still needs refactoring, but I think the functionality has been implemented to use it as demonstration.

lfoppiano commented 6 months ago

is it possible to add two more methods:

set_annotations(annotations=[]): set the annotations and draw them on the PDF clear_annotations(): remove the annotations from the pdf

lfoppiano commented 6 months ago

Another point, every time we create a new pdf_viewer(), a new pdf object is added, we might need to deal with it later.

lfoppiano commented 6 months ago

The annotation are working here, but I cannot see them when integrated into a streamlit app https://github.com/lfoppiano/document-qa.

You can reproduce it as follow:

  1. checkout the branch add-pdf-viewer of https://github.com/lfoppiano/document-qa
  2. pip uninstall streamlit-pdf-viewer
  3. pip install -e path_where_your_pdfviewer_is
  4. Run the document-qa app
  5. slide the chunk size to -1
  6. upload a PDF (in this version the pdf is not visualised at first)
  7. Ask one question (nothing will happen in the left column, it's normal)
  8. Ask a second question (the pdf will appear without any annotation)
lfoppiano commented 6 months ago

I've created a new project to test the integration of this component into a streamlit application. It should be much easier for you to test than with document-qa: https://github.com/lfoppiano/pdf-struct/

You should have received an invitation to join.

Don't forget to

pip install -e git+https://github.com/lfoppiano/streamlit-pdf-viewer

After running pip -r requirements

lfoppiano commented 6 months ago

OK. I managed to understand what I did wrong. I forgot to rebuild the frontend. After rebuilding the annotations are pushed to the frontend, but, something is happening and even with 24 annotations, the browser crashes...

lfoppiano commented 6 months ago

The issue happens when no width and height are passed. Can you calculate them from the javascript part?