dsupa commited on
Commit
abe62d8
1 Parent(s): d952fbc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +12 -9
README.md CHANGED
@@ -24,16 +24,19 @@ Here is how to use this model in PyTorch:
24
  ```python
25
  from transformers import TrOCRProcessor, VisionEncoderDecoderModel
26
  from PIL import Image
27
- import requests
28
 
29
- # load image
30
- url = 'https://huggingface.co/dsupa/mangaocr-hoogberta-v1/to_test_hf_model/test1.jpg'
31
- image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
32
 
33
- processor = TrOCRProcessor.from_pretrained('dsupa/mangaocr-hoogberta-v1')
34
- model = VisionEncoderDecoderModel.from_pretrained('dsupa/mangaocr-hoogberta-v1')
35
- pixel_values = processor(images=image, return_tensors="pt").pixel_values
 
 
36
 
37
- generated_ids = model.generate(pixel_values)
38
- generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
 
 
 
39
  ```
 
24
  ```python
25
  from transformers import TrOCRProcessor, VisionEncoderDecoderModel
26
  from PIL import Image
 
27
 
28
+ processor = TrOCRProcessor.from_pretrained('dsupa/mangaocr-hoogberta-v2')
29
+ model = VisionEncoderDecoderModel.from_pretrained('dsupa/mangaocr-hoogberta-v2')
 
30
 
31
+ def predict(image_path):
32
+ image = Image.open(image_path).convert("RGB")
33
+ pixel_values = processor(images=image, return_tensors="pt").pixel_values
34
+ generated_ids = model.generate(pixel_values)
35
+ generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
36
 
37
+ return generated_text
38
+
39
+ image_path = "your_img.jpg"
40
+ pred = predit(image_path)
41
+ print(pred)
42
  ```