Charles Kabui
commited on
Commit
·
4575a6f
1
Parent(s):
22a5952
layout
Browse files- analysis.ipynb +41 -4
- app.py +11 -13
analysis.ipynb
CHANGED
|
@@ -11,7 +11,7 @@
|
|
| 11 |
},
|
| 12 |
{
|
| 13 |
"cell_type": "code",
|
| 14 |
-
"execution_count":
|
| 15 |
"metadata": {},
|
| 16 |
"outputs": [],
|
| 17 |
"source": [
|
|
@@ -301,9 +301,46 @@
|
|
| 301 |
},
|
| 302 |
{
|
| 303 |
"cell_type": "code",
|
| 304 |
-
"execution_count":
|
| 305 |
"metadata": {},
|
| 306 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
"source": [
|
| 308 |
"from app import app\n",
|
| 309 |
"\n",
|
|
@@ -350,7 +387,7 @@
|
|
| 350 |
"name": "python",
|
| 351 |
"nbconvert_exporter": "python",
|
| 352 |
"pygments_lexer": "ipython3",
|
| 353 |
-
"version": "3.
|
| 354 |
}
|
| 355 |
},
|
| 356 |
"nbformat": 4,
|
|
|
|
| 11 |
},
|
| 12 |
{
|
| 13 |
"cell_type": "code",
|
| 14 |
+
"execution_count": 1,
|
| 15 |
"metadata": {},
|
| 16 |
"outputs": [],
|
| 17 |
"source": [
|
|
|
|
| 301 |
},
|
| 302 |
{
|
| 303 |
"cell_type": "code",
|
| 304 |
+
"execution_count": 5,
|
| 305 |
"metadata": {},
|
| 306 |
+
"outputs": [
|
| 307 |
+
{
|
| 308 |
+
"name": "stdout",
|
| 309 |
+
"output_type": "stream",
|
| 310 |
+
"text": [
|
| 311 |
+
"Running on local URL: http://127.0.0.1:7860\n",
|
| 312 |
+
"\n",
|
| 313 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
| 314 |
+
]
|
| 315 |
+
},
|
| 316 |
+
{
|
| 317 |
+
"data": {
|
| 318 |
+
"text/html": [
|
| 319 |
+
"<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
| 320 |
+
],
|
| 321 |
+
"text/plain": [
|
| 322 |
+
"<IPython.core.display.HTML object>"
|
| 323 |
+
]
|
| 324 |
+
},
|
| 325 |
+
"metadata": {},
|
| 326 |
+
"output_type": "display_data"
|
| 327 |
+
},
|
| 328 |
+
{
|
| 329 |
+
"name": "stdout",
|
| 330 |
+
"output_type": "stream",
|
| 331 |
+
"text": [
|
| 332 |
+
"Keyboard interruption in main thread... closing server.\n"
|
| 333 |
+
]
|
| 334 |
+
},
|
| 335 |
+
{
|
| 336 |
+
"data": {
|
| 337 |
+
"text/plain": []
|
| 338 |
+
},
|
| 339 |
+
"execution_count": 5,
|
| 340 |
+
"metadata": {},
|
| 341 |
+
"output_type": "execute_result"
|
| 342 |
+
}
|
| 343 |
+
],
|
| 344 |
"source": [
|
| 345 |
"from app import app\n",
|
| 346 |
"\n",
|
|
|
|
| 387 |
"name": "python",
|
| 388 |
"nbconvert_exporter": "python",
|
| 389 |
"pygments_lexer": "ipython3",
|
| 390 |
+
"version": "3.1.0"
|
| 391 |
}
|
| 392 |
},
|
| 393 |
"nbformat": 4,
|
app.py
CHANGED
|
@@ -5,7 +5,7 @@ from pdf2image import convert_from_path, convert_from_bytes
|
|
| 5 |
|
| 6 |
def similarity_fn(document_image_1, document_image_2):
|
| 7 |
xxx = 'BOTH' if document_image_1 and document_image_2 else 'ONE' if document_image_1 or document_image_2 else 'NONE'
|
| 8 |
-
return xxx
|
| 9 |
|
| 10 |
def load_image(filename, page = 0):
|
| 11 |
try:
|
|
@@ -61,11 +61,11 @@ def document_view(document_number: int):
|
|
| 61 |
|
| 62 |
def app():
|
| 63 |
title = 'Document Similarity Search Using Visual Layout Features'
|
| 64 |
-
description = "<h2>
|
| 65 |
-
article = "<h4>More details, Links about this! - Document Similarity Search using Detectron2<h4>"
|
| 66 |
css = '''
|
| 67 |
image { max-height="86vh" !important; }
|
| 68 |
.center { display: flex; flex: 1 1 auto; align-items: center; align-content: center; justify-content: center; justify-items: center; }
|
|
|
|
| 69 |
'''
|
| 70 |
with gr.Blocks(title=title, css=css) as app:
|
| 71 |
with gr.Row():
|
|
@@ -75,17 +75,15 @@ def app():
|
|
| 75 |
document_1_image = document_view(1)
|
| 76 |
with gr.Column():
|
| 77 |
document_2_image = document_view(2)
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
| 82 |
submit.click(
|
| 83 |
-
fn=
|
| 84 |
inputs=[document_1_image, document_2_image],
|
| 85 |
outputs=[similarity_output])
|
| 86 |
-
|
| 87 |
-
# threshold.change(
|
| 88 |
-
# fn=lambda image, threshold: similarity_fn(image, threshold, just_image=False),
|
| 89 |
-
# inputs=[document_1, threshold],
|
| 90 |
-
# outputs=[annotated_document_image, message])
|
| 91 |
return app.launch(debug=True)
|
|
|
|
| 5 |
|
| 6 |
def similarity_fn(document_image_1, document_image_2):
|
| 7 |
xxx = 'BOTH' if document_image_1 and document_image_2 else 'ONE' if document_image_1 or document_image_2 else 'NONE'
|
| 8 |
+
return gr.HTML(f'<pre>Similarity between the two documents: {xxx}<pre>', visible=True)
|
| 9 |
|
| 10 |
def load_image(filename, page = 0):
|
| 11 |
try:
|
|
|
|
| 61 |
|
| 62 |
def app():
|
| 63 |
title = 'Document Similarity Search Using Visual Layout Features'
|
| 64 |
+
description = f"<h2>{title}<h2>"
|
|
|
|
| 65 |
css = '''
|
| 66 |
image { max-height="86vh" !important; }
|
| 67 |
.center { display: flex; flex: 1 1 auto; align-items: center; align-content: center; justify-content: center; justify-items: center; }
|
| 68 |
+
.hr { width: 100%; display: block; padding: 0; margin: 0; background: gray; height: 4px; border: none; }
|
| 69 |
'''
|
| 70 |
with gr.Blocks(title=title, css=css) as app:
|
| 71 |
with gr.Row():
|
|
|
|
| 75 |
document_1_image = document_view(1)
|
| 76 |
with gr.Column():
|
| 77 |
document_2_image = document_view(2)
|
| 78 |
+
gr.HTML('<hr/>', elem_classes=['hr'])
|
| 79 |
+
with gr.Row(elem_classes=['center']):
|
| 80 |
+
with gr.Column():
|
| 81 |
+
submit = gr.Button(value="Similarity", variant="primary")
|
| 82 |
+
reset = gr.Button(value="Reset", variant="secondary")
|
| 83 |
+
with gr.Column():
|
| 84 |
+
similarity_output = gr.HTML(visible=False)
|
| 85 |
submit.click(
|
| 86 |
+
fn=similarity_fn,
|
| 87 |
inputs=[document_1_image, document_2_image],
|
| 88 |
outputs=[similarity_output])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
return app.launch(debug=True)
|