Ransaka commited on
Commit
a0e8378
1 Parent(s): ebbbe36

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +18 -18
README.md CHANGED
@@ -27,24 +27,24 @@ 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
 
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