Create Gradio demo interface. Returns: gr.Blocks: Gradio Blocks application instance.
()
| 355 | |
| 356 | # Define the Gradio Interface |
| 357 | def create_demo() -> gr.Blocks: |
| 358 | """Create Gradio demo interface. |
| 359 | |
| 360 | Returns: |
| 361 | gr.Blocks: Gradio Blocks application instance. |
| 362 | """ |
| 363 | # Get example images path and download if necessary |
| 364 | example_img_dir = get_example_images_path(demo_type='doc') |
| 365 | |
| 366 | # Get list of example images |
| 367 | example_images = [] |
| 368 | if os.path.exists(example_img_dir): |
| 369 | for file in os.listdir(example_img_dir): |
| 370 | if file.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')): |
| 371 | example_images.append(os.path.join(example_img_dir, file)) |
| 372 | example_images = sorted(example_images) |
| 373 | |
| 374 | with gr.Blocks(css=custom_css, |
| 375 | theme=gr.themes.Soft(), |
| 376 | title='OpenDoc-0.1B Demo') as demo: |
| 377 | # Header |
| 378 | gr.HTML(""" |
| 379 | <div class="app-header"> |
| 380 | <h1>🚀 OpenDoc-0.1B</h1> |
| 381 | <p>Ultra-Lightweight Document Parsing System with 0.1B Parameters (built by <a href="https://github.com/Topdu/OpenOCR">OCR Team</a>, <a href="https://fvl.fudan.edu.cn">FVL Lab</a>)</p> |
| 382 | <p style="font-size: 0.95em; color: #888;"> |
| 383 | Powered by <a href="https://www.paddleocr.ai/latest/version3.x/module_usage/layout_analysis.html" target="_blank">PP-DocLayoutV2</a> for layout analysis and <a href="https://arxiv.org/pdf/2512.21095" target="_blank">UniRec-0.1B</a> for unified recognition of text, formulas, and tables |
| 384 | </p> |
| 385 | </div> |
| 386 | <div class="quick-links"> |
| 387 | <a href="https://github.com/Topdu/OpenOCR" target="_blank">📖 GitHub</a> |
| 388 | <a href="https://arxiv.org/pdf/2512.21095" target="_blank">📄 Paper</a> |
| 389 | <a href="https://huggingface.co/topdu/unirec-0.1b" target="_blank">🤗 Model</a> |
| 390 | </div> |
| 391 | """) |
| 392 | |
| 393 | with gr.Row(): |
| 394 | with gr.Column(scale=4, elem_classes=['upload-section']): |
| 395 | input_img = gr.Image(type='filepath', |
| 396 | label='📤 Upload Document Image', |
| 397 | elem_classes=['image-container']) |
| 398 | |
| 399 | # Add examples if available |
| 400 | if example_images: |
| 401 | gr.Examples( |
| 402 | examples=example_images, |
| 403 | inputs=input_img, |
| 404 | label='📚 Example Documents' |
| 405 | ) |
| 406 | btn = gr.Button('🔍 Analyze Document', |
| 407 | variant='primary', |
| 408 | size='lg') |
| 409 | gr.Markdown(""" |
| 410 | ### 💡 Tips |
| 411 | - Supports Chinese and English documents |
| 412 | - Best for reports, papers, magazines, and complex layouts |
| 413 | - Handles text, formulas, tables, and images |
| 414 | """) |
no test coverage detected