Spaces:
Running
Running
make the annotations injection working
Browse files- streamlit_app.py +26 -5
streamlit_app.py
CHANGED
@@ -347,9 +347,22 @@ if uploaded_file and not st.session_state.loaded_embeddings:
|
|
347 |
|
348 |
# timestamp = datetime.utcnow()
|
349 |
|
350 |
-
|
351 |
-
|
352 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
|
354 |
with right_column:
|
355 |
# css = '''
|
@@ -396,9 +409,13 @@ with right_column:
|
|
396 |
_, text_response, coordinates = st.session_state['rqa'][model].query_document(question,
|
397 |
st.session_state.doc_id,
|
398 |
context_size=context_size)
|
399 |
-
|
400 |
-
{"page": coo[0], "x": coo[1], "y": coo[2], "width": coo[3], "height": coo[4], "color": "
|
401 |
coordinates for c in coord]]
|
|
|
|
|
|
|
|
|
402 |
# with left_column:
|
403 |
# pdf_viewer(input=st.session_state['binary'], annotations=st.session_state['annotations'], key=1)
|
404 |
|
@@ -427,3 +444,7 @@ with right_column:
|
|
427 |
|
428 |
elif st.session_state.loaded_embeddings and st.session_state.doc_id:
|
429 |
play_old_messages()
|
|
|
|
|
|
|
|
|
|
347 |
|
348 |
# timestamp = datetime.utcnow()
|
349 |
|
350 |
+
def rgb_to_hex(rgb):
|
351 |
+
return "#{:02x}{:02x}{:02x}".format(*rgb)
|
352 |
+
|
353 |
+
def generate_color_gradient(num_elements):
|
354 |
+
# Define warm and cold colors in RGB format
|
355 |
+
warm_color = (255, 165, 0) # Orange
|
356 |
+
cold_color = (0, 0, 255) # Blue
|
357 |
+
|
358 |
+
# Generate a linear gradient of colors
|
359 |
+
color_gradient = [
|
360 |
+
rgb_to_hex(tuple(int(warm * (1 - i/num_elements) + cold * (i/num_elements)) for warm, cold in zip(warm_color, cold_color)))
|
361 |
+
for i in range(num_elements)
|
362 |
+
]
|
363 |
+
|
364 |
+
return color_gradient
|
365 |
+
|
366 |
|
367 |
with right_column:
|
368 |
# css = '''
|
|
|
409 |
_, text_response, coordinates = st.session_state['rqa'][model].query_document(question,
|
410 |
st.session_state.doc_id,
|
411 |
context_size=context_size)
|
412 |
+
annotations = [
|
413 |
+
{"page": coo[0], "x": coo[1], "y": coo[2], "width": coo[3], "height": coo[4], "color": "grey"} for coo in [c.split(",") for coord in
|
414 |
coordinates for c in coord]]
|
415 |
+
gradients = generate_color_gradient(len(annotations))
|
416 |
+
for i, color in enumerate(gradients):
|
417 |
+
annotations[i]['color'] = color
|
418 |
+
st.session_state['annotations'] = annotations
|
419 |
# with left_column:
|
420 |
# pdf_viewer(input=st.session_state['binary'], annotations=st.session_state['annotations'], key=1)
|
421 |
|
|
|
444 |
|
445 |
elif st.session_state.loaded_embeddings and st.session_state.doc_id:
|
446 |
play_old_messages()
|
447 |
+
|
448 |
+
with left_column:
|
449 |
+
if st.session_state['binary']:
|
450 |
+
pdf_viewer(input=st.session_state['binary'], width=600, height=800, annotations=st.session_state['annotations'])
|