Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,74 +3,42 @@ import sagemaker
|
|
| 3 |
import boto3
|
| 4 |
from sagemaker.huggingface import HuggingFaceModel, get_huggingface_llm_image_uri
|
| 5 |
|
|
|
|
| 6 |
try:
|
| 7 |
-
|
| 8 |
except ValueError:
|
| 9 |
-
|
| 10 |
-
|
| 11 |
|
| 12 |
-
#
|
| 13 |
hub = {
|
| 14 |
-
|
| 15 |
-
|
| 16 |
}
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
# create Hugging Face Model Class
|
| 21 |
huggingface_model = HuggingFaceModel(
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
)
|
| 26 |
|
| 27 |
-
#
|
| 28 |
predictor = huggingface_model.deploy(
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
# send request
|
| 35 |
-
predictor.predict({
|
| 36 |
-
"inputs": "Hi, what can you help me with?",
|
| 37 |
-
})
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
import json
|
| 41 |
-
import sagemaker
|
| 42 |
-
import boto3
|
| 43 |
-
from sagemaker.huggingface import HuggingFaceModel, get_huggingface_llm_image_uri
|
| 44 |
-
|
| 45 |
-
try:
|
| 46 |
-
role = sagemaker.get_execution_role()
|
| 47 |
-
except ValueError:
|
| 48 |
-
iam = boto3.client('iam')
|
| 49 |
-
role = iam.get_role(RoleName='sagemaker_execution_role')['Role']['Arn']
|
| 50 |
-
|
| 51 |
-
# Hub Model configuration. https://huggingface.co/models
|
| 52 |
-
hub = {
|
| 53 |
-
'HF_MODEL_ID':'praneethposina/customer_support_bot',
|
| 54 |
-
'SM_NUM_GPUS': json.dumps(1)
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
# create Hugging Face Model Class
|
| 60 |
-
huggingface_model = HuggingFaceModel(
|
| 61 |
-
image_uri=get_huggingface_llm_image_uri("huggingface",version="3.2.3"),
|
| 62 |
-
env=hub,
|
| 63 |
-
role=role,
|
| 64 |
)
|
| 65 |
|
| 66 |
-
#
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
# send request
|
| 74 |
-
predictor.predict({
|
| 75 |
-
"inputs": "Hi, what can you help me with?",
|
| 76 |
-
})
|
|
|
|
| 3 |
import boto3
|
| 4 |
from sagemaker.huggingface import HuggingFaceModel, get_huggingface_llm_image_uri
|
| 5 |
|
| 6 |
+
# Get IAM execution role
|
| 7 |
try:
|
| 8 |
+
role = sagemaker.get_execution_role()
|
| 9 |
except ValueError:
|
| 10 |
+
iam = boto3.client('iam')
|
| 11 |
+
role = iam.get_role(RoleName='sagemaker_execution_role')['Role']['Arn']
|
| 12 |
|
| 13 |
+
# Hugging Face model configuration
|
| 14 |
hub = {
|
| 15 |
+
'HF_MODEL_ID': 'praneethposina/customer_support_bot',
|
| 16 |
+
'SM_NUM_GPUS': json.dumps(1),
|
| 17 |
}
|
| 18 |
|
| 19 |
+
# Get the correct image URI for Hugging Face LLM
|
| 20 |
+
image_uri = get_huggingface_llm_image_uri(
|
| 21 |
+
backend="huggingface",
|
| 22 |
+
version="3.2.3"
|
| 23 |
+
)
|
| 24 |
|
| 25 |
+
# Create HuggingFaceModel instance
|
|
|
|
| 26 |
huggingface_model = HuggingFaceModel(
|
| 27 |
+
image_uri=image_uri,
|
| 28 |
+
env=hub,
|
| 29 |
+
role=role
|
| 30 |
)
|
| 31 |
|
| 32 |
+
# Deploy the model to SageMaker
|
| 33 |
predictor = huggingface_model.deploy(
|
| 34 |
+
initial_instance_count=1,
|
| 35 |
+
instance_type="ml.g5.2xlarge",
|
| 36 |
+
container_startup_health_check_timeout=300,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
)
|
| 38 |
|
| 39 |
+
# Perform inference
|
| 40 |
+
response = predictor.predict({
|
| 41 |
+
"inputs": "Hi, what can you help me with?"
|
| 42 |
+
})
|
| 43 |
+
|
| 44 |
+
print("Model Response:", response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|