Update README.md
Browse files
README.md
CHANGED
@@ -25,6 +25,28 @@ More information needed
|
|
25 |
|
26 |
More information needed
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
### Framework versions
|
29 |
|
30 |
- Transformers 4.35.2
|
|
|
25 |
|
26 |
More information needed
|
27 |
|
28 |
+
## Example
|
29 |
+
```python
|
30 |
+
from PIL import Image
|
31 |
+
import requests
|
32 |
+
from io import BytesIO
|
33 |
+
|
34 |
+
from transformers import TrOCRProcessor, VisionEncoderDecoderModel, AutoTokenizer
|
35 |
+
|
36 |
+
image_url = "https://datasets-server.huggingface.co/assets/Ransaka/sinhala_synthetic_ocr/--/bf7c8a455b564cd73fe035031e19a5f39babb73b/--/default/train/0/image/image.jpg"
|
37 |
+
response = requests.get(image_url)
|
38 |
+
img = Image.open(BytesIO(response.content))
|
39 |
+
|
40 |
+
processor = TrOCRProcessor.from_pretrained('Ransaka/TrOCR-Sinhala')
|
41 |
+
model = VisionEncoderDecoderModel.from_pretrained('Ransaka/TrOCR-Sinhala')
|
42 |
+
model.to("cuda:0")
|
43 |
+
|
44 |
+
pixel_values = processor(img, return_tensors="pt").pixel_values.to('cuda:0')
|
45 |
+
generated_ids = model.generate(pixel_values,num_beams=2,early_stopping=True)
|
46 |
+
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
47 |
+
generated_text #දිවයිනට බලයට ඇති ආපදා තත්ත්වය හමුවේ සබරගමුව පළාතේ
|
48 |
+
```
|
49 |
+
|
50 |
### Framework versions
|
51 |
|
52 |
- Transformers 4.35.2
|