Upload handler.py with huggingface_hub
Browse files- handler.py +14 -1
handler.py
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import base64
|
| 3 |
import io
|
|
@@ -28,7 +41,7 @@ class EndpointHandler:
|
|
| 28 |
image_b64 = inputs_data
|
| 29 |
prompt = "Text Recognition:"
|
| 30 |
else:
|
| 31 |
-
return [{"error": "Send {inputs: {image:
|
| 32 |
|
| 33 |
try:
|
| 34 |
image_bytes = base64.b64decode(image_b64)
|
|
|
|
| 1 |
+
import subprocess
|
| 2 |
+
import sys
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Install transformers from source BEFORE any transformers import
|
| 6 |
+
if not os.path.exists("/tmp/.transformers_installed"):
|
| 7 |
+
subprocess.check_call([
|
| 8 |
+
sys.executable, "-m", "pip", "install", "-q", "--upgrade",
|
| 9 |
+
"git+https://github.com/huggingface/transformers.git",
|
| 10 |
+
"accelerate"
|
| 11 |
+
])
|
| 12 |
+
open("/tmp/.transformers_installed", "w").close()
|
| 13 |
+
|
| 14 |
import torch
|
| 15 |
import base64
|
| 16 |
import io
|
|
|
|
| 41 |
image_b64 = inputs_data
|
| 42 |
prompt = "Text Recognition:"
|
| 43 |
else:
|
| 44 |
+
return [{"error": "Send {inputs: {image: base64, prompt: str}}"}]
|
| 45 |
|
| 46 |
try:
|
| 47 |
image_bytes = base64.b64decode(image_b64)
|