Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,7 +28,7 @@ TASK_PROMPTS = {
|
|
| 28 |
@spaces.GPU
|
| 29 |
def process_image(image, task):
|
| 30 |
if image is None:
|
| 31 |
-
return "
|
| 32 |
|
| 33 |
if image.mode in ('RGBA', 'LA', 'P'):
|
| 34 |
image = image.convert('RGB')
|
|
@@ -75,11 +75,50 @@ css = """
|
|
| 75 |
|
| 76 |
:root {
|
| 77 |
--input-focus: #2d8cf0;
|
| 78 |
-
--font-color: #
|
| 79 |
-
--font-color-sub: #
|
| 80 |
-
--bg-color:
|
| 81 |
-
--main-color:
|
| 82 |
-
--accent-bg:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
}
|
| 84 |
|
| 85 |
* {
|
|
@@ -87,7 +126,7 @@ css = """
|
|
| 87 |
}
|
| 88 |
|
| 89 |
.gradio-container {
|
| 90 |
-
background: linear-gradient(135deg,
|
| 91 |
min-height: 100vh;
|
| 92 |
}
|
| 93 |
|
|
@@ -164,7 +203,11 @@ css = """
|
|
| 164 |
}
|
| 165 |
|
| 166 |
.upload-box:hover {
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
}
|
| 169 |
|
| 170 |
.dropdown-field {
|
|
@@ -180,6 +223,14 @@ css = """
|
|
| 180 |
flex-wrap: wrap;
|
| 181 |
}
|
| 182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
.task-btn {
|
| 184 |
flex: 1;
|
| 185 |
min-width: 100px;
|
|
@@ -196,13 +247,13 @@ css = """
|
|
| 196 |
}
|
| 197 |
|
| 198 |
.task-btn:hover {
|
| 199 |
-
|
| 200 |
}
|
| 201 |
|
| 202 |
.task-btn.selected, .task-btn:active {
|
| 203 |
box-shadow: 0px 0px var(--main-color) !important;
|
| 204 |
transform: translate(3px, 3px);
|
| 205 |
-
background-color:
|
| 206 |
}
|
| 207 |
|
| 208 |
.go-button {
|
|
@@ -210,18 +261,18 @@ css = """
|
|
| 210 |
height: 55px;
|
| 211 |
border-radius: 8px !important;
|
| 212 |
border: 3px solid var(--main-color) !important;
|
| 213 |
-
background: linear-gradient(135deg,
|
| 214 |
box-shadow: 5px 5px var(--main-color) !important;
|
| 215 |
font-size: 1.2em !important;
|
| 216 |
font-weight: 700 !important;
|
| 217 |
-
color:
|
| 218 |
cursor: pointer;
|
| 219 |
transition: all 0.15s ease;
|
| 220 |
margin-top: 15px;
|
| 221 |
}
|
| 222 |
|
| 223 |
.go-button:hover {
|
| 224 |
-
|
| 225 |
}
|
| 226 |
|
| 227 |
.go-button:active {
|
|
@@ -230,7 +281,7 @@ css = """
|
|
| 230 |
}
|
| 231 |
|
| 232 |
.output-area {
|
| 233 |
-
background-color: var(--
|
| 234 |
border: 2px solid var(--main-color) !important;
|
| 235 |
border-radius: 8px !important;
|
| 236 |
box-shadow: 4px 4px var(--main-color) !important;
|
|
@@ -244,6 +295,7 @@ css = """
|
|
| 244 |
background-color: transparent !important;
|
| 245 |
border: none !important;
|
| 246 |
box-shadow: none !important;
|
|
|
|
| 247 |
}
|
| 248 |
|
| 249 |
.example-gallery {
|
|
@@ -263,12 +315,19 @@ css = """
|
|
| 263 |
}
|
| 264 |
|
| 265 |
.md-preview {
|
| 266 |
-
background-color: var(--
|
| 267 |
border: 2px solid var(--main-color) !important;
|
| 268 |
border-radius: 8px !important;
|
| 269 |
box-shadow: 4px 4px var(--main-color) !important;
|
| 270 |
padding: 20px !important;
|
| 271 |
min-height: 300px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
}
|
| 273 |
|
| 274 |
.tabs-container button {
|
|
@@ -277,24 +336,30 @@ css = """
|
|
| 277 |
font-weight: 600 !important;
|
| 278 |
border-radius: 6px 6px 0 0 !important;
|
| 279 |
margin-right: 5px;
|
|
|
|
| 280 |
}
|
| 281 |
|
| 282 |
.tabs-container button.selected {
|
| 283 |
-
background-color:
|
| 284 |
box-shadow: none !important;
|
|
|
|
| 285 |
}
|
| 286 |
|
| 287 |
.footer-note {
|
| 288 |
text-align: center;
|
| 289 |
margin-top: 20px;
|
| 290 |
padding: 15px;
|
| 291 |
-
background:
|
| 292 |
border-radius: 8px;
|
| 293 |
border: 2px solid var(--main-color);
|
| 294 |
font-size: 0.9em;
|
| 295 |
color: var(--font-color-sub);
|
| 296 |
}
|
| 297 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
footer {
|
| 299 |
display: none !important;
|
| 300 |
}
|
|
@@ -324,6 +389,19 @@ label {
|
|
| 324 |
box-shadow: 0px 0px var(--main-color) !important;
|
| 325 |
transform: translate(2px, 2px);
|
| 326 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 327 |
"""
|
| 328 |
|
| 329 |
with gr.Blocks(title="GLM-OCR") as demo:
|
|
@@ -331,15 +409,15 @@ with gr.Blocks(title="GLM-OCR") as demo:
|
|
| 331 |
gr.HTML("""
|
| 332 |
<div class="main-wrapper">
|
| 333 |
<div class="header-card">
|
| 334 |
-
<h1 class="header-title">
|
| 335 |
-
<p class="header-subtitle">Document parsing
|
| 336 |
</div>
|
| 337 |
</div>
|
| 338 |
""")
|
| 339 |
|
| 340 |
with gr.Row(elem_classes=["main-wrapper"]):
|
| 341 |
with gr.Column(scale=1, elem_classes=["content-card"]):
|
| 342 |
-
gr.HTML('<div class="section-label">
|
| 343 |
|
| 344 |
image_input = gr.Image(
|
| 345 |
type="pil",
|
|
@@ -349,7 +427,7 @@ with gr.Blocks(title="GLM-OCR") as demo:
|
|
| 349 |
height=250
|
| 350 |
)
|
| 351 |
|
| 352 |
-
gr.HTML('<div class="section-label" style="margin-top: 20px;">
|
| 353 |
|
| 354 |
task = gr.Radio(
|
| 355 |
choices=list(TASK_PROMPTS.keys()),
|
|
@@ -359,12 +437,12 @@ with gr.Blocks(title="GLM-OCR") as demo:
|
|
| 359 |
)
|
| 360 |
|
| 361 |
btn = gr.Button(
|
| 362 |
-
"Recognize
|
| 363 |
variant="primary",
|
| 364 |
elem_classes=["go-button"]
|
| 365 |
)
|
| 366 |
|
| 367 |
-
gr.HTML('<div class="section-label" style="margin-top: 20px;">
|
| 368 |
|
| 369 |
examples = gr.Examples(
|
| 370 |
examples=[
|
|
@@ -377,7 +455,7 @@ with gr.Blocks(title="GLM-OCR") as demo:
|
|
| 377 |
)
|
| 378 |
|
| 379 |
with gr.Column(scale=1, elem_classes=["content-card"]):
|
| 380 |
-
gr.HTML('<div class="section-label">
|
| 381 |
|
| 382 |
with gr.Tabs(elem_classes=["tabs-container"]):
|
| 383 |
with gr.Tab("Text"):
|
|
@@ -397,7 +475,7 @@ with gr.Blocks(title="GLM-OCR") as demo:
|
|
| 397 |
gr.HTML("""
|
| 398 |
<div class="main-wrapper">
|
| 399 |
<div class="footer-note">
|
| 400 |
-
|
| 401 |
Supports text, formula, and table recognition
|
| 402 |
</div>
|
| 403 |
</div>
|
|
@@ -421,7 +499,7 @@ with gr.Blocks(title="GLM-OCR") as demo:
|
|
| 421 |
|
| 422 |
if __name__ == "__main__":
|
| 423 |
demo.queue(max_size=50).launch(
|
| 424 |
-
css=css,
|
| 425 |
show_error=True,
|
| 426 |
ssr_mode=False
|
| 427 |
)
|
|
|
|
| 28 |
@spaces.GPU
|
| 29 |
def process_image(image, task):
|
| 30 |
if image is None:
|
| 31 |
+
return "Please upload an image first"
|
| 32 |
|
| 33 |
if image.mode in ('RGBA', 'LA', 'P'):
|
| 34 |
image = image.convert('RGB')
|
|
|
|
| 75 |
|
| 76 |
:root {
|
| 77 |
--input-focus: #2d8cf0;
|
| 78 |
+
--font-color: #1a1a1a;
|
| 79 |
+
--font-color-sub: #4a4a4a;
|
| 80 |
+
--bg-color: #f5f5dc;
|
| 81 |
+
--main-color: #1a1a1a;
|
| 82 |
+
--accent-bg: #b8d4e3;
|
| 83 |
+
--card-bg: #f0f0f0;
|
| 84 |
+
--gradient-start: #e8f5e9;
|
| 85 |
+
--gradient-mid: #e3f2fd;
|
| 86 |
+
--gradient-end: #fce4ec;
|
| 87 |
+
--button-gradient-start: #ffd54f;
|
| 88 |
+
--button-gradient-end: #ffb300;
|
| 89 |
+
--output-bg: #fffef5;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
@media (prefers-color-scheme: dark) {
|
| 93 |
+
:root {
|
| 94 |
+
--font-color: #e8e8e8;
|
| 95 |
+
--font-color-sub: #b0b0b0;
|
| 96 |
+
--bg-color: #2a2a2a;
|
| 97 |
+
--main-color: #e8e8e8;
|
| 98 |
+
--accent-bg: #3a4a5a;
|
| 99 |
+
--card-bg: #1e1e1e;
|
| 100 |
+
--gradient-start: #1a2a1a;
|
| 101 |
+
--gradient-mid: #1a2a3a;
|
| 102 |
+
--gradient-end: #2a1a2a;
|
| 103 |
+
--button-gradient-start: #cc9a00;
|
| 104 |
+
--button-gradient-end: #b38600;
|
| 105 |
+
--output-bg: #2a2a2a;
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
.dark {
|
| 110 |
+
--font-color: #e8e8e8;
|
| 111 |
+
--font-color-sub: #b0b0b0;
|
| 112 |
+
--bg-color: #2a2a2a;
|
| 113 |
+
--main-color: #e8e8e8;
|
| 114 |
+
--accent-bg: #3a4a5a;
|
| 115 |
+
--card-bg: #1e1e1e;
|
| 116 |
+
--gradient-start: #1a2a1a;
|
| 117 |
+
--gradient-mid: #1a2a3a;
|
| 118 |
+
--gradient-end: #2a1a2a;
|
| 119 |
+
--button-gradient-start: #cc9a00;
|
| 120 |
+
--button-gradient-end: #b38600;
|
| 121 |
+
--output-bg: #2a2a2a;
|
| 122 |
}
|
| 123 |
|
| 124 |
* {
|
|
|
|
| 126 |
}
|
| 127 |
|
| 128 |
.gradio-container {
|
| 129 |
+
background: linear-gradient(135deg, var(--gradient-start), var(--gradient-mid), var(--gradient-end)) !important;
|
| 130 |
min-height: 100vh;
|
| 131 |
}
|
| 132 |
|
|
|
|
| 203 |
}
|
| 204 |
|
| 205 |
.upload-box:hover {
|
| 206 |
+
opacity: 0.9;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
.upload-box span, .upload-box p, .upload-box label {
|
| 210 |
+
color: var(--font-color) !important;
|
| 211 |
}
|
| 212 |
|
| 213 |
.dropdown-field {
|
|
|
|
| 223 |
flex-wrap: wrap;
|
| 224 |
}
|
| 225 |
|
| 226 |
+
.task-buttons label {
|
| 227 |
+
color: var(--font-color) !important;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
.task-buttons input[type="radio"] + label {
|
| 231 |
+
color: var(--font-color) !important;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
.task-btn {
|
| 235 |
flex: 1;
|
| 236 |
min-width: 100px;
|
|
|
|
| 247 |
}
|
| 248 |
|
| 249 |
.task-btn:hover {
|
| 250 |
+
opacity: 0.9;
|
| 251 |
}
|
| 252 |
|
| 253 |
.task-btn.selected, .task-btn:active {
|
| 254 |
box-shadow: 0px 0px var(--main-color) !important;
|
| 255 |
transform: translate(3px, 3px);
|
| 256 |
+
background-color: var(--button-gradient-start) !important;
|
| 257 |
}
|
| 258 |
|
| 259 |
.go-button {
|
|
|
|
| 261 |
height: 55px;
|
| 262 |
border-radius: 8px !important;
|
| 263 |
border: 3px solid var(--main-color) !important;
|
| 264 |
+
background: linear-gradient(135deg, var(--button-gradient-start), var(--button-gradient-end)) !important;
|
| 265 |
box-shadow: 5px 5px var(--main-color) !important;
|
| 266 |
font-size: 1.2em !important;
|
| 267 |
font-weight: 700 !important;
|
| 268 |
+
color: #1a1a1a !important;
|
| 269 |
cursor: pointer;
|
| 270 |
transition: all 0.15s ease;
|
| 271 |
margin-top: 15px;
|
| 272 |
}
|
| 273 |
|
| 274 |
.go-button:hover {
|
| 275 |
+
opacity: 0.9;
|
| 276 |
}
|
| 277 |
|
| 278 |
.go-button:active {
|
|
|
|
| 281 |
}
|
| 282 |
|
| 283 |
.output-area {
|
| 284 |
+
background-color: var(--output-bg) !important;
|
| 285 |
border: 2px solid var(--main-color) !important;
|
| 286 |
border-radius: 8px !important;
|
| 287 |
box-shadow: 4px 4px var(--main-color) !important;
|
|
|
|
| 295 |
background-color: transparent !important;
|
| 296 |
border: none !important;
|
| 297 |
box-shadow: none !important;
|
| 298 |
+
color: var(--font-color) !important;
|
| 299 |
}
|
| 300 |
|
| 301 |
.example-gallery {
|
|
|
|
| 315 |
}
|
| 316 |
|
| 317 |
.md-preview {
|
| 318 |
+
background-color: var(--output-bg) !important;
|
| 319 |
border: 2px solid var(--main-color) !important;
|
| 320 |
border-radius: 8px !important;
|
| 321 |
box-shadow: 4px 4px var(--main-color) !important;
|
| 322 |
padding: 20px !important;
|
| 323 |
min-height: 300px;
|
| 324 |
+
color: var(--font-color) !important;
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
.md-preview p, .md-preview h1, .md-preview h2, .md-preview h3,
|
| 328 |
+
.md-preview h4, .md-preview h5, .md-preview h6, .md-preview li,
|
| 329 |
+
.md-preview span, .md-preview code, .md-preview pre {
|
| 330 |
+
color: var(--font-color) !important;
|
| 331 |
}
|
| 332 |
|
| 333 |
.tabs-container button {
|
|
|
|
| 336 |
font-weight: 600 !important;
|
| 337 |
border-radius: 6px 6px 0 0 !important;
|
| 338 |
margin-right: 5px;
|
| 339 |
+
color: var(--font-color) !important;
|
| 340 |
}
|
| 341 |
|
| 342 |
.tabs-container button.selected {
|
| 343 |
+
background-color: var(--button-gradient-start) !important;
|
| 344 |
box-shadow: none !important;
|
| 345 |
+
color: #1a1a1a !important;
|
| 346 |
}
|
| 347 |
|
| 348 |
.footer-note {
|
| 349 |
text-align: center;
|
| 350 |
margin-top: 20px;
|
| 351 |
padding: 15px;
|
| 352 |
+
background: var(--card-bg);
|
| 353 |
border-radius: 8px;
|
| 354 |
border: 2px solid var(--main-color);
|
| 355 |
font-size: 0.9em;
|
| 356 |
color: var(--font-color-sub);
|
| 357 |
}
|
| 358 |
|
| 359 |
+
.footer-note strong {
|
| 360 |
+
color: var(--font-color);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
footer {
|
| 364 |
display: none !important;
|
| 365 |
}
|
|
|
|
| 389 |
box-shadow: 0px 0px var(--main-color) !important;
|
| 390 |
transform: translate(2px, 2px);
|
| 391 |
}
|
| 392 |
+
|
| 393 |
+
span, p, div, input, textarea, button, a {
|
| 394 |
+
color: var(--font-color);
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
.gr-input, .gr-text-input, .gr-textarea {
|
| 398 |
+
color: var(--font-color) !important;
|
| 399 |
+
background-color: var(--bg-color) !important;
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
.gr-radio label span {
|
| 403 |
+
color: var(--font-color) !important;
|
| 404 |
+
}
|
| 405 |
"""
|
| 406 |
|
| 407 |
with gr.Blocks(title="GLM-OCR") as demo:
|
|
|
|
| 409 |
gr.HTML("""
|
| 410 |
<div class="main-wrapper">
|
| 411 |
<div class="header-card">
|
| 412 |
+
<h1 class="header-title">GLM-OCR</h1>
|
| 413 |
+
<p class="header-subtitle">Document parsing and text recognition powered by AI</p>
|
| 414 |
</div>
|
| 415 |
</div>
|
| 416 |
""")
|
| 417 |
|
| 418 |
with gr.Row(elem_classes=["main-wrapper"]):
|
| 419 |
with gr.Column(scale=1, elem_classes=["content-card"]):
|
| 420 |
+
gr.HTML('<div class="section-label">Upload Image</div>')
|
| 421 |
|
| 422 |
image_input = gr.Image(
|
| 423 |
type="pil",
|
|
|
|
| 427 |
height=250
|
| 428 |
)
|
| 429 |
|
| 430 |
+
gr.HTML('<div class="section-label" style="margin-top: 20px;">Recognition Type</div>')
|
| 431 |
|
| 432 |
task = gr.Radio(
|
| 433 |
choices=list(TASK_PROMPTS.keys()),
|
|
|
|
| 437 |
)
|
| 438 |
|
| 439 |
btn = gr.Button(
|
| 440 |
+
"Recognize",
|
| 441 |
variant="primary",
|
| 442 |
elem_classes=["go-button"]
|
| 443 |
)
|
| 444 |
|
| 445 |
+
gr.HTML('<div class="section-label" style="margin-top: 20px;">Examples</div>')
|
| 446 |
|
| 447 |
examples = gr.Examples(
|
| 448 |
examples=[
|
|
|
|
| 455 |
)
|
| 456 |
|
| 457 |
with gr.Column(scale=1, elem_classes=["content-card"]):
|
| 458 |
+
gr.HTML('<div class="section-label">Output</div>')
|
| 459 |
|
| 460 |
with gr.Tabs(elem_classes=["tabs-container"]):
|
| 461 |
with gr.Tab("Text"):
|
|
|
|
| 475 |
gr.HTML("""
|
| 476 |
<div class="main-wrapper">
|
| 477 |
<div class="footer-note">
|
| 478 |
+
Powered by <strong>zai-org/GLM-OCR</strong> |
|
| 479 |
Supports text, formula, and table recognition
|
| 480 |
</div>
|
| 481 |
</div>
|
|
|
|
| 499 |
|
| 500 |
if __name__ == "__main__":
|
| 501 |
demo.queue(max_size=50).launch(
|
| 502 |
+
css=css,
|
| 503 |
show_error=True,
|
| 504 |
ssr_mode=False
|
| 505 |
)
|