Spaces:
Running
Running
Commit
·
51a9bb2
1
Parent(s):
53bf45b
Create service.py
Browse files- service.py +27 -0
service.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import bentoml
|
| 2 |
+
|
| 3 |
+
from bentoml.io import Image, JSON
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
from transformers import AutoFeatureExtractor, AutoModelForObjectDetection
|
| 6 |
+
|
| 7 |
+
class PretrainedModelRunnable(bentoml.Runnable):
|
| 8 |
+
SUPPORTED_RESOURCES = ("cpu",)
|
| 9 |
+
SUPPORTS_CPU_MULTI_THREADING = True
|
| 10 |
+
|
| 11 |
+
def __init__(self):
|
| 12 |
+
self.unmasker = pipeline('object-detection', model="davanstrien/detr-resnet-50_fine_tuned_nls_chapbooks",
|
| 13 |
+
feature_extractor="davanstrien/detr-resnet-50_fine_tuned_nls_chapbooks")
|
| 14 |
+
|
| 15 |
+
@bentoml.Runnable.method(batchable=True)
|
| 16 |
+
def __call__(self, input_text):
|
| 17 |
+
return self.unmasker(input_text)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
runner = bentoml.Runner(PretrainedModelRunnable, name="pretrained_illustration_detection")
|
| 21 |
+
|
| 22 |
+
svc = bentoml.Service('pretrained_illustration_detection', runners=[runner])
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@svc.api(input=Image(), output=JSON())
|
| 26 |
+
async def object_detect(input_series: str) -> list:
|
| 27 |
+
return await runner.async_run(input_series)
|