lfoppiano commited on
Commit
66819b5
1 Parent(s): c07b97b

fix coordinates colors when working with chunks

Browse files
document_qa/document_qa_engine.py CHANGED
@@ -63,8 +63,6 @@ class TextMerger:
63
  new_coordinates.append(current_coordinates)
64
  current_texts = []
65
  current_coordinates = []
66
- else:
67
- print("bao")
68
 
69
  if len(current_texts) > 0:
70
  new_passages.append(current_texts)
 
63
  new_coordinates.append(current_coordinates)
64
  current_texts = []
65
  current_coordinates = []
 
 
66
 
67
  if len(current_texts) > 0:
68
  new_passages.append(current_texts)
streamlit_app.py CHANGED
@@ -430,16 +430,14 @@ with right_column:
430
  _, text_response, coordinates = st.session_state['rqa'][model].query_document(question,
431
  st.session_state.doc_id,
432
  context_size=context_size)
433
- annotations = [
434
- GrobidAggregationProcessor.box_to_dict(coo) for coo in [c.split(",") for coord in
435
- coordinates for c in coord]
436
- ]
437
  gradients = generate_color_gradient(len(annotations))
438
  for i, color in enumerate(gradients):
439
- annotations[i]['color'] = color
440
- st.session_state['annotations'] = annotations
441
- # with left_column:
442
- # pdf_viewer(input=st.session_state['binary'], annotations=st.session_state['annotations'], key=1)
443
 
444
  if not text_response:
445
  st.error("Something went wrong. Contact Luca Foppiano ([email protected]) to report the issue.")
@@ -470,7 +468,14 @@ with right_column:
470
  with left_column:
471
  if st.session_state['binary']:
472
  if st.session_state['should_show_annotations']:
473
- pdf_viewer(input=st.session_state['binary'], width=600, height=800,
 
 
 
474
  annotations=st.session_state['annotations'])
475
  else:
476
- pdf_viewer(input=st.session_state['binary'], width=600, height=800)
 
 
 
 
 
430
  _, text_response, coordinates = st.session_state['rqa'][model].query_document(question,
431
  st.session_state.doc_id,
432
  context_size=context_size)
433
+
434
+ annotations = [[GrobidAggregationProcessor.box_to_dict([cs for cs in c.split(",")]) for c in coord_doc]
435
+ for coord_doc in coordinates]
 
436
  gradients = generate_color_gradient(len(annotations))
437
  for i, color in enumerate(gradients):
438
+ for annotation in annotations[i]:
439
+ annotation['color'] = color
440
+ st.session_state['annotations'] = [annotation for annotation_doc in annotations for annotation in annotation_doc]
 
441
 
442
  if not text_response:
443
  st.error("Something went wrong. Contact Luca Foppiano ([email protected]) to report the issue.")
 
468
  with left_column:
469
  if st.session_state['binary']:
470
  if st.session_state['should_show_annotations']:
471
+ pdf_viewer(input=st.session_state['binary'],
472
+ width=600,
473
+ height=800,
474
+ annotation_outline_size=2,
475
  annotations=st.session_state['annotations'])
476
  else:
477
+ pdf_viewer(input=st.session_state['binary'],
478
+ width=600,
479
+ height=800,
480
+ annotation_outline_size=2
481
+ )