Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
moved client into azure preprocessing
Browse files
main.py
CHANGED
|
@@ -25,12 +25,31 @@ SIMSHIP_WEBHOOK_SECRET = os.environ.get("SIMSHIP_WEBHOOK_SECRET")
|
|
| 25 |
AZURE_SUBSCRIPTION_ID = os.getenv('AZURE_SUBSCRIPTION_ID')
|
| 26 |
AZURE_RESOURCE_GROUP = os.getenv('AZURE_RESOURCE_GROUP')
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
def send_slack_message(payload: dict, max_retries: int = 3, timeout: int = 10, retry_delay: int = 2):
|
| 36 |
"""
|
|
@@ -186,25 +205,6 @@ def process_simship_webhook(data: dict):
|
|
| 186 |
else:
|
| 187 |
pass
|
| 188 |
|
| 189 |
-
def archive_model_in_azure(model_id: str) -> None:
|
| 190 |
-
name = model_id.replace("/", "-").replace("_", "-").lower()
|
| 191 |
-
models = list(client.models.list(name=name))
|
| 192 |
-
if len(models) < 1:
|
| 193 |
-
msg = f"Model {name} not available in Azure ML, then no need to delete anything."
|
| 194 |
-
logger.error(msg)
|
| 195 |
-
raise ValueError(msg)
|
| 196 |
-
|
| 197 |
-
for model in models:
|
| 198 |
-
try:
|
| 199 |
-
client.models.archive(name=model.name, version=model.version) # type: ignore
|
| 200 |
-
logger.info(f"Archived {model.name=} {model.version=}")
|
| 201 |
-
except Exception as e:
|
| 202 |
-
msg = f"Failed when archiving model with {name=} with exception {e}"
|
| 203 |
-
logger.error(msg)
|
| 204 |
-
raise RuntimeError(msg)
|
| 205 |
-
|
| 206 |
-
logger.info(f"Model {name} already archived on Azure ML!")
|
| 207 |
-
|
| 208 |
app = FastAPI()
|
| 209 |
|
| 210 |
@app.post("/webhook/model-catalog")
|
|
|
|
| 25 |
AZURE_SUBSCRIPTION_ID = os.getenv('AZURE_SUBSCRIPTION_ID')
|
| 26 |
AZURE_RESOURCE_GROUP = os.getenv('AZURE_RESOURCE_GROUP')
|
| 27 |
|
| 28 |
+
def archive_model_in_azure(model_id: str) -> None:
|
| 29 |
+
client = MLClient(
|
| 30 |
+
credential=DefaultAzureCredential(),
|
| 31 |
+
subscription_id=AZURE_SUBSCRIPTION_ID,
|
| 32 |
+
resource_group_name=AZURE_RESOURCE_GROUP,
|
| 33 |
+
registry_name="HuggingFace",
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
name = model_id.replace("/", "-").replace("_", "-").lower()
|
| 37 |
+
models = list(client.models.list(name=name))
|
| 38 |
+
if len(models) < 1:
|
| 39 |
+
msg = f"Model {name} not available in Azure ML, then no need to delete anything."
|
| 40 |
+
logger.error(msg)
|
| 41 |
+
raise ValueError(msg)
|
| 42 |
+
|
| 43 |
+
for model in models:
|
| 44 |
+
try:
|
| 45 |
+
client.models.archive(name=model.name, version=model.version) # type: ignore
|
| 46 |
+
logger.info(f"Archived {model.name=} {model.version=}")
|
| 47 |
+
except Exception as e:
|
| 48 |
+
msg = f"Failed when archiving model with {name=} with exception {e}"
|
| 49 |
+
logger.error(msg)
|
| 50 |
+
raise RuntimeError(msg)
|
| 51 |
+
|
| 52 |
+
logger.info(f"Model {name} already archived on Azure ML!")
|
| 53 |
|
| 54 |
def send_slack_message(payload: dict, max_retries: int = 3, timeout: int = 10, retry_delay: int = 2):
|
| 55 |
"""
|
|
|
|
| 205 |
else:
|
| 206 |
pass
|
| 207 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
app = FastAPI()
|
| 209 |
|
| 210 |
@app.post("/webhook/model-catalog")
|