File size: 1,627 Bytes
3ef158d
 
 
 
 
c3dcd04
3ef158d
c3dcd04
3ef158d
c3dcd04
3ef158d
c3dcd04
 
3ef158d
c3dcd04
 
3ef158d
 
c3dcd04
 
3ef158d
c3dcd04
3ef158d
c3dcd04
 
3ef158d
c3dcd04
 
3ef158d
c3dcd04
3ef158d
c3dcd04
 
 
 
 
 
 
 
3ef158d
c3dcd04
3ef158d
c3dcd04
 
3ef158d
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
---
library_name: transformers
tags: []
---

# Model Card for Florence-2-FT-ArabicOCR

Florence-2 for ArabicOCR

## Usage 

```python
import requests

from PIL import Image
from transformers import AutoProcessor, AutoModelForCausalLM 


model = AutoModelForCausalLM.from_pretrained("gagan3012/Florence-2-FT-ArabicOCR", trust_remote_code=True)
processor = AutoProcessor.from_pretrained("gagan3012/Florence-2-FT-ArabicOCR", trust_remote_code=True)

prompt = "<ArabicOCR>"

url = "https://datasets-server.huggingface.co/cached-assets/Fakhraddin/khatt/--/a3236e1dee690fbb4ce9ceadac24b2be375f5503/--/default/validation/0/image/image.jpg?Expires=1719446453&Signature=WaBqdA7YWlwmyVFf~Nr4l0Qm6uM34p9e7Df4GPLNA93qhg7VS3JgZpqHvHWA3ZRqaz7JbPANNSrEv27lskSAGcZ6ow168Lv2Yzkemv87mA6sbED9UqTQAyeSWgCZ6z-3OUHLIfHRtrlsSetKDSyhKSYhIHARx8tI-Z35wOhTXnPDWbq63rtrFQ1YFc~u-YzETwn7SWqXO-NJpl-JZ~xPSbYHzrDQtZgFxnrC~aEyVzJXdfdQ8v7AxzRoz5I6ISimDADy-KGu0d6LuYd3eAwf-LWwGbLEeNYtMZgevRJIFeDxi-75lYitmxiVG0BLfNFtJAJGYvjpeLsug0cIwo-pAg__&Key-Pair-Id=K3EI6M078Z3AC3"
image = Image.open(requests.get(url, stream=True).raw)

if image.mode != "RGB":
    image = image.convert("RGB")

inputs = processor(text=prompt, images=image, return_tensors="pt")

generated_ids = model.generate(
    input_ids=inputs["input_ids"],
    pixel_values=inputs["pixel_values"],
    max_new_tokens=1024,
    do_sample=False,
    num_beams=3
)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=False)[0]

parsed_answer = processor.post_process_generation(generated_text, task="<ArabicOCR>", image_size=(image.width, image.height))

print(parsed_answer)
```