clarifai / clarifai-java Goto Github PK
View Code? Open in Web Editor NEWDEPRECATED Clarifai API Java Client, use clarifai-java-grpc instead.
Home Page: https://docs.clarifai.com
License: Other
DEPRECATED Clarifai API Java Client, use clarifai-java-grpc instead.
Home Page: https://docs.clarifai.com
License: Other
If multiple videos are queued using input -> ClarifaiInput.forVideo(input.getUrl()));
client.getDefaultModels().generalVideoModel() .predict() .withInputs(inputs) .executeSync().get();
The first video receives tags relevant to the video but all videos after receive an empty data ArrayList on the ClarifaiOutput object.
Temporary fix will be queuing our videos one by one
Hi, recently, after every request, i get an error:
Fatal Exception: java.lang.RuntimeException: Failed to invoke clarifai2.dto.model.output_info.ColorOutputInfo() with no args
at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:111)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:210)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:952)
at com.google.gson.Gson.fromJson(Gson.java:925)
at clarifai2.internal.InternalUtil.fromJson(InternalUtil.java:145)
at clarifai2.dto.model.output_info.OutputInfo$Adapter$1.deserialize(OutputInfo.java:37)
at clarifai2.dto.model.output_info.OutputInfo$Adapter$1.deserialize(OutputInfo.java:23)
at clarifai2.internal.JSONAdapterFactory$Adapter.read(JSONAdapterFactory.java:173)
at com.google.gson.TypeAdapter$1.read(TypeAdapter.java:199)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:952)
at com.google.gson.Gson.fromJson(Gson.java:925)
at clarifai2.internal.InternalUtil.fromJson(InternalUtil.java:145)
at clarifai2.dto.model.Model$Adapter$2.deserialize(Model.java:212)
at clarifai2.dto.model.Model$Adapter$2.deserialize(Model.java:197)
at clarifai2.internal.JSONAdapterFactory$Adapter.read(JSONAdapterFactory.java:173)
at com.google.gson.TypeAdapter$1.read(TypeAdapter.java:199)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:952)
at clarifai2.api.request.model.GetModelRequest$1$1.fromJSON(GetModelRequest.java:34)
at clarifai2.api.request.model.GetModelRequest$1$1.fromJSON(GetModelRequest.java:32)
at clarifai2.api.request.ClarifaiRequest$Impl.executeSync(ClarifaiRequest.java:285)
at clarifai2.api.request.ClarifaiRequest$Builder.executeSync(ClarifaiRequest.java:192)
at clarifai2.dto.model.DefaultModels.update(DefaultModels.java:52)
at clarifai2.dto.model.DefaultModels.access$000(DefaultModels.java:10)
at clarifai2.dto.model.DefaultModels$1.run(DefaultModels.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Caused by java.lang.InstantiationException: can't instantiate class clarifai2.dto.model.output_info.ColorOutputInfo
at java.lang.reflect.Constructor.constructNative(Constructor.java)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:108)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:210)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:952)
at com.google.gson.Gson.fromJson(Gson.java:925)
at clarifai2.internal.InternalUtil.fromJson(InternalUtil.java:145)
at clarifai2.dto.model.output_info.OutputInfo$Adapter$1.deserialize(OutputInfo.java:37)
at clarifai2.dto.model.output_info.OutputInfo$Adapter$1.deserialize(OutputInfo.java:23)
at clarifai2.internal.JSONAdapterFactory$Adapter.read(JSONAdapterFactory.java:173)
at com.google.gson.TypeAdapter$1.read(TypeAdapter.java:199)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:952)
at com.google.gson.Gson.fromJson(Gson.java:925)
at clarifai2.internal.InternalUtil.fromJson(InternalUtil.java:145)
at clarifai2.dto.model.Model$Adapter$2.deserialize(Model.java:212)
at clarifai2.dto.model.Model$Adapter$2.deserialize(Model.java:197)
at clarifai2.internal.JSONAdapterFactory$Adapter.read(JSONAdapterFactory.java:173)
at com.google.gson.TypeAdapter$1.read(TypeAdapter.java:199)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:952)
at clarifai2.api.request.model.GetModelRequest$1$1.fromJSON(GetModelRequest.java:34)
at clarifai2.api.request.model.GetModelRequest$1$1.fromJSON(GetModelRequest.java:32)
at clarifai2.api.request.ClarifaiRequest$Impl.executeSync(ClarifaiRequest.java:285)
at clarifai2.api.request.ClarifaiRequest$Builder.executeSync(ClarifaiRequest.java:192)
at clarifai2.dto.model.DefaultModels.update(DefaultModels.java:52)
at clarifai2.dto.model.DefaultModels.access$000(DefaultModels.java:10)
at clarifai2.dto.model.DefaultModels$1.run(DefaultModels.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
After read stackowerflow, i update gson to 2.8.0, but i had same problem.
Version of Clarifai: 2.3.0
Version of Gson: 2.8.0
hey i am building from this source app github.com/Clarifai/clarifai-java and for now its work its scan
photo :
now after is scan how i can do like if he see the word sky ( on the results List ) so i want when he see this word he wil say
like
sky 0.99892235 = ok
how i can do ?
i coud do loop ? ( the problem i not the the id to the words )
Any help would be appreciated
Source Code:
package com.proptiger.data.service.cms.listing;
import java.util.List;
import clarifai2.api.ClarifaiBuilder;
import clarifai2.api.ClarifaiClient;
import clarifai2.api.ClarifaiToken;
import clarifai2.api.request.ClarifaiRequest;
import clarifai2.dto.input.ClarifaiInput;
import clarifai2.dto.input.image.ClarifaiImage;
import clarifai2.dto.model.output.ClarifaiOutput;
import clarifai2.dto.prediction.Prediction;
public class ListingAutoApprovalService {
private void clarifyresponse(String URL) {
final ClarifaiClient client = new ClarifaiBuilder(
"{{app_id}}",
"{{app_secret}}").buildSync();
ClarifaiToken token = client.getToken();
@SuppressWarnings("unused")
final ClarifaiRequest<List<ClarifaiOutput<Prediction>>> predictionResults =
client.predict("{{model_id}}")
.withInputs(ClarifaiInput.forImage(ClarifaiImage.of(URL))).build();
@SuppressWarnings("unused")
ClarifaiToken token1 = client.getToken();
// predictionResults.getStatus();
/*
* final ClarifaiResponse<List<ClarifaiOutput<Concept>>>
* predictionResults = client.getDefaultModels().generalModel() // You
* can also do client.getModelByID("id") to get custom models .predict()
* .withInputs( ClarifaiInput.forImage(ClarifaiImage.of(
* "https://samples.clarifai.com/metro-north.jpg")) ) .executeSync() ;
* /*
*
* // String token = "fvFlUXSr7Z2d1BwJ3QzFZDoMoKhg4o"; /* ClarifaiClient
* client = new ClarifaiBuilder(
* "{{app_id}}",
*"{{app_secret}}").buildSync();
*/
// client.predict("f5385c66fe154fb9b3271ad3b5d2bb4a").withInputs(ClarifaiInput.forImage(ClarifaiImage.of(URL)))
// .executeSync();
}
public static void main(String args[]) {
ListingAutoApprovalService object = new ListingAutoApprovalService();
System.out.print("test");
object.clarifyresponse("https://content.makaan.com/16/7268897/274/6562459.jpeg");
System.out.print("test");
}
}
Exception in thread "main" java.lang.RuntimeException: Failed to invoke clarifai2.dto.ClarifaiStatus() with no args at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:107) at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:162) at com.google.gson.Gson.fromJson(Gson.java:803) at com.google.gson.Gson.fromJson(Gson.java:868) at com.google.gson.Gson.fromJson(Gson.java:841) at clarifai2.api.request.ClarifaiRequestImpl.getClarifaiResponse(ClarifaiRequestImpl.java:78) at clarifai2.api.request.ClarifaiRequestImpl.executeSync(ClarifaiRequestImpl.java:43) at clarifai2.api.request.ClarifaiRequest$Builder.executeSync(ClarifaiRequest.java:188) at com.proptiger.data.service.cms.listing.ListingAutoApprovalService.clarifyresponse(ListingAutoApprovalService.java:21) at com.proptiger.data.service.cms.listing.ListingAutoApprovalService.main(ListingAutoApprovalService.java:36) Caused by: java.lang.InstantiationException at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:104) ... 9 more
Hi,
I have tried faceDetectionModel with below request
client.getDefaultModels().faceDetectionModel().predict().withInputs(ClarifaiInput.forImage(ClarifaiImage.of(image))).executeSync()
and image passed as a parameter was https://developer.clarifai.com/static/images/model-samples/face-001.jpg and then
I am getting nullpointer exception with
at clarifai2.dto.prediction.Region$Adapter$1.deserialize(Region.java:53)
at clarifai2.dto.prediction.Region$Adapter$1.deserialize(Region.java:38)
at clarifai2.internal.JSONAdapterFactory$Adapter.read(JSONAdapterFactory.java:173)
at com.google.gson.TypeAdapter$1.read(TypeAdapter.java:199)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:952)
at com.google.gson.Gson.fromJson(Gson.java:925)
at clarifai2.internal.InternalUtil.fromJson(InternalUtil.java:153)
at clarifai2.dto.model.output.ClarifaiOutput$Adapter$1.deserialize(ClarifaiOutput.java:94)
at clarifai2.dto.model.output.ClarifaiOutput$Adapter$1.deserialize(ClarifaiOutput.java:54)
at clarifai2.internal.JSONAdapterFactory$Adapter.read(JSONAdapterFactory.java:173)
at com.google.gson.TypeAdapter$1.read(TypeAdapter.java:199)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:952)
at clarifai2.internal.InternalUtil.fromJson(InternalUtil.java:162)
at clarifai2.api.request.model.PredictRequest$1$3.fromJSON(PredictRequest.java:134)
at clarifai2.api.request.model.PredictRequest$1$3.fromJSON(PredictRequest.java:131)
at clarifai2.api.request.ClarifaiRequest$Impl.executeSync(ClarifaiRequest.java:285)
at clarifai2.api.request.ClarifaiRequest$Builder.executeSync(ClarifaiRequest.java:192)
We get the this exception while trying to tag some of the MP4 video files:
Jul 01 04:05:07 ip-10-130-102-211 PRODUCTION: com.clarifai.api.exception.ClarifaiException: IOException
Jul 01 04:05:07 ip-10-130-102-211 PRODUCTION: at com.clarifai.api.ClarifaiRequester.executeOnce(ClarifaiRequester.java:100)
Jul 01 04:05:07 ip-10-130-102-211 PRODUCTION: at com.clarifai.api.ClarifaiRequester.execute(ClarifaiRequester.java:39)
Jul 01 04:05:07 ip-10-130-102-211 PRODUCTION: at com.clarifai.api.ClarifaiClient.recognize(ClarifaiClient.java:88)
any suggestions?
Hi, Clarifai Team,
I am testing the Clarifai API for integration with our business. One issue I encountered and not be able to find a good reference is the customized language. I saw general 1.3 supported other languages but not be able to reproduce it in Java API:
final ClarifaiClient client = new ClarifaiBuilder("key", "sec").buildSync();
final List<ClarifaiOutput> predictionResults =
client.getDefaultModels().generalModel().predict().withInputs(
ClarifaiInput.forImage(ClarifaiImage.of("https://samples.clarifai.com/metro-north.jpg"))
) .executeSync().get();
In the API doc I didn't find how to specify language and my application settings are already set default language other than English, still, only English tag returned.
Could you help to take a look?
Best,
Felix
Hi, I get an error with a minimal example:
final ClarifaiClient client = new ClarifaiBuilder(CLIENT_ID, CLIENT_SECRET).buildSync();
final ClarifaiResponse<List<ClarifaiOutput<Concept>>> response = client.getDefaultModels().generalModel().predict().withInputs(ClarifaiInput.forImage(ClarifaiImage.of(IMAGE_URL))).executeSync();
Following the solution to this problem on stack overflow I have updated my gson to 2.8.0 and my clarifai version is 2.2.1, but I had the same problem with gson 2.7 and clarifai 2.1.0
Exception in thread "main" java.lang.IllegalArgumentException: @JsonAdapter value must be TypeAdapter or TypeAdapterFactory reference.
at com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory.getTypeAdapter(JsonAdapterAnnotationTypeAdapterFactory.java:64)
at com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory.create(JsonAdapterAnnotationTypeAdapterFactory.java:46)
at com.google.gson.Gson.getAdapter(Gson.java:358)
at com.google.gson.Gson.getAdapter(Gson.java:447)
at clarifai2.internal.AutoValueTypeAdapterFactory.create(AutoValueTypeAdapterFactory.java:35)
at com.google.gson.Gson.getAdapter(Gson.java:358)
at com.google.gson.Gson.toJson(Gson.java:587)
at com.google.gson.Gson.toJsonTree(Gson.java:488)
at com.google.gson.Gson.toJsonTree(Gson.java:467)
at clarifai2.api.request.model.PredictRequest$1$1.call(PredictRequest.java:61)
at clarifai2.api.request.model.PredictRequest$1$1.call(PredictRequest.java:59)
at clarifai2.internal.JSONArrayBuilder.addAll(JSONArrayBuilder.java:60)
at clarifai2.api.request.model.PredictRequest$1.httpRequest(PredictRequest.java:59)
at clarifai2.api.request.ClarifaiRequest$Impl.executeSync(ClarifaiRequest.java:230)
at clarifai2.api.request.ClarifaiRequest$Builder.executeSync(ClarifaiRequest.java:170)
at com.tnsglobal.instagram.clarifai.ClarifaiTester.main(ClarifaiTester.java:32)
Our tests started failing with requests to NSFW model with the following:
clarifai2.exception.ClarifaiException: Deserialization of UNKNOWN is not implemented
at clarifai2.dto.model.output.ClarifaiOutput.deserializePredictions(ClarifaiOutput.java:120)
at clarifai2.dto.model.output.ClarifaiOutput.deserialize(ClarifaiOutput.java:56)
at clarifai2.api.request.model.PredictRequest$1.unmarshalerGrpc(PredictRequest.java:166)
at clarifai2.api.request.model.PredictRequest$1.unmarshalerGrpc(PredictRequest.java:114)
at clarifai2.api.request.ClarifaiRequest$Impl.executeSync(ClarifaiRequest.java:310)
at clarifai2.api.request.ClarifaiRequest$Builder.executeSync(ClarifaiRequest.java:211)
We are using the following Clarifai client:
<dependency>
<groupId>com.clarifai.clarifai-api2</groupId>
<artifactId>core</artifactId>
<version>2.8.1</version>
</dependency>
This happens in response to the following call:
clarifaiClient
.getDefaultModels()
.nsfwModel()
.predict()
.withInputs(images.stream().map(ClarifaiInput::forImage).collect(Collectors.toList()))
.executeSync();
The response JSON comes as valid, however the model/output_info section seems to be empty:
"model": {
"id": "e9576d86d2004ed1a38ba0cf39ecb4b1",
"name": "nsfw-v1.0",
"createdAt": "2016-09-17T22:18:59.955626Z",
"appId": "main",
"outputInfo": {
"outputConfig": {
},
"message": "Show output_info with: GET /models/{model_id}/output_info"
},
"modelVersion": {
"id": "aa47919c9a8d4d94bfa283121281bcc4",
"createdAt": "2018-01-23T19:25:09.618692Z",
"status": {
"code": "MODEL_TRAINED",
"description": "Model is trained and ready"
}
},
"displayName": "nsfw-v1-visual-classifier"
}
Which causes the above exception during parcing.
This started happening 12/20/2021 before that everything was working fine.
Hi,
I'm trying to use this library with Android by doing this inside my Gradle file:
implementation 'com.clarifai.clarifai-api2:core:2.4.0'
Problem is that it throwing me a RuntimeException saying - Unable to merge dex.
Any fix for this?
The readme points at https://developer.clarifai.com/guide-v2/ but this returns HTTP 404.
I need to be able to check for a specific tag for an image with the java client.
https://developer.clarifai.com/guide/tag#select-classes
I think this could easily be accomplished by adding a new field (a list or array of tags) to RecognitionRequest and making sure that gets passed along in the request body under the "select_classes" parameter.
If multiple tags, they should be comma separated.
Hi folks,
I am attempting to run the example, but I keep getting an IOException being thrown when the folling line in ClarifaiRequester.java is evaluated;
boolean isSuccess = (conn.getResponseCode() >= 200 && conn.getResponseCode() < 300);
I modified the Main.java class to instantiate the ClarifaiClient with my appId and secret.
Please let me know if you need further information.
Thanks!
Hi!
Is there any way to close ClarifaiClient in order to close underlying http connections?
Hi!
I'm trying to take some tags from an image which is stored in my pc.
Everytime i'm trying to get the tags I get this exception:
Exception in thread "main" java.util.NoSuchElementException: This API call was not successful. Details about this error: ClarifaiStatus{networkErrorOccurred=false, statusCode=10020, description=Failure, errorDetails=null}
What's the problem with it? Thank you in advance!
public static List<String> recognize(String imageUrl) {
// Defining List Object
List<String> resultList = new ArrayList<String>();
if(imageUrl != null) {
final ClarifaiClient client = new ClarifaiBuilder("<apiKey>").buildSync();
final List<ClarifaiOutput<Concept>> predictionResults =
client.getDefaultModels().generalModel() // You can also do client.getModelByID("id") to get custom models
.predict()
.withInputs(
ClarifaiInput.forImage(ClarifaiImage.of(imageUrl))
)
.executeSync()
.get();
if (predictionResults != null && predictionResults.size() > 0) {
// Prediction List Iteration
for (int i = 0; i < predictionResults.size(); i++) {
ClarifaiOutput<Concept> clarifaiOutput = predictionResults.get(i);
List<Concept> concepts = clarifaiOutput.data();
if(concepts != null && concepts.size() > 0) {
for (int j = 0; j < concepts.size(); j++) {
resultList.add(concepts.get(j).name());
}
}
}
}
}
return resultList;
}
public static void main(String[] args) {
// You can change the Image URL accordingly.
String imageUrl = "file:///home/paolo/Scrivania/Clarifai/pippo.png";
// List of Recognized Result from Image
List<String> resultList = ImageRecognizer.recognize(imageUrl);
// Iteration of Result
for(String result : resultList) {
System.out.println(result);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.