Update README.md
Browse files
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 |
-
|
30 |
-
|
31 |
-
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
pixel_values = processor(images=image, return_tensors="pt").pixel_values
|
|
|
|
|
36 |
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
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 |
```
|