Upload lightonai_LightOnOCR-1B-1025_1.txt with huggingface_hub
Browse files
lightonai_LightOnOCR-1B-1025_1.txt
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
```CODE:
|
| 2 |
+
# Get a test image
|
| 3 |
+
image_url = "https://jeroen.github.io/images/testocr.png"
|
| 4 |
+
response = requests.get(image_url)
|
| 5 |
+
image = Image.open(BytesIO(response.content)).convert("RGB")
|
| 6 |
+
|
| 7 |
+
display(image)
|
| 8 |
+
|
| 9 |
+
# Run inference
|
| 10 |
+
messages = [{"role": "user", "content": [{"type": "image"}]}]
|
| 11 |
+
text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 12 |
+
|
| 13 |
+
inputs = processor(text=[text], images=[image], return_tensors="pt").to(device)
|
| 14 |
+
inputs["pixel_values"] = inputs["pixel_values"].to(torch.bfloat16)
|
| 15 |
+
|
| 16 |
+
outputs = model.generate(
|
| 17 |
+
**inputs,
|
| 18 |
+
max_new_tokens=1024,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
input_length = inputs['input_ids'].shape[1]
|
| 22 |
+
generated_text = processor.tokenizer.decode(outputs[0, input_length:], skip_special_tokens=True)
|
| 23 |
+
|
| 24 |
+
print("============
|
| 25 |
+
")
|
| 26 |
+
print(generated_text)
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
ERROR:
|
| 30 |
+
Traceback (most recent call last):
|
| 31 |
+
File "/tmp/lightonai_LightOnOCR-1B-1025_1puSIaX.py", line 18, in <module>
|
| 32 |
+
response = requests.get(image_url)
|
| 33 |
+
^^^^^^^^
|
| 34 |
+
NameError: name 'requests' is not defined
|