Carlos Lorenzo Santos commited on
Commit
7c6f837
Β·
0 Parent(s):

Initial dots.ocr deployment for HuggingFace Space

Browse files
Files changed (3) hide show
  1. README.md +17 -0
  2. app.py +45 -0
  3. requirements.txt +7 -0
README.md ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Dots OCR
3
+ emoji: πŸ”
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: gradio
7
+ sdk_version: 4.44.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: apache-2.0
11
+ models:
12
+ - rednote-hilab/dots.ocr
13
+ ---
14
+
15
+ # dots.ocr - Multilingual OCR
16
+
17
+ State-of-the-art multilingual document OCR supporting 100+ languages, tables, formulas, and complex layouts.
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModel, AutoTokenizer
3
+ from PIL import Image
4
+ import torch
5
+
6
+ # Load model and tokenizer
7
+ model_name = "rednote-hilab/dots.ocr"
8
+ print("Loading dots.ocr model...")
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
10
+ model = AutoModel.from_pretrained(
11
+ model_name,
12
+ trust_remote_code=True,
13
+ torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
14
+ device_map="auto"
15
+ )
16
+ print("Model loaded!")
17
+
18
+ def process_image(image):
19
+ """Process image with dots.ocr"""
20
+ if image is None:
21
+ return "Please upload an image"
22
+
23
+ try:
24
+ # Run OCR
25
+ result = model.generate(image, tokenizer)
26
+ return result
27
+ except Exception as e:
28
+ return f"Error: {str(e)}"
29
+
30
+ # Create Gradio interface
31
+ iface = gr.Interface(
32
+ fn=process_image,
33
+ inputs=gr.Image(type="pil", label="Upload Image"),
34
+ outputs=gr.Textbox(label="OCR Result", lines=10),
35
+ title="dots.ocr - Multilingual OCR",
36
+ description="Upload an image to extract text using dots.ocr. Supports 100+ languages, tables, formulas, and complex layouts.",
37
+ examples=[
38
+ ["examples/example1.jpg"],
39
+ ["examples/example2.png"]
40
+ ],
41
+ theme="soft"
42
+ )
43
+
44
+ if __name__ == "__main__":
45
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ gradio==4.44.0
2
+ transformers==4.45.0
3
+ torch
4
+ torchvision
5
+ pillow
6
+ accelerate
7
+ sentencepiece