Commit
Β·
febfebc
1
Parent(s):
b66d03f
refactor app.py
Browse files
app.py
CHANGED
|
@@ -46,7 +46,6 @@ CSS = """
|
|
| 46 |
--link-hover: #2b6cb0;
|
| 47 |
--content-width: 1200px;
|
| 48 |
}
|
| 49 |
-
|
| 50 |
body {
|
| 51 |
display: flex;
|
| 52 |
justify-content: center;
|
|
@@ -54,7 +53,6 @@ body {
|
|
| 54 |
color: var(--text-color);
|
| 55 |
font-family: Arial, sans-serif;
|
| 56 |
}
|
| 57 |
-
|
| 58 |
.upload-section {
|
| 59 |
width: 100%;
|
| 60 |
margin: 0 auto 30px;
|
|
@@ -63,7 +61,6 @@ body {
|
|
| 63 |
border-radius: 8px;
|
| 64 |
box-shadow: var(--shadow);
|
| 65 |
}
|
| 66 |
-
|
| 67 |
.center-content {
|
| 68 |
display: flex;
|
| 69 |
flex-direction: column;
|
|
@@ -71,24 +68,20 @@ body {
|
|
| 71 |
text-align: center;
|
| 72 |
margin-bottom: 20px;
|
| 73 |
}
|
| 74 |
-
|
| 75 |
.header {
|
| 76 |
margin-bottom: 30px;
|
| 77 |
width: 100%;
|
| 78 |
}
|
| 79 |
-
|
| 80 |
.logo-container {
|
| 81 |
width: 100%;
|
| 82 |
margin-bottom: 20px;
|
| 83 |
}
|
| 84 |
-
|
| 85 |
.logo-img {
|
| 86 |
width: 100%;
|
| 87 |
max-width: var(--content-width);
|
| 88 |
margin: 0 auto;
|
| 89 |
display: block;
|
| 90 |
}
|
| 91 |
-
|
| 92 |
.nav-bar {
|
| 93 |
display: flex;
|
| 94 |
justify-content: center;
|
|
@@ -97,14 +90,12 @@ body {
|
|
| 97 |
box-shadow: var(--shadow);
|
| 98 |
margin-bottom: 20px;
|
| 99 |
}
|
| 100 |
-
|
| 101 |
.nav-links {
|
| 102 |
display: flex;
|
| 103 |
gap: 30px;
|
| 104 |
width: 100%;
|
| 105 |
justify-content: center;
|
| 106 |
}
|
| 107 |
-
|
| 108 |
.nav-link {
|
| 109 |
color: var(--black);
|
| 110 |
text-decoration: none;
|
|
@@ -112,12 +103,10 @@ body {
|
|
| 112 |
font-size: 24px;
|
| 113 |
transition: color 0.2s;
|
| 114 |
}
|
| 115 |
-
|
| 116 |
.nav-link:hover {
|
| 117 |
color: var(--link-hover);
|
| 118 |
text-decoration: none;
|
| 119 |
}
|
| 120 |
-
|
| 121 |
button {
|
| 122 |
background-color: var(--text-color) !important;
|
| 123 |
color: var(--black) !important;
|
|
@@ -125,7 +114,6 @@ button {
|
|
| 125 |
border-radius: 4px;
|
| 126 |
padding: 8px 16px;
|
| 127 |
}
|
| 128 |
-
|
| 129 |
.file-download {
|
| 130 |
margin-top: 15px !important;
|
| 131 |
}
|
|
@@ -138,12 +126,10 @@ button {
|
|
| 138 |
animation: spin 1s linear infinite;
|
| 139 |
margin: 20px auto;
|
| 140 |
}
|
| 141 |
-
|
| 142 |
@keyframes spin {
|
| 143 |
0% { transform: rotate(0deg); }
|
| 144 |
100% { transform: rotate(360deg); }
|
| 145 |
}
|
| 146 |
-
|
| 147 |
.loader-container {
|
| 148 |
text-align: center;
|
| 149 |
margin: 20px 0;
|
|
@@ -158,12 +144,10 @@ button {
|
|
| 158 |
padding: 10px;
|
| 159 |
border-radius: 4px;
|
| 160 |
}
|
| 161 |
-
|
| 162 |
.bold-label .gr-radio label {
|
| 163 |
font-size: 14px;
|
| 164 |
color: var(--black);
|
| 165 |
}
|
| 166 |
-
|
| 167 |
#analyze-btn {
|
| 168 |
background-color: #FF5722 !important;
|
| 169 |
color: white !important;
|
|
@@ -173,8 +157,6 @@ button {
|
|
| 173 |
left: 3% !important;
|
| 174 |
z-index: 1000 !important;
|
| 175 |
}
|
| 176 |
-
|
| 177 |
-
|
| 178 |
#unzip-btn {
|
| 179 |
background-color: #4CAF50 !important;
|
| 180 |
color: white !important;
|
|
@@ -184,19 +166,16 @@ button {
|
|
| 184 |
left: 18% !important;
|
| 185 |
z-index: 1000 !important;
|
| 186 |
}
|
| 187 |
-
|
| 188 |
#download_file {
|
| 189 |
position: fixed !important;
|
| 190 |
bottom: 1% !important;
|
| 191 |
left: 22% !important;
|
| 192 |
z-index: 1000 !important;
|
| 193 |
}
|
| 194 |
-
|
| 195 |
#analyze-btn:hover,#unzip-btn:hover{
|
| 196 |
transform: translateY(-3px) !important;
|
| 197 |
box-shadow: 0 4px 8px rgba(0,0,0,0.3) !important;
|
| 198 |
}
|
| 199 |
-
|
| 200 |
.square-pdf-btn {
|
| 201 |
width: 90% !important;
|
| 202 |
height: 3% !important;
|
|
@@ -207,48 +186,34 @@ button {
|
|
| 207 |
justify-content: center !important;
|
| 208 |
gap: 8px !important;
|
| 209 |
}
|
| 210 |
-
|
| 211 |
-
|
| 212 |
.square-pdf-btn img {
|
| 213 |
width: 20% !important;
|
| 214 |
height: 1% !important;
|
| 215 |
margin: 0 !important;
|
| 216 |
}
|
| 217 |
-
|
| 218 |
-
|
| 219 |
.square-pdf-btn span {
|
| 220 |
font-size: 14px !important;
|
| 221 |
text-align: center !important;
|
| 222 |
}
|
| 223 |
-
|
| 224 |
-
|
| 225 |
.gradio-gallery-item:hover {
|
| 226 |
background-color: transparent !important;
|
| 227 |
filter: none !important;
|
| 228 |
transform: none !important;
|
| 229 |
}
|
| 230 |
-
|
| 231 |
.custom-markdown h3 {
|
| 232 |
font-size: 25px !important;
|
| 233 |
}
|
| 234 |
-
|
| 235 |
.tight-spacing {
|
| 236 |
margin-bottom: -20px !important;
|
| 237 |
}
|
| 238 |
-
|
| 239 |
.tight-spacing-as {
|
| 240 |
margin-top: 0px !important;
|
| 241 |
margin-bottom: 0px !important;
|
| 242 |
}
|
| 243 |
|
| 244 |
-
.left-margin-column {
|
| 245 |
-
margin-left: 5%;
|
| 246 |
-
}
|
| 247 |
-
|
| 248 |
.image-container img {
|
| 249 |
display: inline-block !important;
|
| 250 |
}
|
| 251 |
-
|
| 252 |
}
|
| 253 |
"""
|
| 254 |
MAX_NUM_PAGES = 10
|
|
@@ -637,6 +602,7 @@ def toggle_spinner():
|
|
| 637 |
gr.Column(visible=False),
|
| 638 |
gr.File(visible=False),
|
| 639 |
gr.update(visible=False),
|
|
|
|
| 640 |
)
|
| 641 |
|
| 642 |
|
|
@@ -836,7 +802,7 @@ with gr.Blocks(css=CSS, title="Document Analysis System", theme=paddle_theme) as
|
|
| 836 |
elem_classes=["tight-spacing"],
|
| 837 |
)
|
| 838 |
with gr.Column(
|
| 839 |
-
visible=False
|
| 840 |
) as Module_Options:
|
| 841 |
use_chart_recognition_md = gr.Markdown(
|
| 842 |
"### Using the chart parsing module",
|
|
@@ -894,7 +860,7 @@ with gr.Blocks(css=CSS, title="Document Analysis System", theme=paddle_theme) as
|
|
| 894 |
elem_id="use_textline_orientation_rd",
|
| 895 |
)
|
| 896 |
with gr.Column(
|
| 897 |
-
visible=True
|
| 898 |
) as Subpipeline_Options:
|
| 899 |
use_seal_recognition_md = gr.Markdown(
|
| 900 |
"### Using the seal text recognition subpipeline",
|
|
@@ -930,7 +896,7 @@ with gr.Blocks(css=CSS, title="Document Analysis System", theme=paddle_theme) as
|
|
| 930 |
elem_id="use_table_recognition_rd",
|
| 931 |
)
|
| 932 |
with gr.Column(
|
| 933 |
-
visible=False
|
| 934 |
) as Layout_region_detection_Options:
|
| 935 |
layout_threshold_md = gr.Markdown(
|
| 936 |
"### Score threshold of layout region detection model",
|
|
@@ -970,7 +936,7 @@ with gr.Blocks(css=CSS, title="Document Analysis System", theme=paddle_theme) as
|
|
| 970 |
elem_id="layout_unclip_ratio_nb",
|
| 971 |
)
|
| 972 |
with gr.Column(
|
| 973 |
-
visible=False
|
| 974 |
) as Text_detection_Options:
|
| 975 |
text_det_limit_type_md = gr.Markdown(
|
| 976 |
"### Image side length restriction type for text detection",
|
|
@@ -1051,7 +1017,7 @@ with gr.Blocks(css=CSS, title="Document Analysis System", theme=paddle_theme) as
|
|
| 1051 |
)
|
| 1052 |
|
| 1053 |
with gr.Column(
|
| 1054 |
-
visible=False
|
| 1055 |
) as Seal_text_recognition_Options:
|
| 1056 |
seal_det_limit_type_md = gr.Markdown(
|
| 1057 |
"### Image side length restriction type for seal text detection",
|
|
@@ -1130,7 +1096,7 @@ with gr.Blocks(css=CSS, title="Document Analysis System", theme=paddle_theme) as
|
|
| 1130 |
elem_id="seal_rec_score_thresh_nb",
|
| 1131 |
)
|
| 1132 |
with gr.Column(
|
| 1133 |
-
visible=False
|
| 1134 |
) as Table_recognition_Options:
|
| 1135 |
use_ocr_results_with_table_cells_md = gr.Markdown(
|
| 1136 |
"### Cell OCR mode",
|
|
@@ -1202,11 +1168,7 @@ with gr.Blocks(css=CSS, title="Document Analysis System", theme=paddle_theme) as
|
|
| 1202 |
process_btn = gr.Button(
|
| 1203 |
"π Parse Document", elem_id="analyze-btn", variant="primary"
|
| 1204 |
)
|
| 1205 |
-
|
| 1206 |
-
"π¦ Download Full Results (ZIP)",
|
| 1207 |
-
elem_id="unzip-btn",
|
| 1208 |
-
variant="primary",
|
| 1209 |
-
)
|
| 1210 |
gr.Markdown(
|
| 1211 |
f"""
|
| 1212 |
1. Only the first {MAX_NUM_PAGES} pages will be processed.
|
|
@@ -1399,6 +1361,12 @@ with gr.Blocks(css=CSS, title="Document Analysis System", theme=paddle_theme) as
|
|
| 1399 |
visible=False,
|
| 1400 |
)
|
| 1401 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1402 |
# # Navigation bar
|
| 1403 |
with gr.Column(elem_classes=["nav-bar"]):
|
| 1404 |
gr.HTML(
|
|
@@ -1436,7 +1404,7 @@ with gr.Blocks(css=CSS, title="Document Analysis System", theme=paddle_theme) as
|
|
| 1436 |
""",
|
| 1437 |
)
|
| 1438 |
process_btn.click(
|
| 1439 |
-
toggle_spinner, outputs=[loading_spinner, prepare_spinner, download_file, tabs]
|
| 1440 |
).then(
|
| 1441 |
process_file,
|
| 1442 |
inputs=[
|
|
@@ -1484,7 +1452,7 @@ with gr.Blocks(css=CSS, title="Document Analysis System", theme=paddle_theme) as
|
|
| 1484 |
+ output_json_list
|
| 1485 |
+ markdown_display_list
|
| 1486 |
+ gallery_list,
|
| 1487 |
-
)
|
| 1488 |
|
| 1489 |
gallery_markdown.select(
|
| 1490 |
update_markdown,
|
|
@@ -1541,11 +1509,9 @@ with gr.Blocks(css=CSS, title="Document Analysis System", theme=paddle_theme) as
|
|
| 1541 |
tooltip.style.left = x + "px";
|
| 1542 |
tooltip.style.top = y + "px";
|
| 1543 |
}}
|
| 1544 |
-
|
| 1545 |
function hideTooltip() {{
|
| 1546 |
tooltip.style.opacity = "0";
|
| 1547 |
}}
|
| 1548 |
-
|
| 1549 |
elem.addEventListener("mousemove", showTooltip);
|
| 1550 |
elem.addEventListener("mouseleave", hideTooltip);
|
| 1551 |
}});
|
|
|
|
| 46 |
--link-hover: #2b6cb0;
|
| 47 |
--content-width: 1200px;
|
| 48 |
}
|
|
|
|
| 49 |
body {
|
| 50 |
display: flex;
|
| 51 |
justify-content: center;
|
|
|
|
| 53 |
color: var(--text-color);
|
| 54 |
font-family: Arial, sans-serif;
|
| 55 |
}
|
|
|
|
| 56 |
.upload-section {
|
| 57 |
width: 100%;
|
| 58 |
margin: 0 auto 30px;
|
|
|
|
| 61 |
border-radius: 8px;
|
| 62 |
box-shadow: var(--shadow);
|
| 63 |
}
|
|
|
|
| 64 |
.center-content {
|
| 65 |
display: flex;
|
| 66 |
flex-direction: column;
|
|
|
|
| 68 |
text-align: center;
|
| 69 |
margin-bottom: 20px;
|
| 70 |
}
|
|
|
|
| 71 |
.header {
|
| 72 |
margin-bottom: 30px;
|
| 73 |
width: 100%;
|
| 74 |
}
|
|
|
|
| 75 |
.logo-container {
|
| 76 |
width: 100%;
|
| 77 |
margin-bottom: 20px;
|
| 78 |
}
|
|
|
|
| 79 |
.logo-img {
|
| 80 |
width: 100%;
|
| 81 |
max-width: var(--content-width);
|
| 82 |
margin: 0 auto;
|
| 83 |
display: block;
|
| 84 |
}
|
|
|
|
| 85 |
.nav-bar {
|
| 86 |
display: flex;
|
| 87 |
justify-content: center;
|
|
|
|
| 90 |
box-shadow: var(--shadow);
|
| 91 |
margin-bottom: 20px;
|
| 92 |
}
|
|
|
|
| 93 |
.nav-links {
|
| 94 |
display: flex;
|
| 95 |
gap: 30px;
|
| 96 |
width: 100%;
|
| 97 |
justify-content: center;
|
| 98 |
}
|
|
|
|
| 99 |
.nav-link {
|
| 100 |
color: var(--black);
|
| 101 |
text-decoration: none;
|
|
|
|
| 103 |
font-size: 24px;
|
| 104 |
transition: color 0.2s;
|
| 105 |
}
|
|
|
|
| 106 |
.nav-link:hover {
|
| 107 |
color: var(--link-hover);
|
| 108 |
text-decoration: none;
|
| 109 |
}
|
|
|
|
| 110 |
button {
|
| 111 |
background-color: var(--text-color) !important;
|
| 112 |
color: var(--black) !important;
|
|
|
|
| 114 |
border-radius: 4px;
|
| 115 |
padding: 8px 16px;
|
| 116 |
}
|
|
|
|
| 117 |
.file-download {
|
| 118 |
margin-top: 15px !important;
|
| 119 |
}
|
|
|
|
| 126 |
animation: spin 1s linear infinite;
|
| 127 |
margin: 20px auto;
|
| 128 |
}
|
|
|
|
| 129 |
@keyframes spin {
|
| 130 |
0% { transform: rotate(0deg); }
|
| 131 |
100% { transform: rotate(360deg); }
|
| 132 |
}
|
|
|
|
| 133 |
.loader-container {
|
| 134 |
text-align: center;
|
| 135 |
margin: 20px 0;
|
|
|
|
| 144 |
padding: 10px;
|
| 145 |
border-radius: 4px;
|
| 146 |
}
|
|
|
|
| 147 |
.bold-label .gr-radio label {
|
| 148 |
font-size: 14px;
|
| 149 |
color: var(--black);
|
| 150 |
}
|
|
|
|
| 151 |
#analyze-btn {
|
| 152 |
background-color: #FF5722 !important;
|
| 153 |
color: white !important;
|
|
|
|
| 157 |
left: 3% !important;
|
| 158 |
z-index: 1000 !important;
|
| 159 |
}
|
|
|
|
|
|
|
| 160 |
#unzip-btn {
|
| 161 |
background-color: #4CAF50 !important;
|
| 162 |
color: white !important;
|
|
|
|
| 166 |
left: 18% !important;
|
| 167 |
z-index: 1000 !important;
|
| 168 |
}
|
|
|
|
| 169 |
#download_file {
|
| 170 |
position: fixed !important;
|
| 171 |
bottom: 1% !important;
|
| 172 |
left: 22% !important;
|
| 173 |
z-index: 1000 !important;
|
| 174 |
}
|
|
|
|
| 175 |
#analyze-btn:hover,#unzip-btn:hover{
|
| 176 |
transform: translateY(-3px) !important;
|
| 177 |
box-shadow: 0 4px 8px rgba(0,0,0,0.3) !important;
|
| 178 |
}
|
|
|
|
| 179 |
.square-pdf-btn {
|
| 180 |
width: 90% !important;
|
| 181 |
height: 3% !important;
|
|
|
|
| 186 |
justify-content: center !important;
|
| 187 |
gap: 8px !important;
|
| 188 |
}
|
|
|
|
|
|
|
| 189 |
.square-pdf-btn img {
|
| 190 |
width: 20% !important;
|
| 191 |
height: 1% !important;
|
| 192 |
margin: 0 !important;
|
| 193 |
}
|
|
|
|
|
|
|
| 194 |
.square-pdf-btn span {
|
| 195 |
font-size: 14px !important;
|
| 196 |
text-align: center !important;
|
| 197 |
}
|
|
|
|
|
|
|
| 198 |
.gradio-gallery-item:hover {
|
| 199 |
background-color: transparent !important;
|
| 200 |
filter: none !important;
|
| 201 |
transform: none !important;
|
| 202 |
}
|
|
|
|
| 203 |
.custom-markdown h3 {
|
| 204 |
font-size: 25px !important;
|
| 205 |
}
|
|
|
|
| 206 |
.tight-spacing {
|
| 207 |
margin-bottom: -20px !important;
|
| 208 |
}
|
|
|
|
| 209 |
.tight-spacing-as {
|
| 210 |
margin-top: 0px !important;
|
| 211 |
margin-bottom: 0px !important;
|
| 212 |
}
|
| 213 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
.image-container img {
|
| 215 |
display: inline-block !important;
|
| 216 |
}
|
|
|
|
| 217 |
}
|
| 218 |
"""
|
| 219 |
MAX_NUM_PAGES = 10
|
|
|
|
| 602 |
gr.Column(visible=False),
|
| 603 |
gr.File(visible=False),
|
| 604 |
gr.update(visible=False),
|
| 605 |
+
gr.update(visible=False),
|
| 606 |
)
|
| 607 |
|
| 608 |
|
|
|
|
| 802 |
elem_classes=["tight-spacing"],
|
| 803 |
)
|
| 804 |
with gr.Column(
|
| 805 |
+
visible=False
|
| 806 |
) as Module_Options:
|
| 807 |
use_chart_recognition_md = gr.Markdown(
|
| 808 |
"### Using the chart parsing module",
|
|
|
|
| 860 |
elem_id="use_textline_orientation_rd",
|
| 861 |
)
|
| 862 |
with gr.Column(
|
| 863 |
+
visible=True
|
| 864 |
) as Subpipeline_Options:
|
| 865 |
use_seal_recognition_md = gr.Markdown(
|
| 866 |
"### Using the seal text recognition subpipeline",
|
|
|
|
| 896 |
elem_id="use_table_recognition_rd",
|
| 897 |
)
|
| 898 |
with gr.Column(
|
| 899 |
+
visible=False
|
| 900 |
) as Layout_region_detection_Options:
|
| 901 |
layout_threshold_md = gr.Markdown(
|
| 902 |
"### Score threshold of layout region detection model",
|
|
|
|
| 936 |
elem_id="layout_unclip_ratio_nb",
|
| 937 |
)
|
| 938 |
with gr.Column(
|
| 939 |
+
visible=False
|
| 940 |
) as Text_detection_Options:
|
| 941 |
text_det_limit_type_md = gr.Markdown(
|
| 942 |
"### Image side length restriction type for text detection",
|
|
|
|
| 1017 |
)
|
| 1018 |
|
| 1019 |
with gr.Column(
|
| 1020 |
+
visible=False
|
| 1021 |
) as Seal_text_recognition_Options:
|
| 1022 |
seal_det_limit_type_md = gr.Markdown(
|
| 1023 |
"### Image side length restriction type for seal text detection",
|
|
|
|
| 1096 |
elem_id="seal_rec_score_thresh_nb",
|
| 1097 |
)
|
| 1098 |
with gr.Column(
|
| 1099 |
+
visible=False
|
| 1100 |
) as Table_recognition_Options:
|
| 1101 |
use_ocr_results_with_table_cells_md = gr.Markdown(
|
| 1102 |
"### Cell OCR mode",
|
|
|
|
| 1168 |
process_btn = gr.Button(
|
| 1169 |
"π Parse Document", elem_id="analyze-btn", variant="primary"
|
| 1170 |
)
|
| 1171 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1172 |
gr.Markdown(
|
| 1173 |
f"""
|
| 1174 |
1. Only the first {MAX_NUM_PAGES} pages will be processed.
|
|
|
|
| 1361 |
visible=False,
|
| 1362 |
)
|
| 1363 |
)
|
| 1364 |
+
download_all_btn = gr.Button(
|
| 1365 |
+
"π¦ Download Full Results (ZIP)",
|
| 1366 |
+
elem_id="unzip-btn",
|
| 1367 |
+
variant="primary",
|
| 1368 |
+
visible=False,
|
| 1369 |
+
)
|
| 1370 |
# # Navigation bar
|
| 1371 |
with gr.Column(elem_classes=["nav-bar"]):
|
| 1372 |
gr.HTML(
|
|
|
|
| 1404 |
""",
|
| 1405 |
)
|
| 1406 |
process_btn.click(
|
| 1407 |
+
toggle_spinner, outputs=[loading_spinner, prepare_spinner, download_file, tabs, download_all_btn]
|
| 1408 |
).then(
|
| 1409 |
process_file,
|
| 1410 |
inputs=[
|
|
|
|
| 1452 |
+ output_json_list
|
| 1453 |
+ markdown_display_list
|
| 1454 |
+ gallery_list,
|
| 1455 |
+
).then(lambda: gr.update(visible=True), outputs=download_all_btn)
|
| 1456 |
|
| 1457 |
gallery_markdown.select(
|
| 1458 |
update_markdown,
|
|
|
|
| 1509 |
tooltip.style.left = x + "px";
|
| 1510 |
tooltip.style.top = y + "px";
|
| 1511 |
}}
|
|
|
|
| 1512 |
function hideTooltip() {{
|
| 1513 |
tooltip.style.opacity = "0";
|
| 1514 |
}}
|
|
|
|
| 1515 |
elem.addEventListener("mousemove", showTooltip);
|
| 1516 |
elem.addEventListener("mouseleave", hideTooltip);
|
| 1517 |
}});
|