Commit
Β·
1a8600d
1
Parent(s):
db8b41d
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,53 +186,37 @@ 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: -
|
| 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 |
#markdown-title {
|
| 253 |
text-align: center;
|
| 254 |
}
|
| 255 |
-
|
| 256 |
-
|
| 257 |
}
|
| 258 |
"""
|
| 259 |
|
|
@@ -463,6 +426,7 @@ def toggle_spinner():
|
|
| 463 |
gr.Column(visible=False),
|
| 464 |
gr.File(visible=False),
|
| 465 |
gr.update(visible=False),
|
|
|
|
| 466 |
)
|
| 467 |
|
| 468 |
|
|
@@ -588,7 +552,7 @@ with gr.Blocks(css=CSS, title=TITLE, theme=paddle_theme) as demo:
|
|
| 588 |
elem_classes=["tight-spacing"],
|
| 589 |
)
|
| 590 |
with gr.Column(
|
| 591 |
-
visible=True
|
| 592 |
) as Module_Options:
|
| 593 |
use_doc_orientation_classify_md = gr.Markdown(
|
| 594 |
"### Using the document image orientation classification module",
|
|
@@ -624,7 +588,7 @@ with gr.Blocks(css=CSS, title=TITLE, theme=paddle_theme) as demo:
|
|
| 624 |
elem_id="use_textline_orientation_rd",
|
| 625 |
)
|
| 626 |
with gr.Column(
|
| 627 |
-
visible=False
|
| 628 |
) as Text_detection_Options:
|
| 629 |
text_det_limit_type_md = gr.Markdown(
|
| 630 |
"### Image side length restriction type for text detection",
|
|
@@ -707,11 +671,7 @@ with gr.Blocks(css=CSS, title=TITLE, theme=paddle_theme) as demo:
|
|
| 707 |
process_btn = gr.Button(
|
| 708 |
"π Parse Document", elem_id="analyze-btn", variant="primary"
|
| 709 |
)
|
| 710 |
-
|
| 711 |
-
"π¦ Download Full Results (ZIP)",
|
| 712 |
-
elem_id="unzip-btn",
|
| 713 |
-
variant="primary",
|
| 714 |
-
)
|
| 715 |
|
| 716 |
# Results display section
|
| 717 |
with gr.Column(scale=7):
|
|
@@ -818,6 +778,12 @@ with gr.Blocks(css=CSS, title=TITLE, theme=paddle_theme) as demo:
|
|
| 818 |
visible=False,
|
| 819 |
)
|
| 820 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 821 |
# # Navigation bar
|
| 822 |
with gr.Column(elem_classes=["nav-bar"]):
|
| 823 |
gr.HTML(
|
|
@@ -851,7 +817,7 @@ with gr.Blocks(css=CSS, title=TITLE, theme=paddle_theme) as demo:
|
|
| 851 |
""",
|
| 852 |
)
|
| 853 |
process_btn.click(
|
| 854 |
-
toggle_spinner, outputs=[loading_spinner, prepare_spinner, download_file, tabs]
|
| 855 |
).then(
|
| 856 |
process_file,
|
| 857 |
inputs=[
|
|
@@ -874,7 +840,7 @@ with gr.Blocks(css=CSS, title=TITLE, theme=paddle_theme) as demo:
|
|
| 874 |
update_display,
|
| 875 |
inputs=[results_state],
|
| 876 |
outputs=overall_ocr_res_images + output_json_list + gallery_list,
|
| 877 |
-
)
|
| 878 |
gallery_ocr_det.select(update_image, outputs=overall_ocr_res_images)
|
| 879 |
|
| 880 |
download_all_btn.click(
|
|
@@ -923,11 +889,9 @@ with gr.Blocks(css=CSS, title=TITLE, theme=paddle_theme) as demo:
|
|
| 923 |
tooltip.style.left = x + "px";
|
| 924 |
tooltip.style.top = y + "px";
|
| 925 |
}}
|
| 926 |
-
|
| 927 |
function hideTooltip() {{
|
| 928 |
tooltip.style.opacity = "0";
|
| 929 |
}}
|
| 930 |
-
|
| 931 |
elem.addEventListener("mousemove", showTooltip);
|
| 932 |
elem.addEventListener("mouseleave", hideTooltip);
|
| 933 |
}});
|
|
|
|
| 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: -5px !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 |
#markdown-title {
|
| 218 |
text-align: center;
|
| 219 |
}
|
|
|
|
|
|
|
| 220 |
}
|
| 221 |
"""
|
| 222 |
|
|
|
|
| 426 |
gr.Column(visible=False),
|
| 427 |
gr.File(visible=False),
|
| 428 |
gr.update(visible=False),
|
| 429 |
+
gr.update(visible=False),
|
| 430 |
)
|
| 431 |
|
| 432 |
|
|
|
|
| 552 |
elem_classes=["tight-spacing"],
|
| 553 |
)
|
| 554 |
with gr.Column(
|
| 555 |
+
visible=True
|
| 556 |
) as Module_Options:
|
| 557 |
use_doc_orientation_classify_md = gr.Markdown(
|
| 558 |
"### Using the document image orientation classification module",
|
|
|
|
| 588 |
elem_id="use_textline_orientation_rd",
|
| 589 |
)
|
| 590 |
with gr.Column(
|
| 591 |
+
visible=False
|
| 592 |
) as Text_detection_Options:
|
| 593 |
text_det_limit_type_md = gr.Markdown(
|
| 594 |
"### Image side length restriction type for text detection",
|
|
|
|
| 671 |
process_btn = gr.Button(
|
| 672 |
"π Parse Document", elem_id="analyze-btn", variant="primary"
|
| 673 |
)
|
| 674 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 675 |
|
| 676 |
# Results display section
|
| 677 |
with gr.Column(scale=7):
|
|
|
|
| 778 |
visible=False,
|
| 779 |
)
|
| 780 |
)
|
| 781 |
+
download_all_btn = gr.Button(
|
| 782 |
+
"π¦ Download Full Results (ZIP)",
|
| 783 |
+
elem_id="unzip-btn",
|
| 784 |
+
variant="primary",
|
| 785 |
+
visible=False,
|
| 786 |
+
)
|
| 787 |
# # Navigation bar
|
| 788 |
with gr.Column(elem_classes=["nav-bar"]):
|
| 789 |
gr.HTML(
|
|
|
|
| 817 |
""",
|
| 818 |
)
|
| 819 |
process_btn.click(
|
| 820 |
+
toggle_spinner, outputs=[loading_spinner, prepare_spinner, download_file, tabs, download_all_btn]
|
| 821 |
).then(
|
| 822 |
process_file,
|
| 823 |
inputs=[
|
|
|
|
| 840 |
update_display,
|
| 841 |
inputs=[results_state],
|
| 842 |
outputs=overall_ocr_res_images + output_json_list + gallery_list,
|
| 843 |
+
).then(lambda: gr.update(visible=True), outputs=download_all_btn)
|
| 844 |
gallery_ocr_det.select(update_image, outputs=overall_ocr_res_images)
|
| 845 |
|
| 846 |
download_all_btn.click(
|
|
|
|
| 889 |
tooltip.style.left = x + "px";
|
| 890 |
tooltip.style.top = y + "px";
|
| 891 |
}}
|
|
|
|
| 892 |
function hideTooltip() {{
|
| 893 |
tooltip.style.opacity = "0";
|
| 894 |
}}
|
|
|
|
| 895 |
elem.addEventListener("mousemove", showTooltip);
|
| 896 |
elem.addEventListener("mouseleave", hideTooltip);
|
| 897 |
}});
|