Skip to content

Commit

Permalink
Add README text
Browse files Browse the repository at this point in the history
  • Loading branch information
rok-povsic committed Dec 4, 2019
1 parent 7355f9b commit 691b36a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion README.md
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()));
}
```
Binary file added docs/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 691b36a

Please sign in to comment.