Update handler.py
Browse files- handler.py +21 -0
handler.py
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from transformers import AutoProcessor, AutoModelForImageTextToText
|
| 2 |
import torch
|
| 3 |
from PIL import Image
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import sys
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Install transformers dev build that supports paddleocr_vl
|
| 6 |
+
subprocess.check_call([
|
| 7 |
+
sys.executable, "-m", "pip", "install", "--quiet", "--upgrade",
|
| 8 |
+
"git+https://github.com/huggingface/transformers.git",
|
| 9 |
+
])
|
| 10 |
+
|
| 11 |
+
# Monkey-patch old API that huggingface_inference_toolkit depends on
|
| 12 |
+
import transformers
|
| 13 |
+
if not hasattr(transformers, "file_utils"):
|
| 14 |
+
import types
|
| 15 |
+
file_utils_shim = types.ModuleType("transformers.file_utils")
|
| 16 |
+
# Provide stubs for commonly used symbols
|
| 17 |
+
file_utils_shim.is_tf_available = transformers.utils.is_tf_available
|
| 18 |
+
file_utils_shim.is_torch_available = transformers.utils.is_torch_available
|
| 19 |
+
sys.modules["transformers.file_utils"] = file_utils_shim
|
| 20 |
+
transformers.file_utils = file_utils_shim
|
| 21 |
+
|
| 22 |
from transformers import AutoProcessor, AutoModelForImageTextToText
|
| 23 |
import torch
|
| 24 |
from PIL import Image
|