-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,869 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!--index.html file--> | ||
|
||
<script> | ||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
// In this section, we set the user authentication, app ID, model ID, and model type ID. | ||
// Change these strings to run your own example. | ||
////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
const USER_ID = 'YOUR_USER_ID_HERE'; | ||
// Your PAT (Personal Access Token) can be found in the portal under Authentification | ||
const PAT = 'YOUR_PAT_HERE'; | ||
const APP_ID = 'YOUR_APP_ID_HERE'; | ||
// Change these to create your own model | ||
const MODEL_ID = 'zero-shot-text-model'; | ||
const MODEL_TYPE_ID = 'zero-shot-text-classifier'; | ||
|
||
/////////////////////////////////////////////////////////////////////////////////// | ||
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE | ||
/////////////////////////////////////////////////////////////////////////////////// | ||
|
||
const raw = JSON.stringify({ | ||
'user_app_id': { | ||
'user_id': USER_ID, | ||
'app_id': APP_ID | ||
}, | ||
'model': { | ||
'id': MODEL_ID, | ||
'model_type_id': MODEL_TYPE_ID, | ||
'notes': 'zero shot text classifier' | ||
} | ||
}); | ||
|
||
const requestOptions = { | ||
method: 'POST', | ||
headers: { | ||
'Accept': 'application/json', | ||
'Authorization': 'Key ' + PAT | ||
}, | ||
body: raw | ||
}; | ||
|
||
fetch('https://api.clarifai.com/v2/models', requestOptions) | ||
.then(response => response.text()) | ||
.then(result => console.log(result)) | ||
.catch(error => console.log('error', error)); | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.clarifai.example; | ||
|
||
import com.clarifai.grpc.api.*; | ||
import com.clarifai.channel.ClarifaiChannel; | ||
import com.clarifai.credentials.ClarifaiCallCredentials; | ||
import com.clarifai.grpc.api.status.StatusCode; | ||
|
||
public class ClarifaiExample { | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////// | ||
// In this section, we set the user authentication, app ID, model ID, and model type ID. | ||
// Change these strings to run your own example. | ||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
static final String USER_ID = "YOUR_USER_ID_HERE"; | ||
//Your PAT (Personal Access Token) can be found in the portal under Authentication | ||
static final String PAT = "YOUR_PAT_HERE"; | ||
static final String APP_ID = "YOUR_APP_ID_HERE"; | ||
// Change these to create your own model | ||
static final String MODEL_ID = "zero-shot-text-model"; | ||
static final String MODEL_TYPE_ID = "zero-shot-text-classifier"; | ||
|
||
/////////////////////////////////////////////////////////////////////////////////// | ||
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE | ||
/////////////////////////////////////////////////////////////////////////////////// | ||
|
||
public static void main(String[] args) { | ||
|
||
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel()) | ||
.withCallCredentials(new ClarifaiCallCredentials(PAT)); | ||
|
||
SingleModelResponse postModelsResponse = stub.postModels( | ||
PostModelsRequest.newBuilder() | ||
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID)) | ||
.addModels( | ||
Model.newBuilder() | ||
.setId(MODEL_ID) | ||
.setModelTypeId(MODEL_TYPE_ID) | ||
.setNotes("zero shot text classifier") | ||
).build() | ||
); | ||
|
||
if (postModelsResponse.getStatus().getCode() != StatusCode.SUCCESS) { | ||
throw new RuntimeException("Post models failed, status: " + postModelsResponse.getStatus()); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//index.js file | ||
|
||
//////////////////////////////////////////////////////////////////////////////////////////// | ||
// In this section, we set the user authentication, app ID, model ID, and model type ID. | ||
// Change these strings to run your own example. | ||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
const USER_ID = 'YOUR_USER_ID_HERE'; | ||
// Your PAT (Personal Access Token) can be found in the portal under Authentification | ||
const PAT = 'YOUR_PAT_HERE'; | ||
const APP_ID = 'YOUR_APP_ID_HERE'; | ||
// Change these to create your own model | ||
const MODEL_ID = 'zero-shot-text-model'; | ||
const MODEL_TYPE_ID = 'zero-shot-text-classifier'; | ||
|
||
///////////////////////////////////////////////////////////////////////////// | ||
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE | ||
///////////////////////////////////////////////////////////////////////////// | ||
|
||
const { ClarifaiStub, grpc } = require('clarifai-nodejs-grpc'); | ||
|
||
const stub = ClarifaiStub.grpc(); | ||
|
||
// This will be used by every Clarifai endpoint call | ||
const metadata = new grpc.Metadata(); | ||
metadata.set('authorization', 'Key ' + PAT); | ||
|
||
stub.PostModels( | ||
{ | ||
user_app_id: { | ||
'user_id': USER_ID, | ||
'app_id': APP_ID | ||
}, | ||
models: [ | ||
{ | ||
id: MODEL_ID, | ||
model_type_id: MODEL_TYPE_ID, | ||
notes: 'zero shot text classifier' | ||
} | ||
] | ||
}, | ||
metadata, | ||
(err, response) => { | ||
if (err) { | ||
throw new Error(err); | ||
} | ||
|
||
if (response.status.code !== 10000) { | ||
throw new Error('Post models failed, status: ' + response.status.description); | ||
} | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
require __DIR__ . "/vendor/autoload.php"; | ||
|
||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
// In this section, we set the user authentication, app ID, model ID, and model type ID. | ||
// Change these strings to run your own example. | ||
///////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
$USER_ID = "YOUR_USER_ID_HERE"; | ||
// Your PAT (Personal Access Token) can be found in the portal under Authentification | ||
$PAT = "YOUR_PAT_HERE"; | ||
$APP_ID = "YOUR_APP_ID_HERE"; | ||
// Change these to create your own model | ||
$MODEL_ID = "zero-shot-text-model"; | ||
$MODEL_TYPE_ID = "zero-shot-text-classifier"; | ||
|
||
/////////////////////////////////////////////////////////////////////////////////// | ||
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE | ||
/////////////////////////////////////////////////////////////////////////////////// | ||
|
||
use Clarifai\ClarifaiClient; | ||
use Clarifai\Api\Model; | ||
use Clarifai\Api\PostModelsRequest; | ||
use Clarifai\Api\Status\StatusCode; | ||
use Clarifai\Api\UserAppIDSet; | ||
|
||
$client = ClarifaiClient::grpc(); | ||
|
||
$metadata = ["Authorization" => ["Key " . $PAT]]; | ||
|
||
$userDataObject = new UserAppIDSet([ | ||
"user_id" => $USER_ID, | ||
"app_id" => $APP_ID, | ||
]); | ||
|
||
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a | ||
// request and then wait for the response | ||
[$response, $status] = $client->PostModels( | ||
// The request object carries the request along with the request status and other metadata related to the request itself | ||
new PostModelsRequest([ | ||
"user_app_id" => $userDataObject, | ||
"models" => [ | ||
new Model([ | ||
"id" => $MODEL_ID, | ||
"model_type_id" => $MODEL_TYPE_ID, | ||
"notes" => "zero shot text classifier" | ||
]), | ||
], | ||
]), | ||
$metadata | ||
)->wait(); | ||
|
||
// A response is returned and the first thing we do is check the status of it | ||
// A successful response will have a status code of 0; otherwise, there is some error | ||
if ($status->code !== 0) { | ||
throw new Exception("Error: {$status->details}"); | ||
} | ||
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure | ||
// (not just that the communication was successful) | ||
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) { | ||
throw new Exception("Failure response: " . $response->getStatus()->getDescription() . " " . $response->getStatus()->getDetails()); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
########################################################################################## | ||
# In this section, we set the user authentication, app ID, model ID, and model type ID. | ||
# Change these strings to run your own example. | ||
######################################################################################### | ||
|
||
USER_ID = 'YOUR_USER_ID_HERE' | ||
# Your PAT (Personal Access Token) can be found in the portal under Authentification | ||
PAT = 'YOUR_PAT_HERE' | ||
APP_ID = 'YOUR_APP_ID_HERE' | ||
# Change these to create your own model | ||
MODEL_ID = 'zero-shot-text-model' | ||
MODEL_TYPE_ID = 'zero-shot-text-classifier' | ||
|
||
########################################################################## | ||
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE | ||
########################################################################## | ||
|
||
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel | ||
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc | ||
from clarifai_grpc.grpc.api.status import status_code_pb2 | ||
|
||
channel = ClarifaiChannel.get_grpc_channel() | ||
stub = service_pb2_grpc.V2Stub(channel) | ||
|
||
metadata = (('authorization', 'Key ' + PAT),) | ||
|
||
userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID) | ||
|
||
post_models_response = stub.PostModels( | ||
service_pb2.PostModelsRequest( | ||
user_app_id=userDataObject, | ||
models=[ | ||
resources_pb2.Model( | ||
id=MODEL_ID, | ||
model_type_id=MODEL_TYPE_ID, | ||
notes='zero shot text classifier' | ||
) | ||
] | ||
), | ||
metadata=metadata | ||
) | ||
|
||
if post_models_response.status.code != status_code_pb2.SUCCESS: | ||
print(post_models_response.status) | ||
raise Exception("Post models failed, status: " + post_models_response.status.description) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/models" \ | ||
-H "Authorization: Key YOUR_PAT_HERE" \ | ||
-H "Content-Type: application/json" \ | ||
-d '{ | ||
"model": { | ||
"id": "zero-shot-text-model", | ||
"model_type_id": "zero-shot-text-classifier", | ||
"notes": "zero shot text classifier" | ||
} | ||
}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<!--index.html file--> | ||
|
||
<script> | ||
////////////////////////////////////////////////////////////////////////////////////////// | ||
// In this section, we set the user authentication, app ID, model ID, and concept IDs. | ||
// Change these strings to run your own example. | ||
///////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
const USER_ID = "YOUR_USER_ID_HERE"; | ||
// Your PAT (Personal Access Token) can be found in the portal under Authentification | ||
const PAT = "YOUR_PAT_HERE"; | ||
const APP_ID = "YOUR_APP_ID_HERE"; | ||
// Change these to import your own model | ||
const MODEL_ID = "zero-shot-text-model"; | ||
const CONCEPT_ID_1 = "happy"; | ||
const CONCEPT_ID_2 = "sad"; | ||
|
||
/////////////////////////////////////////////////////////////////////////////////// | ||
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE | ||
/////////////////////////////////////////////////////////////////////////////////// | ||
|
||
const raw = JSON.stringify({ | ||
"user_app_id": { | ||
"user_id": USER_ID, | ||
"app_id": APP_ID | ||
}, | ||
"model_versions": [{ | ||
"import_info": { | ||
"params": { | ||
"toolkit":"HuggingFace", | ||
"pipeline_name":"zero-shot-classification", | ||
"model_name":"facebook/bart-large-mnli", | ||
"tokenizer_config":{}, | ||
"use_gpu": true | ||
} | ||
}, | ||
"output_info": { | ||
"data": { | ||
"concepts": [ | ||
{ | ||
"id": CONCEPT_ID_1 | ||
}, | ||
{ | ||
"id": CONCEPT_ID_2 | ||
} | ||
] | ||
} | ||
} | ||
}] | ||
|
||
}); | ||
|
||
const requestOptions = { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Authorization": "Key " + PAT | ||
}, | ||
body: raw | ||
}; | ||
|
||
fetch(`https://api.clarifai.com/v2/models/${MODEL_ID}/versions`, requestOptions) | ||
.then(response => response.text()) | ||
.then(result => console.log(result)) | ||
.catch(error => console.log("error", error)); | ||
|
||
</script> |
Oops, something went wrong.