Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use specific URL method for apps #257

Merged
merged 3 commits into from
Dec 29, 2023
Merged

Conversation

isaac-chung
Copy link
Contributor

@isaac-chung isaac-chung commented Dec 28, 2023

Problem

Users should be able to use the web URL e.g. "https://clarifai.com/Isaac/let-me-see-if-this-works1" to instantiate an App object.

Code snippet used:

from clarifai.client.app import App
app = App("https://clarifai.com/Isaac/let-me-see-if-this-works1")

Actual Behaviour:

In [6]: app = App("https://clarifai.com/Isaac/let-me-see-if-this-works1")
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>:1                                                                                    │
│                                                                                                  │
│ /Users/isaacchung/virtualenv/v1/lib/python3.10/site-packages/clarifai/client/app.py:50 in        │
│ __init__                                                                                         │
│                                                                                                  │
│    47 │   if url and app_id:                                                                     │
│    48 │     raise UserError("You can only specify one of url or app_id.")                        │
│    49 │   if url:                                                                                │
│ ❱  50 │     user_id, app_id, _, _, _ = ClarifaiUrlHelper.split_clarifai_url(url)                 │
│    51 │     kwargs = {'user_id': user_id}                                                        │
│    52 │   self.kwargs = {**kwargs, 'id': app_id}                                                 │
│    53 │   self.app_info = resources_pb2.App(**self.kwargs)                                       │
│                                                                                                  │
│ /Users/isaacchung/virtualenv/v1/lib/python3.10/site-packages/clarifai/urls/helper.py:76 in       │
│ split_clarifai_url                                                                               │
│                                                                                                  │
│    73 │   path = path.lstrip("/")                                                                │
│    74 │   parts = path.split("/")                                                                │
│    75 │   if len(parts) != 5 and len(parts) != 7:                                                │
│ ❱  76 │     raise ValueError(                                                                    │
│    77 │   │     "Provided url must have 4 or 6 parts after the domain name. These are: {user_i   │
│    78 │     )                                                                                    │
│    79 │   user_id, app_id, resource_type, resource_id = parts[1:5]                               │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: Provided url must have 4 or 6 parts after the domain name. These are: {user_id}/{app_id}/{resource_type}/{resource_id}/{resource_version_type}/{resource_version_id}

Fix

Use an app-specific url parser method to handle URLs that only have 3 parts (host, user_id, app_id).

@isaac-chung isaac-chung marked this pull request as ready for review December 28, 2023 17:38
Copy link
Contributor

@sainivedh sainivedh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct.

@sainivedh
Copy link
Contributor

sainivedh commented Dec 29, 2023

@isaac-chung Any idea why the test fails for margin-100-image-crop model 🤔 ?

@isaac-chung isaac-chung merged commit 006d02b into master Dec 29, 2023
17 checks passed
@isaac-chung isaac-chung deleted the isaac/fix-app-url-parsing branch December 29, 2023 07:50
@sainivedh sainivedh mentioned this pull request Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants