File size: 1,331 Bytes
891b60f
 
 
1a61307
 
 
 
891b60f
1a61307
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c82553e
1a61307
c82553e
1a61307
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
library_name: transformers
tags:
- Maths
- Handwritten
- OCR
- Transformers
---
# Model Description

This model performs OCR on hand-written calculus formulas, extracting text with high accuracy

## Usage

### Installation
```bash
pip install unsloth transformers torch pillow
```

### Inference Code
```python
from unsloth import FastVisionModel
import torch
from transformers import AutoModel
import os

os.environ["UNSLOTH_WARN_UNINITIALIZED"] = '0'

# Load the model
model, tokenizer = FastVisionModel.from_pretrained(
    "karankulshrestha/formula_ocr",
    load_in_4bit = False,
    auto_model = AutoModel,
    trust_remote_code = True,
    unsloth_force_compile = True,
    use_gradient_checkpointing = "unsloth",
)

# Enable fast inference
FastVisionModel.for_inference(model)

# Run OCR on an image
result = model.infer(
    tokenizer,
    prompt="\nFree OCR.",
    image_file="path/to/your/image.jpg",
    output_path="./output",
    base_size=1024,
    image_size=640,
    crop_mode=True,
    save_results=True,
)

print("OCR Result:", result)
```


## Output

![Output Setup](fine_tune.png)

## Citation
```bibtex
@misc{formula_ocr},
  author = {Karan Kulshrestha},
  title = {Hand-written OCR Model},
  year = {2025},
  publisher = {HuggingFace},
  url = {https://huggingface.co/karankulshrestha/formula_ocr}
}
```