Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sagemaker.huggingface import HuggingFaceModel
|
| 2 |
+
import sagemaker
|
| 3 |
+
|
| 4 |
+
role = sagemaker.get_execution_role()
|
| 5 |
+
# Hub Model configuration. https://huggingface.co/models
|
| 6 |
+
hub = {
|
| 7 |
+
'HF_MODEL_ID':'dalle-mini/dalle-mega',
|
| 8 |
+
'HF_TASK':'text2text-generation'
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
# create Hugging Face Model Class
|
| 12 |
+
huggingface_model = HuggingFaceModel(
|
| 13 |
+
transformers_version='4.17.0',
|
| 14 |
+
pytorch_version='1.10.2',
|
| 15 |
+
py_version='py38',
|
| 16 |
+
env=hub,
|
| 17 |
+
role=role,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# deploy model to SageMaker Inference
|
| 21 |
+
predictor = huggingface_model.deploy(
|
| 22 |
+
initial_instance_count=1, # number of instances
|
| 23 |
+
instance_type='ml.m5.xlarge' # ec2 instance type
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
predictor.predict({
|
| 27 |
+
'inputs': No input example has been defined for this model task.
|
| 28 |
+
})
|