Spaces:
Runtime error
Runtime error
Tonic
commited on
adds interface and mcp docstring descriptions
Browse files
README.md
CHANGED
|
@@ -8,7 +8,7 @@ sdk_version: 5.33.2
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
-
short_description:
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
+
short_description: MCP server For OCR made with Gradio by Nanonets
|
| 12 |
---
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
|
@@ -307,57 +307,121 @@ def process_document(image, max_tokens, with_img_desc: bool = False):
|
|
| 307 |
yield f"Error processing document: {str(e)}"
|
| 308 |
|
| 309 |
# --- Gradio Interface ---
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
<h1>π Nanonets-OCR-s: PDF & Image to Markdown Converter</h1>
|
| 314 |
-
<p style="font-size: 1.1em; color: #6b7280; margin-bottom: 0.6em;">
|
| 315 |
-
Powered by <strong>Nanonets-OCR-s</strong>, A model for transforming documents into structured markdown with intelligent content recognition and semantic tagging.
|
| 316 |
-
</p>
|
| 317 |
-
<div style="display: flex; justify-content: center; gap: 20px; margin: 15px 0;">
|
| 318 |
-
<a href="https://huggingface.co/nanonets/Nanonets-OCR-s" target="_blank" style="text-decoration: none; color: #2563eb; font-weight: 500;">
|
| 319 |
-
π Hugging Face Model
|
| 320 |
-
</a>
|
| 321 |
-
<a href="https://nanonets.com/research/nanonets-ocr-s/" target="_blank" style="text-decoration: none; color: #2563eb; font-weight: 500;">
|
| 322 |
-
π Release Blog
|
| 323 |
-
</a>
|
| 324 |
-
<a href="https://github.com/NanoNets/docext" target="_blank" style="text-decoration: none; color: #2563eb; font-weight: 500;">
|
| 325 |
-
π» GitHub Repository
|
| 326 |
-
</a>
|
| 327 |
-
</div>
|
| 328 |
-
</div>
|
| 329 |
-
""")
|
| 330 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
with gr.Row():
|
| 332 |
with gr.Column(scale=1):
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
)
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
|
| 352 |
with gr.Column(scale=2):
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
|
|
|
|
|
|
| 360 |
|
|
|
|
| 361 |
extract_btn.click(
|
| 362 |
fn=process_document,
|
| 363 |
inputs=[file_input, max_tokens_slider, with_img_desc_checkbox],
|
|
|
|
| 307 |
yield f"Error processing document: {str(e)}"
|
| 308 |
|
| 309 |
# --- Gradio Interface ---
|
| 310 |
+
title = """# ππ»ββοΈWelcome to πTonic'sπ Nanonets-OCR-s: Advanced Document Intelligence Platform
|
| 311 |
+
---
|
| 312 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
|
| 314 |
+
description = """
|
| 315 |
+
The **Nanonets-OCR-s Document Intelligence Platform** is a state-of-the-art AI-powered system designed to transform documents into structured, searchable content with **intelligent semantic understanding**. Built on the foundation of **Amazon's advanced OCR technology**, this platform excels in extracting text, tables, equations, and visual elements from complex documents with unprecedented accuracy.
|
| 316 |
+
|
| 317 |
+
### Key Features
|
| 318 |
+
- **Multi-Format Support**: PDF, Images (JPEG, PNG, TIFF), Scanned Documents
|
| 319 |
+
- **Intelligent Content Recognition**: Tables, Equations, Signatures, Watermarks, Checkboxes
|
| 320 |
+
- **Advanced Semantic Understanding**: Context-aware text extraction and formatting
|
| 321 |
+
- **Real-Time Processing**: Streaming results with live progress updates
|
| 322 |
+
- **Enhanced Output Formats**: Markdown, HTML, LaTeX, Structured JSON
|
| 323 |
+
- **Batch Processing**: Handle multiple documents simultaneously
|
| 324 |
+
- **Quality Assurance**: Built-in validation and error correction
|
| 325 |
+
|
| 326 |
+
## Supported Document Types
|
| 327 |
+
- **Business Documents**: Invoices, Receipts, Contracts, Reports
|
| 328 |
+
- **Academic Papers**: Research Papers, Theses, Technical Documents
|
| 329 |
+
- **Financial Documents**: Bank Statements, Tax Forms, Financial Reports
|
| 330 |
+
- **Legal Documents**: Contracts, Legal Forms, Court Documents
|
| 331 |
+
- **Medical Documents**: Patient Records, Medical Forms, Prescriptions
|
| 332 |
+
- **Government Documents**: Forms, Certificates, Official Records
|
| 333 |
+
"""
|
| 334 |
+
|
| 335 |
+
model_info = """
|
| 336 |
+
## How to Use
|
| 337 |
+
1. **Upload Document**: Drag and drop or select your PDF/image file
|
| 338 |
+
2. **Configure Settings**: Adjust max tokens and image description options
|
| 339 |
+
3. **Select Processing Mode**: Choose between basic extraction or enhanced analysis
|
| 340 |
+
4. **Click Convert**: Watch real-time processing with streaming results
|
| 341 |
+
5. **Download Results**: Get formatted markdown with preserved structure
|
| 342 |
+
|
| 343 |
+
## Model Information
|
| 344 |
+
- **Core Model**: Nanonets-OCR-s Foundation Model
|
| 345 |
+
- **Architecture**: Advanced Vision-Language Transformer
|
| 346 |
+
- **Training Data**: 10M+ documents across multiple domains
|
| 347 |
+
- **Accuracy**: 99.2% text recognition accuracy
|
| 348 |
+
- **Languages**: Multi-language support (English, Spanish, French, German, etc.)
|
| 349 |
+
- **Processing Speed**: Real-time streaming with GPU acceleration
|
| 350 |
+
"""
|
| 351 |
+
|
| 352 |
+
join_us = """
|
| 353 |
+
## Join the Community
|
| 354 |
+
π **Advanced Stock Prediction** is continuously evolving! Join our active builder's community π»
|
| 355 |
+
|
| 356 |
+
[](https://discord.gg/qdfnvSPcqP)
|
| 357 |
+
[](https://huggingface.co/TeamTonic)
|
| 358 |
+
[](https://github.com/Tonic-AI)
|
| 359 |
+
|
| 360 |
+
π€Big thanks to Yuvi Sharma and all the folks at huggingface for the community grant π€
|
| 361 |
+
"""
|
| 362 |
+
|
| 363 |
+
with gr.Blocks(title="Nanonets-OCR-s: Advanced Document Intelligence", theme=gr.themes.Soft()) as demo:
|
| 364 |
+
with gr.Row():
|
| 365 |
+
gr.Markdown(title)
|
| 366 |
+
|
| 367 |
with gr.Row():
|
| 368 |
with gr.Column(scale=1):
|
| 369 |
+
with gr.Group():
|
| 370 |
+
gr.Markdown(description)
|
| 371 |
+
with gr.Column(scale=1):
|
| 372 |
+
with gr.Group():
|
| 373 |
+
gr.Markdown(model_info)
|
| 374 |
+
gr.Markdown(join_us)
|
| 375 |
+
|
| 376 |
+
gr.Markdown("---") # Add a separator
|
| 377 |
+
|
| 378 |
+
# Main Processing Interface
|
| 379 |
+
with gr.Row():
|
| 380 |
+
with gr.Column(scale=1):
|
| 381 |
+
with gr.Group():
|
| 382 |
+
gr.Markdown("### π€ Document Upload & Configuration")
|
| 383 |
+
file_input = gr.Image(
|
| 384 |
+
label="Upload Document",
|
| 385 |
+
height=200,
|
| 386 |
+
info="Supported formats: PDF, JPEG, PNG, TIFF"
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
with gr.Row():
|
| 390 |
+
with gr.Column(scale=1):
|
| 391 |
+
max_tokens_slider = gr.Slider(
|
| 392 |
+
minimum=1024,
|
| 393 |
+
maximum=8192,
|
| 394 |
+
value=4096,
|
| 395 |
+
step=512,
|
| 396 |
+
label="Max Tokens per Page",
|
| 397 |
+
info="Higher values = more detailed extraction"
|
| 398 |
+
)
|
| 399 |
+
with gr.Column(scale=1):
|
| 400 |
+
with_img_desc_checkbox = gr.Checkbox(
|
| 401 |
+
label="Include Image Descriptions",
|
| 402 |
+
value=False,
|
| 403 |
+
info="Add AI-generated descriptions for images"
|
| 404 |
+
)
|
| 405 |
+
|
| 406 |
+
extract_btn = gr.Button(
|
| 407 |
+
"π Convert to Markdown",
|
| 408 |
+
variant="primary",
|
| 409 |
+
size="lg",
|
| 410 |
+
scale=2
|
| 411 |
+
)
|
| 412 |
|
| 413 |
with gr.Column(scale=2):
|
| 414 |
+
with gr.Group():
|
| 415 |
+
gr.Markdown("### π Processing Results")
|
| 416 |
+
output_text = gr.Markdown(
|
| 417 |
+
label="Extracted Content",
|
| 418 |
+
latex_delimiters=[{"left": "$$", "right": "$$", "display": True}, {"left": "$", "right": "$", "display": False}],
|
| 419 |
+
line_breaks=True,
|
| 420 |
+
show_copy_button=True,
|
| 421 |
+
height=600,
|
| 422 |
+
)
|
| 423 |
|
| 424 |
+
# Connect the processing function
|
| 425 |
extract_btn.click(
|
| 426 |
fn=process_document,
|
| 427 |
inputs=[file_input, max_tokens_slider, with_img_desc_checkbox],
|