Skip to content

Commit 4167290

Browse files
committed
Have 'terraform apply' successfully deploying label studio to huggingface spaces in the 'gcp-modular' directory - created a 'label-studio-hf-module'. Made changes to add options in constants and enums for the new label studio component, and updated logic to allow 'huggingface' to be accepted as a provider at the component level
1 parent cc15953 commit 4167290

File tree

10 files changed

+190
-3
lines changed

10 files changed

+190
-3
lines changed

src/mlstacks/constants.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
MLSTACKS_PACKAGE_NAME = "mlstacks"
1818
MLSTACKS_INITIALIZATION_FILE_FLAG = "IGNORE_ME"
1919
MLSTACKS_STACK_COMPONENT_FLAGS = [
20+
"annotator",
2021
"artifact_store",
2122
"container_registry",
2223
"experiment_tracker", # takes flavor
@@ -26,6 +27,7 @@
2627
"step_operator", # takes flavor
2728
]
2829
ALLOWED_FLAVORS = {
30+
"annotator": ["label_studio"],
2931
"artifact_store": ["s3", "gcp", "minio"],
3032
"container_registry": ["gcp", "aws", "default"],
3133
"experiment_tracker": ["mlflow"],
@@ -43,7 +45,8 @@
4345
}
4446
ALLOWED_COMPONENT_TYPES: Dict[str, Dict[str, List[str]]] = {
4547
"aws": {
46-
"artifact_store": ["s3"],
48+
"annotator": ["huggingface"],
49+
"artifact_store": ["s3"],
4750
"container_registry": ["aws"],
4851
"experiment_tracker": ["mlflow"],
4952
"orchestrator": [
@@ -59,6 +62,7 @@
5962
},
6063
"azure": {},
6164
"gcp": {
65+
"annotator": ["huggingface"],
6266
"artifact_store": ["gcp"],
6367
"container_registry": ["gcp"],
6468
"experiment_tracker": ["mlflow"],
@@ -73,6 +77,9 @@
7377
"model_deployer": ["seldon"],
7478
"step_operator": ["vertex"],
7579
},
80+
"huggingface": {
81+
"annotator": ["label_studio"],
82+
},
7683
"k3d": {
7784
"artifact_store": ["minio"],
7885
"container_registry": ["default"],

src/mlstacks/enums.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ComponentFlavorEnum(str, Enum):
4040
GCP = "gcp"
4141
KUBEFLOW = "kubeflow"
4242
KUBERNETES = "kubernetes"
43+
LABEL_STUDIO = "label_studio"
4344
MINIO = "minio"
4445
MLFLOW = "mlflow"
4546
S3 = "s3"
@@ -65,6 +66,7 @@ class ProviderEnum(str, Enum):
6566
AZURE = "azure"
6667
GCP = "gcp"
6768
K3D = "k3d"
69+
HUGGINGFACE = "huggingface"
6870

6971

7072
class AnalyticsEventsEnum(str, Enum):
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
provider "huggingface-spaces" {
2+
# alias = "strickvl"
3+
token = var.huggingface_token
4+
}
5+
6+
# using the labelstudio huggingface module to create a label studio space on huggingface
7+
8+
module "label_studio_hf" {
9+
source = "../modules/label-studio-hf-module"
10+
# providers = {
11+
# huggingface-spaces.strickvl = huggingface-spaces.strickvl
12+
# }
13+
count = var.enable_annotator ? 1 : 0
14+
huggingface_token = var.huggingface_token
15+
enable_annotator = var.enable_annotator
16+
}
17+
18+
output "module_huggingface_token" {
19+
value = length(module.label_studio_hf) > 0 ? module.label_studio_hf[0].huggingface_token_passed : ""
20+
sensitive = true
21+
}
22+
23+
output "token_hash" {
24+
value = sha256(module.label_studio_hf[0].huggingface_token_passed)
25+
sensitive = true
26+
}
27+

src/mlstacks/terraform/gcp-modular/terraform.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ terraform {
2929
source = "loafoe/htpasswd"
3030
version = "1.0.3"
3131
}
32+
33+
huggingface-spaces = {
34+
source = "strickvl/huggingface-spaces"
35+
version = ">= 0.0.4" # Specify the version or version constraint here
36+
}
3237
}
3338

3439
backend "local" {
35-
config = {}
40+
# config = {}
3641
}
3742

3843
required_version = ">= 0.14.8"

src/mlstacks/terraform/gcp-modular/variables.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ variable "enable_experiment_tracker_mlflow" {
2727
description = "Enable MLflow deployment"
2828
default = false
2929
}
30+
31+
variable "enable_annotator" {
32+
description = "Enable Label Studio deployment"
33+
type = bool
34+
default = true
35+
}
36+
37+
variable "huggingface_token" {
38+
description = "Huggingface token"
39+
type = string
40+
# sensitive = true
41+
default = ""
42+
}
43+
3044
variable "enable_model_deployer_seldon" {
3145
description = "Enable Seldon deployment"
3246
default = false
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
resource "huggingface-spaces_space" "ls_space" {
2+
provider = huggingface-spaces
3+
name = "label-studio-hf-module-${formatdate("YYYYMMDD", timestamp())}"
4+
private = false
5+
sdk = "docker"
6+
template = "LabelStudio/LabelStudio"
7+
8+
hardware = var.label_studio_hardware
9+
sleep_time = var.label_studio_sleep_time
10+
storage = "small"
11+
}
12+
13+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
data "huggingface-spaces_space" "ls_space_data" {
2+
id = huggingface-spaces_space.ls_space.id
3+
}
4+
5+
output "label_studio_id" {
6+
value = huggingface-spaces_space.ls_space.id
7+
}
8+
9+
output "label_studio_name" {
10+
value = data.huggingface-spaces_space.ls_space_data.name
11+
}
12+
13+
output "label_studio_author" {
14+
value = data.huggingface-spaces_space.ls_space_data.author
15+
}
16+
17+
output "label_studio_last_modified" {
18+
value = data.huggingface-spaces_space.ls_space_data.last_modified
19+
}
20+
21+
output "label_studio_likes" {
22+
value = data.huggingface-spaces_space.ls_space_data.likes
23+
}
24+
25+
output "label_studio_private" {
26+
value = data.huggingface-spaces_space.ls_space_data.private
27+
}
28+
29+
output "label_studio_sdk" {
30+
value = data.huggingface-spaces_space.ls_space_data.sdk
31+
}
32+
33+
output "label_studio_hardware" {
34+
value = data.huggingface-spaces_space.ls_space_data.hardware
35+
}
36+
37+
output "huggingface_token_passed" {
38+
value = var.huggingface_token
39+
}
40+
41+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_providers {
3+
huggingface-spaces = {
4+
source = "strickvl/huggingface-spaces"
5+
version = ">= 0.0.4"
6+
# configuration_aliases = [huggingface-spaces.strickvl]
7+
}
8+
}
9+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
variable "huggingface_token" {
2+
type = string
3+
description = "The Hugging Face API token."
4+
sensitive = true
5+
}
6+
7+
variable "enable_annotator" {
8+
type = bool
9+
description = "Enable annotator for the Label Studio instance."
10+
default = false
11+
}
12+
13+
variable "enable_persistent_storage" {
14+
type = bool
15+
description = "Enable persistent storage for the Label Studio instance."
16+
default = false
17+
}
18+
19+
variable "persistent_storage_size" {
20+
type = string
21+
description = "The size of the persistent storage for the Label Studio instance."
22+
default = "small"
23+
}
24+
25+
variable "label_studio_disable_signup_without_link" {
26+
type = bool
27+
description = "Disable the signup without link for the Label Studio instance."
28+
default = false
29+
}
30+
31+
variable "label_studio_username" {
32+
type = string
33+
description = "The username for the Label Studio instance."
34+
default = "[email protected]"
35+
sensitive = true
36+
}
37+
38+
variable "label_studio_password" {
39+
type = string
40+
description = "The password for the Label Studio instance."
41+
default = "mlstacks"
42+
sensitive = true
43+
}
44+
45+
variable "label_studio_hardware" {
46+
type = string
47+
description = "The hardware for the Label Studio instance."
48+
default = "cpu-basic"
49+
}
50+
51+
variable "label_studio_template" {
52+
type = string
53+
description = "The template for the Label Studio instance."
54+
default = "LabelStudio/LabelStudio"
55+
}
56+
57+
variable "label_studio_sleep_time" {
58+
type = string
59+
description = "The sleep time in seconds for the Label Studio instance. (gc_timeout)"
60+
default = "3600"
61+
}
62+
63+
variable "label_studio_private" {
64+
type = bool
65+
description = "The private flag for the Label Studio instance."
66+
default = false
67+
}
68+
69+

src/mlstacks/utils/yaml_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def load_stack_yaml(path: str) -> Stack:
122122
)
123123

124124
for component in stack.components:
125-
if component.provider != stack.provider:
125+
if component.provider != stack.provider and component.provider != "huggingface":
126126
raise ValueError(STACK_COMPONENT_PROVIDER_MISMATCH_ERROR_MESSAGE)
127127

128128
return stack

0 commit comments

Comments
 (0)