ariG23498 HF Staff commited on
Commit
e71ad58
·
verified ·
1 Parent(s): bb4dc58

Upload PaddlePaddle_PaddleOCR-VL-1.5_0.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. PaddlePaddle_PaddleOCR-VL-1.5_0.py +68 -0
PaddlePaddle_PaddleOCR-VL-1.5_0.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # /// script
2
+ # requires-python = ">=3.12"
3
+ # dependencies = [
4
+ # "numpy",
5
+ # "einops",
6
+ # "pandas",
7
+ # "matplotlib",
8
+ # "protobuf",
9
+ # "torch",
10
+ # "sentencepiece",
11
+ # "torchvision",
12
+ # "transformers",
13
+ # "timm",
14
+ # "diffusers",
15
+ # "sentence-transformers",
16
+ # "accelerate",
17
+ # "peft",
18
+ # "slack-sdk",
19
+ # ]
20
+ # ///
21
+
22
+ try:
23
+ # See https://www.paddleocr.ai/latest/version3.x/pipeline_usage/PaddleOCR-VL.html to installation
24
+
25
+ from paddleocr import PaddleOCRVL
26
+ pipeline = PaddleOCRVL(pipeline_version="v1.5")
27
+ output = pipeline.predict("path/to/document_image.png")
28
+ for res in output:
29
+ res.print()
30
+ res.save_to_json(save_path="output")
31
+ res.save_to_markdown(save_path="output")
32
+ with open('PaddlePaddle_PaddleOCR-VL-1.5_0.txt', 'w', encoding='utf-8') as f:
33
+ f.write('Everything was good in PaddlePaddle_PaddleOCR-VL-1.5_0.txt')
34
+ except Exception as e:
35
+ import os
36
+ from slack_sdk import WebClient
37
+ client = WebClient(token=os.environ['SLACK_TOKEN'])
38
+ client.chat_postMessage(
39
+ channel='#hub-model-metadata-snippets-sprint',
40
+ text='Problem in <https://huggingface.co/datasets/model-metadata/code_execution_files/blob/main/PaddlePaddle_PaddleOCR-VL-1.5_0.txt|PaddlePaddle_PaddleOCR-VL-1.5_0.txt>',
41
+ )
42
+
43
+ with open('PaddlePaddle_PaddleOCR-VL-1.5_0.txt', 'a', encoding='utf-8') as f:
44
+ import traceback
45
+ f.write('''```CODE:
46
+ # See https://www.paddleocr.ai/latest/version3.x/pipeline_usage/PaddleOCR-VL.html to installation
47
+
48
+ from paddleocr import PaddleOCRVL
49
+ pipeline = PaddleOCRVL(pipeline_version="v1.5")
50
+ output = pipeline.predict("path/to/document_image.png")
51
+ for res in output:
52
+ res.print()
53
+ res.save_to_json(save_path="output")
54
+ res.save_to_markdown(save_path="output")
55
+ ```
56
+
57
+ ERROR:
58
+ ''')
59
+ traceback.print_exc(file=f)
60
+
61
+ finally:
62
+ from huggingface_hub import upload_file
63
+ upload_file(
64
+ path_or_fileobj='PaddlePaddle_PaddleOCR-VL-1.5_0.txt',
65
+ repo_id='model-metadata/code_execution_files',
66
+ path_in_repo='PaddlePaddle_PaddleOCR-VL-1.5_0.txt',
67
+ repo_type='dataset',
68
+ )