Skip to content

Commit

Permalink
Update is_hubai_available to work with hubAI API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ptoupas committed Jan 10, 2025
1 parent c4b1a5d commit e97a453
Showing 1 changed file with 20 additions and 29 deletions.
49 changes: 20 additions & 29 deletions modelconverter/utils/hubai_utils.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
import requests


def is_hubai_available(model_slug: str) -> bool:
url = "https://easyml.cloud.luxonis.com/models/api/v1/models?is_public=true&limit=1000"
response = requests.get(url)
if response.status_code != 200:
from modelconverter.cli import Request, slug_to_id

model_name = model_slug.split(":")[0]
if len(model_slug.split(":")) < 2:
raise ValueError(
f"Failed to get models. Status code: {response.status_code}"
f"Model variant not found in {model_slug}. Please specify it."
)
hub_ai_models = response.json()
for model in hub_ai_models:
slug = f"{model['team_slug']}/{model['slug']}"

model_id = slug_to_id(
model_slug.removeprefix("luxonis/").split(":")[0], "models"
)
model_variants = Request.get(
"modelVersions/", params={"model_id": model_id, "is_public": True}
)

for version in model_variants:
if (
slug in model_slug
or slug.removeprefix(f"{model['team_slug']}/") in model_slug
f"{model_name}:{version['variant_slug']}" == model_slug
or f"{model_name}:{version['variant_slug']}".removeprefix(
"luxonis/"
)
== model_slug
):
model_id = model["id"]
return True

url = f"https://easyml.cloud.luxonis.com/models/api/v1/modelVersions?model_id={model_id}&is_public=true"
response = requests.get(url)
if response.status_code != 200:
raise ValueError(
f"Failed to get model versions. Status code: {response.status_code}"
)
model_versions = response.json()
for version in model_versions:
if (
f"{slug}:{version['variant_slug']}" == model_slug
or f"{slug}:{version['variant_slug']}".removeprefix(
f"{model['team_slug']}/"
)
== model_slug
):
return True
return False

0 comments on commit e97a453

Please sign in to comment.