-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
7355f9b
commit 691b36a
Showing
2 changed files
with
58 additions
and
1 deletion.
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 |
---|---|---|
@@ -1 +1,58 @@ | ||
# clarifai-java-grpc | ||
![Clarifai logo](docs/logo.png) | ||
|
||
# Clarifai Java gRPC Client | ||
|
||
This is the official Clarifai Java gRPC client. | ||
|
||
In addition to the actual gRPC channel, it is also possible to use a JSON channel, which uses | ||
JSON & HTTP/REST, while using the same request / response handling code. | ||
|
||
## Getting started | ||
|
||
```java | ||
import com.clarifai.channel.ClarifaiChannel; | ||
import io.grpc.Channel; | ||
|
||
... | ||
|
||
// Construct one of the channels you want to use | ||
Channel channel = ClarifaiChannel.INSTANCE.getJsonChannel(); | ||
Channel channel = ClarifaiChannel.INSTANCE.getInsecureGrpcChannel(); | ||
|
||
// Note: You can also use a secure (encrypted) ClarifaiChannel.INSTANCE.getGrpcChannel() however | ||
// it is currently not supported in the latest gRPC version. | ||
``` | ||
|
||
Predict concepts in an image: | ||
|
||
```java | ||
import com.clarifai.credentials.ClarifaiCallCredentials; | ||
import com.clarifai.grpc.api.*; | ||
import com.clarifai.grpc.api.status.StatusCode; | ||
|
||
... | ||
|
||
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(channel) | ||
.withCallCredentials(new ClarifaiCallCredentials("YOUR_CLARIFAI_API_KEY")); | ||
|
||
MultiOutputResponse response = stub.postModelOutputs( | ||
PostModelOutputsRequest.newBuilder() | ||
.setModelId("aaa03c23b3724a16a56b629203edc62c") | ||
.addInputs( | ||
Input.newBuilder().setData( | ||
Data.newBuilder().setImage( | ||
Image.newBuilder().setUrl("YOUR_IMAGE_URL") | ||
) | ||
) | ||
) | ||
.build() | ||
); | ||
|
||
if (response.getStatus().getCode() != StatusCode.SUCCESS) { | ||
throw new RuntimeException("Request failed, status: " + response.getStatus()); | ||
} | ||
|
||
for (Concept c : response.getOutputs(0).getData().getConceptsList()) { | ||
System.out.println(String.format("%12s: %,.2f", c.getName(), c.getValue())); | ||
} | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.