ariG23498 HF Staff commited on
Commit
d8f0a18
·
verified ·
1 Parent(s): df43196

Upload lightonai_LightOnOCR-1B-1025_0.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. lightonai_LightOnOCR-1B-1025_0.py +26 -12
lightonai_LightOnOCR-1B-1025_0.py CHANGED
@@ -4,6 +4,8 @@
4
  # "torch",
5
  # "torchvision",
6
  # "transformers",
 
 
7
  # "accelerate",
8
  # "peft",
9
  # "slack-sdk",
@@ -11,13 +13,19 @@
11
  # ///
12
 
13
  try:
14
- # integration status unknown.
15
-
16
- # Please clone model and use locally.
 
 
17
 
18
- # Also feel free to open a Pull request
19
- # for integration of the huggingface model hub
20
- # into the corresponding library =)
 
 
 
 
21
  with open('lightonai_LightOnOCR-1B-1025_0.txt', 'w', encoding='utf-8') as f:
22
  f.write('Everything was good in lightonai_LightOnOCR-1B-1025_0.txt')
23
  except Exception as e:
@@ -32,13 +40,19 @@ except Exception as e:
32
  with open('lightonai_LightOnOCR-1B-1025_0.txt', 'a', encoding='utf-8') as f:
33
  import traceback
34
  f.write('''```CODE:
35
- # integration status unknown.
36
-
37
- # Please clone model and use locally.
 
 
 
 
 
 
38
 
39
- # Also feel free to open a Pull request
40
- # for integration of the huggingface model hub
41
- # into the corresponding library =)
42
  ```
43
 
44
  ERROR:
 
4
  # "torch",
5
  # "torchvision",
6
  # "transformers",
7
+ # "diffusers",
8
+ # "sentence-transformers",
9
  # "accelerate",
10
  # "peft",
11
  # "slack-sdk",
 
13
  # ///
14
 
15
  try:
16
+ import torch
17
+ from PIL import Image
18
+ from transformers import AutoProcessor, LightOnOCRForConditionalGeneration
19
+ import requests
20
+ from io import BytesIO
21
 
22
+ # Load Model
23
+ model_id = "lightonai/LightOnOCR-1B-1025"
24
+ device = "cuda" if torch.cuda.is_available() else "cpu"
25
+
26
+ processor = AutoProcessor.from_pretrained(model_id)
27
+ model = LightOnOCRForConditionalGeneration.from_pretrained(model_id, dtype=torch.bfloat16, device_map=device, attn_implementation="sdpa")
28
+ model.eval();
29
  with open('lightonai_LightOnOCR-1B-1025_0.txt', 'w', encoding='utf-8') as f:
30
  f.write('Everything was good in lightonai_LightOnOCR-1B-1025_0.txt')
31
  except Exception as e:
 
40
  with open('lightonai_LightOnOCR-1B-1025_0.txt', 'a', encoding='utf-8') as f:
41
  import traceback
42
  f.write('''```CODE:
43
+ import torch
44
+ from PIL import Image
45
+ from transformers import AutoProcessor, LightOnOCRForConditionalGeneration
46
+ import requests
47
+ from io import BytesIO
48
+
49
+ # Load Model
50
+ model_id = "lightonai/LightOnOCR-1B-1025"
51
+ device = "cuda" if torch.cuda.is_available() else "cpu"
52
 
53
+ processor = AutoProcessor.from_pretrained(model_id)
54
+ model = LightOnOCRForConditionalGeneration.from_pretrained(model_id, dtype=torch.bfloat16, device_map=device, attn_implementation="sdpa")
55
+ model.eval();
56
  ```
57
 
58
  ERROR: