├── .gitignore ├── .idea ├── codeStyleSettings.xml ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml └── inspectionProfiles │ └── Project_Default.xml ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── appveyor.yml ├── build.gradle ├── core ├── build.gradle └── src │ └── main │ └── java │ └── clarifai2 │ ├── Func0.java │ ├── Func1.java │ ├── api │ ├── BaseClarifaiClient.java │ ├── ClarifaiBuilder.java │ ├── ClarifaiClient.java │ ├── ClarifaiClientImpl.java │ ├── ClarifaiResponse.java │ ├── ClarifaiToken.java │ ├── package-info.java │ └── request │ │ ├── ClarifaiJsonRequest.java │ │ ├── ClarifaiPaginatedRequest.java │ │ ├── ClarifaiRequest.java │ │ ├── PaginatedRequestVendor.java │ │ ├── concept │ │ ├── AddConceptsRequest.java │ │ ├── GetConceptByIDRequest.java │ │ ├── GetConceptsRequest.java │ │ ├── ModifyConceptsRequest.java │ │ └── SearchConceptsRequest.java │ │ ├── input │ │ ├── AddInputsRequest.java │ │ ├── DeleteAllInputsRequest.java │ │ ├── DeleteInputRequest.java │ │ ├── DeleteInputsBatchRequest.java │ │ ├── GetInputRequest.java │ │ ├── GetInputsRequest.java │ │ ├── GetInputsStatusRequest.java │ │ ├── PatchInputMetadataRequest.java │ │ ├── PatchInputRequest.java │ │ ├── SearchClause.java │ │ └── SearchInputsRequest.java │ │ └── model │ │ ├── Action.java │ │ ├── CreateModelGenericRequest.java │ │ ├── CreateModelRequest.java │ │ ├── DeleteAllModelsRequest.java │ │ ├── DeleteModelRequest.java │ │ ├── DeleteModelVersionRequest.java │ │ ├── DeleteModelsBatchRequest.java │ │ ├── FindModelRequest.java │ │ ├── GetModelInputsRequest.java │ │ ├── GetModelRequest.java │ │ ├── GetModelVersionRequest.java │ │ ├── GetModelVersionsRequest.java │ │ ├── GetModelsRequest.java │ │ ├── ModifyModelRequest.java │ │ ├── PatchModelRequest.java │ │ ├── PredictRequest.java │ │ ├── RunModelEvaluationRequest.java │ │ ├── TrainModelRequest.java │ │ └── WorkflowPredictRequest.java │ ├── dto │ ├── ClarifaiStatus.java │ ├── HasClarifaiID.java │ ├── HasClarifaiIDRequired.java │ ├── PointF.java │ ├── Radius.java │ ├── Rectangle.java │ ├── input │ │ ├── ClarifaiFileImage.java │ │ ├── ClarifaiFileVideo.java │ │ ├── ClarifaiImage.java │ │ ├── ClarifaiInput.java │ │ ├── ClarifaiInputValue.java │ │ ├── ClarifaiInputsStatus.java │ │ ├── ClarifaiURLImage.java │ │ ├── ClarifaiURLVideo.java │ │ ├── ClarifaiVideo.java │ │ ├── Crop.java │ │ └── SearchHit.java │ ├── model │ │ ├── ClusterModel.java │ │ ├── ColorModel.java │ │ ├── ConceptModel.java │ │ ├── DefaultModels.java │ │ ├── DetectionModel.java │ │ ├── EmbeddingModel.java │ │ ├── FaceEmbeddingModel.java │ │ ├── Model.java │ │ ├── ModelMetricsStatus.java │ │ ├── ModelTrainingStatus.java │ │ ├── ModelType.java │ │ ├── ModelVersion.java │ │ ├── StatusCode.java │ │ ├── UnknownModel.java │ │ ├── VideoModel.java │ │ ├── output │ │ │ └── ClarifaiOutput.java │ │ └── output_info │ │ │ ├── BlurOutputInfo.java │ │ │ ├── ClusterOutputInfo.java │ │ │ ├── ColorOutputInfo.java │ │ │ ├── ConceptOutputInfo.java │ │ │ ├── DetectionOutputInfo.java │ │ │ ├── EmbeddingOutputInfo.java │ │ │ ├── FaceEmbeddingOutputInfo.java │ │ │ ├── OutputInfo.java │ │ │ ├── UnknownOutputInfo.java │ │ │ └── VideoOutputInfo.java │ ├── prediction │ │ ├── Blur.java │ │ ├── Cluster.java │ │ ├── Color.java │ │ ├── Concept.java │ │ ├── Detection.java │ │ ├── Embedding.java │ │ ├── FaceEmbedding.java │ │ ├── Frame.java │ │ ├── Prediction.java │ │ ├── Region.java │ │ └── Unknown.java │ ├── search │ │ └── SearchInputsResult.java │ └── workflow │ │ ├── Workflow.java │ │ ├── WorkflowPredictResult.java │ │ └── WorkflowResult.java │ ├── exception │ ├── ClarifaiClientClosedException.java │ ├── ClarifaiException.java │ ├── DeprecationException.java │ └── NetworkException.java │ ├── grpc │ ├── ClarifaiHttpClient.java │ ├── ClarifaiHttpClientImpl.java │ ├── DateTimeConverter.java │ ├── FkClarifaiHttpClient.java │ ├── JsonChannel.java │ ├── JsonMarshaller.java │ └── MetadataConverter.java │ ├── internal │ ├── AutoValueTypeAdapterFactory.java │ ├── InternalUtil.java │ ├── JSONAdapterFactory.java │ ├── JSONArrayBuilder.java │ ├── JSONObjectBuilder.java │ ├── JSONUnmarshaler.java │ └── grpc │ │ └── api │ │ ├── ClusterOuterClass.java │ │ ├── Code.java │ │ ├── ColorOuterClass.java │ │ ├── Common.java │ │ ├── ConceptGraph.java │ │ ├── ConceptLanguageOuterClass.java │ │ ├── ConceptOuterClass.java │ │ ├── ConceptReferenceOuterClass.java │ │ ├── DataOuterClass.java │ │ ├── EmbeddingOuterClass.java │ │ ├── Endpoint.java │ │ ├── FaceOuterClass.java │ │ ├── Feedback.java │ │ ├── FocusOuterClass.java │ │ ├── GeoOuterClass.java │ │ ├── Healthz.java │ │ ├── ImageOuterClass.java │ │ ├── InputOuterClass.java │ │ ├── ModelOuterClass.java │ │ ├── ModelVersionOuterClass.java │ │ ├── OutputOuterClass.java │ │ ├── PaginationOuterClass.java │ │ ├── Search.java │ │ ├── Subscription.java │ │ ├── TextOuterClass.java │ │ ├── UsageIntervalTypeOuterClass.java │ │ ├── V2Grpc.java │ │ ├── VideoOuterClass.java │ │ ├── Visualization.java │ │ ├── VocabOuterClass.java │ │ ├── WorkflowOuterClass.java │ │ ├── status │ │ ├── StatusCodeOuterClass.java │ │ └── StatusOuterClass.java │ │ └── utils │ │ ├── Extensions.java │ │ └── TestProtoOuterClass.java │ └── solutions │ ├── Solutions.java │ └── moderation │ ├── Moderation.java │ ├── api │ └── request │ │ ├── input │ │ └── GetModerationStatusRequest.java │ │ └── model │ │ └── ModerationPredictRequest.java │ └── dto │ ├── ModerationDetail.java │ ├── ModerationOutput.java │ └── ModerationStatus.java ├── gradle.properties.enc ├── gradle ├── pmd.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── logo.png ├── pmd-ruleset.xml ├── scripts ├── app_and_key_for_tests.py ├── buildArtifacts.gradle └── publishToMavenCentral.gradle ├── settings.gradle └── tests ├── assets ├── beer.mp4 ├── image.png └── metro-north.jpg ├── build.gradle └── src └── test ├── java └── clarifai2 │ ├── integration_tests │ ├── BaseIntTest.java │ ├── ClarifaiClientIntTests.java │ ├── ConceptIntTests.java │ ├── EnvVar.java │ ├── GuideExamples.java │ ├── InputIntTests.java │ ├── KeysIntTests.java │ ├── ModelEqualityIntTests.java │ ├── ModelEvaluationIntTests.java │ ├── ModelOutputInfoIntTests.java │ ├── ModelVersionIntTests.java │ ├── PredictIntTests.java │ ├── QuickstartGuideExamples.java │ ├── SearchInputsIntTests.java │ ├── VariousIntTests.java │ ├── VariousModelsIntTests.java │ └── WorkflowPredictIntTests.java │ └── unit_tests │ ├── BaseUnitTest.java │ ├── ConceptsUnitTests.java │ ├── FindModelsUnitTests.java │ ├── InputUnitTests.java │ ├── InvalidResponseUnitTests.java │ ├── MetadataConverterUnitTests.java │ ├── ModelEvaluationUnitTests.java │ ├── ModelUnitTests.java │ ├── ModelVersionUnitTests.java │ ├── PredictUnitTests.java │ ├── SearchConceptsUnitTests.java │ ├── SearchInputsUnitTests.java │ ├── VariousModelsUnitTests.java │ └── WorkflowUnitTests.java └── resources ├── addConcepts_request.json ├── addConcepts_response.json ├── addInputs_request.json ├── addInputs_response.json ├── addMetadataForInput_request.json ├── addMetadataForInput_response.json ├── batchPredictWithArguments_request.json ├── batchPredictWithArguments_response.json ├── batchPredictWithOneInvalidURL_request.json ├── batchPredictWithOneInvalidURL_response.json ├── batchPredict_request.json ├── batchPredict_response.json ├── createModelGeneric_request.json ├── createModelGeneric_response.json ├── createModel_request.json ├── createModel_response.json ├── deleteAllInputs_request.json ├── deleteAllInputs_response.json ├── deleteAllModels_response.json ├── deleteInput_response.json ├── deleteInputsBatch_request.json ├── deleteInputsBatch_response.json ├── deleteModelVersion_response.json ├── deleteModel_response.json ├── deleteModelsBatch_request.json ├── deleteModelsBatch_response.json ├── findModelByNameAndType_request.json ├── findModelByNameAndType_response.json ├── findModelByName_request.json ├── findModelByName_response.json ├── getColorModel_response.json ├── getConceptModel_response.json ├── getConcept_response.json ├── getConcepts_response.json ├── getDemographicsModel_response.json ├── getEmbeddingModel_response.json ├── getFaceConceptsModel_response.json ├── getFaceEmbeddingModel_response.json ├── getInput_response.json ├── getInputsStatus_response.json ├── getInputs_response.json ├── getLogoModel_response.json ├── getModelInputs_response.json ├── getModelVersion_response.json ├── getModelVersions_response.json ├── getModel_response.json ├── getModels_response.json ├── getVideoModel_response.json ├── invalidJson_response.json ├── mergeConceptsForInput_request.json ├── mergeConceptsForInput_response.json ├── modifyConcepts_request.json ├── modifyConcepts_response.json ├── modifyModel_request.json ├── modifyModel_response.json ├── predictColor_request.json ├── predictColor_response.json ├── predictConcept_request.json ├── predictConcept_response.json ├── predictDemographics_request.json ├── predictDemographics_response.json ├── predictEmbedding_request.json ├── predictEmbedding_response.json ├── predictFaceConcepts_request.json ├── predictFaceConcepts_response.json ├── predictFaceEmbedding_request.json ├── predictFaceEmbedding_response.json ├── predictLogo_request.json ├── predictLogo_response.json ├── predictVideo_request.json ├── predictVideo_response.json ├── predictWithArguments_request.json ├── predictWithArguments_response.json ├── predictWithInvalidURL_request.json ├── predictWithInvalidURL_response.json ├── predictWithUnknownFields_request.json ├── predictWithUnknownFields_response.json ├── predict_request.json ├── predict_response.json ├── removeConceptsForInputs_request.json ├── removeConceptsForInputs_response.json ├── runModelEvaluation_response.json ├── searchConceptsWithLanguage_request.json ├── searchConceptsWithLanguage_response.json ├── searchConcepts_request.json ├── searchConcepts_response.json ├── searchInputsByConceptID_request.json ├── searchInputsByConceptID_response.json ├── searchInputsByConceptName_request.json ├── searchInputsByConceptName_response.json ├── searchInputsByGeo_request.json ├── searchInputsByGeo_response.json ├── trainModel_request.json ├── trainModel_response.json ├── workflowBatchPredict_request.json ├── workflowBatchPredict_response.json ├── workflowPredictWithBase64_request.json ├── workflowPredictWithBase64_response.json ├── workflowPredict_request.json └── workflowPredict_response.json /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 24 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | branches: 2 | only: 3 | - master 4 | - /^\d+\.\d+\.\d+(-\w+\d*)*$/ 5 | 6 | sudo: true 7 | 8 | language: java 9 | 10 | jdk: 11 | - openjdk8 12 | - openjdk9 13 | - openjdk11 14 | 15 | before_cache: 16 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 17 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ 18 | cache: 19 | directories: 20 | - $HOME/.gradle/caches/ 21 | - $HOME/.gradle/wrapper/ 22 | - $HOME/.gradle/native/ 23 | - $HOME/.gradle/daemon/native/ 24 | 25 | before_script: 26 | - export PYTHONPATH=. 27 | - export CLARIFAI_APP_ID="$(python scripts/app_and_key_for_tests.py --create-app java-travis)" 28 | - export CLARIFAI_API_KEY="$(python scripts/app_and_key_for_tests.py --create-key ${CLARIFAI_APP_ID})" 29 | - python scripts/app_and_key_for_tests.py --create-workflow ${CLARIFAI_API_KEY} 30 | 31 | after_script: 32 | - export PYTHONPATH=. 33 | - python scripts/app_and_key_for_tests.py --delete-app $CLARIFAI_APP_ID 34 | 35 | before_deploy: 36 | - openssl aes-256-cbc -K $encrypted_fe71053f5cc2_key -iv $encrypted_fe71053f5cc2_iv -in gradle.properties.enc -out gradle.properties -d 37 | - IS_ALPHA=false; if [[ $TRAVIS_TAG == *"alpha"* ]]; then IS_ALPHA=true; fi 38 | 39 | deploy: 40 | - provider: script 41 | script: 42 | - ./gradlew bintrayUpload 43 | skip_cleanup: true 44 | on: 45 | jdk: openjdk11 46 | tags: true 47 | repo: Clarifai/clarifai-java 48 | - provider: releases 49 | skip_cleanup: true 50 | api_key: $GITHUB_TOKEN 51 | file_glob: true 52 | file: 53 | - core/build/libs/core-*.jar 54 | on: 55 | jdk: openjdk11 56 | tags: true 57 | repo: Clarifai/clarifai-java 58 | prerelease: $IS_ALPHA 59 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2016 Clarifai, Inc. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | branches: 2 | only: 3 | - master 4 | 5 | environment: 6 | matrix: 7 | - JAVA_HOME: C:\Program Files\Java\jdk1.8.0 8 | 9 | os: Windows Server 2012 10 | 11 | build_script: 12 | - gradlew.bat assemble --info --no-daemon 13 | 14 | before_test: 15 | - cd C:\projects\clarifai-java 16 | - for /f %%i in ('C:\Python36\python.exe scripts\app_and_key_for_tests.py --create-app java-appveyor') do set CLARIFAI_APP_ID=%%i 17 | - for /f %%i in ('C:\Python36\python.exe scripts\app_and_key_for_tests.py --create-key %CLARIFAI_APP_ID%') do set CLARIFAI_API_KEY=%%i 18 | - for /f %%i in ('C:\Python36\python.exe scripts\app_and_key_for_tests.py --create-workflow %CLARIFAI_API_KEY%') do rem 19 | 20 | test_script: 21 | - gradlew.bat check --info --no-daemon 22 | 23 | after_test: 24 | - cd C:\projects\clarifai-java 25 | - 'C:\Python36\python.exe scripts\app_and_key_for_tests.py --delete-app %CLARIFAI_APP_ID%' 26 | 27 | cache: 28 | - C:\Users\appveyor\.gradle 29 | 30 | matrix: 31 | fast_finish: true 32 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | maven { url "https://plugins.gradle.org/m2/" } 4 | } 5 | dependencies { 6 | classpath( 7 | "gradle.plugin.com.palantir.gradle.gitversion:gradle-git-version:0.5.3", 8 | "com.github.ben-manes:gradle-versions-plugin:0.13.0", 9 | "gradle.plugin.de.fuerstenau:BuildConfigPlugin:1.1.4", 10 | "net.ltgt.gradle:gradle-apt-plugin:0.21", 11 | "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3", 12 | ) 13 | } 14 | } 15 | subprojects { 16 | apply plugin: "java" 17 | apply plugin: "maven" 18 | apply plugin: "idea" 19 | apply plugin: "signing" 20 | apply plugin: "com.palantir.git-version" 21 | apply plugin: "com.github.ben-manes.versions" 22 | 23 | sourceCompatibility = JavaVersion.VERSION_1_7 24 | targetCompatibility = JavaVersion.VERSION_1_7 25 | 26 | // Set the group and version across all subprojects to ensure consistency 27 | group 'com.clarifai.clarifai-api2' 28 | def details = versionDetails() 29 | def tag = details.lastTag.replace(".dirty", "") 30 | if (details.commitDistance != 0) { 31 | tag = tag + '-' + details.gitHash 32 | } 33 | version tag 34 | println("Computed version as: ${getVersion()}") 35 | 36 | repositories { 37 | mavenLocal() 38 | jcenter() 39 | mavenCentral() 40 | maven { url "https://jitpack.io" } 41 | } 42 | 43 | ext.versions = [ 44 | autoValue: "1.5.2", 45 | autoValueWith: "1.0.0", 46 | customHashCodeEquals: "db3442d", 47 | grpc: "1.17.1", 48 | gson: "2.8.5", 49 | javaxAnnotationApi: "1.3.2", 50 | okhttp: "3.12.0", 51 | protobuf: "3.6.1", 52 | protobufJavaUtil: "3.6.1", 53 | 54 | junit: "4.12", 55 | junitRetryRule: "cbdd972", 56 | slf4j: "1.7.21", 57 | ] 58 | 59 | ext.deps = [ 60 | nullityAnnotations: "org.jetbrains:annotations:16.0.3", 61 | ] 62 | } 63 | 64 | wrapper { 65 | gradleVersion = "4.10.3" 66 | } 67 | -------------------------------------------------------------------------------- /core/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "de.fuerstenau.buildconfig" 2 | apply plugin: "net.ltgt.apt" 3 | apply from: rootProject.file("scripts/buildArtifacts.gradle") 4 | 5 | dependencies { 6 | compile( 7 | "com.squareup.okhttp3:okhttp:$versions.okhttp", 8 | "com.google.code.gson:gson:$versions.gson", 9 | "com.google.protobuf:protobuf-java:$versions.protobuf", 10 | 11 | "io.grpc:grpc-netty-shaded:$versions.grpc", 12 | "io.grpc:grpc-protobuf:$versions.grpc", 13 | "io.grpc:grpc-stub:$versions.grpc", 14 | "com.google.protobuf:protobuf-java-util:$versions.protobufJavaUtil", 15 | ) 16 | 17 | compileOnly( 18 | "com.google.auto.value:auto-value:$versions.autoValue", 19 | deps.nullityAnnotations, 20 | "com.github.kevinmost.auto-value-custom-hashcode-equals:adapter:$versions.customHashCodeEquals", 21 | "javax.annotation:javax.annotation-api:$versions.javaxAnnotationApi", 22 | ) 23 | 24 | annotationProcessor( 25 | "com.google.auto.value:auto-value:$versions.autoValue", 26 | "com.gabrielittner.auto.value:auto-value-with:$versions.autoValueWith", 27 | "com.github.kevinmost.auto-value-custom-hashcode-equals:processor:$versions.customHashCodeEquals", 28 | ) 29 | } 30 | 31 | apply from: rootProject.file("scripts/publishToMavenCentral.gradle") 32 | 33 | buildConfig { 34 | packageName = "clarifai2" 35 | clsName = "BuildConfig" 36 | } 37 | apply from: rootProject.file("gradle/pmd.gradle") 38 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/Func0.java: -------------------------------------------------------------------------------- 1 | package clarifai2; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | public interface Func0 { 6 | @NotNull R call(); 7 | } 8 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/Func1.java: -------------------------------------------------------------------------------- 1 | package clarifai2; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | public interface Func1 { 6 | @NotNull R call(@NotNull T t); 7 | } 8 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/ClarifaiToken.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | public final class ClarifaiToken { 6 | @NotNull private final String accessToken; 7 | private final long expiresAt; 8 | 9 | ClarifaiToken(@NotNull String accessToken, long expiresInSeconds) { 10 | this.accessToken = accessToken; 11 | this.expiresAt = System.currentTimeMillis() + (expiresInSeconds * 1000); 12 | } 13 | 14 | /** 15 | * @return the access token 16 | */ 17 | @NotNull public String getAccessToken() { 18 | return accessToken; 19 | } 20 | 21 | /** 22 | * @return the amount of milliseconds after the start of the Unix epoch when this token is considered expired 23 | */ 24 | public long getExpiresAt() { 25 | return expiresAt; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Classes that are used to access the Clarifai API. 3 | *

4 | * API client instances can be constructed via {@link clarifai2.api.ClarifaiBuilder}. 5 | */ 6 | package clarifai2.api; 7 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/PaginatedRequestVendor.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request; 2 | 3 | import com.google.common.util.concurrent.ListenableFuture; 4 | 5 | interface PaginatedRequestVendor { 6 | ListenableFuture vendRequestGrpc(int page); 7 | 8 | T vendResponseGrpc(Object returnedObject); 9 | } 10 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/concept/AddConceptsRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.concept; 2 | 3 | import clarifai2.internal.grpc.api.ConceptOuterClass; 4 | import clarifai2.Func1; 5 | import clarifai2.api.BaseClarifaiClient; 6 | import clarifai2.api.request.ClarifaiRequest; 7 | import clarifai2.dto.prediction.Concept; 8 | import clarifai2.internal.JSONArrayBuilder; 9 | import clarifai2.internal.JSONObjectBuilder; 10 | import clarifai2.internal.JSONUnmarshaler; 11 | import com.google.common.util.concurrent.ListenableFuture; 12 | import com.google.gson.Gson; 13 | import com.google.gson.JsonElement; 14 | import com.google.gson.JsonNull; 15 | import com.google.gson.JsonObject; 16 | import okhttp3.Request; 17 | import org.jetbrains.annotations.NotNull; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Arrays; 21 | import java.util.Collection; 22 | import java.util.List; 23 | 24 | public final class AddConceptsRequest extends ClarifaiRequest.Builder { 25 | 26 | @NotNull private final List concepts = new ArrayList<>(); 27 | 28 | public AddConceptsRequest(@NotNull BaseClarifaiClient client) { 29 | super(client); 30 | } 31 | 32 | @NotNull @Override protected String method() { 33 | return "POST"; 34 | } 35 | 36 | @NotNull @Override protected String subUrl() { 37 | return "v2/concepts"; 38 | } 39 | 40 | @NotNull public AddConceptsRequest plus(@NotNull Concept... concepts) { 41 | return plus(Arrays.asList(concepts)); 42 | } 43 | 44 | @NotNull public AddConceptsRequest plus(@NotNull Collection concepts) { 45 | this.concepts.addAll(concepts); 46 | return this; 47 | } 48 | 49 | @NotNull @Override protected DeserializedRequest request() { 50 | return new DeserializedRequest() { 51 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 52 | List protoConcepts = new ArrayList<>(); 53 | 54 | for (Concept concept : concepts) { 55 | protoConcepts.add(concept.serialize()); 56 | } 57 | 58 | 59 | return stub().postConcepts( 60 | ConceptOuterClass.PostConceptsRequest.newBuilder() 61 | .addAllConcepts(protoConcepts) 62 | .build() 63 | ); 64 | } 65 | 66 | @NotNull @Override public JsonNull unmarshalerGrpc(Object returnedObject) { 67 | return JsonNull.INSTANCE; 68 | } 69 | }; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/concept/GetConceptByIDRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.concept; 2 | 3 | import clarifai2.internal.grpc.api.ConceptOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import clarifai2.dto.prediction.Concept; 7 | import clarifai2.grpc.JsonChannel; 8 | import clarifai2.internal.JSONUnmarshaler; 9 | import com.google.common.util.concurrent.ListenableFuture; 10 | import com.google.gson.Gson; 11 | import com.google.gson.JsonElement; 12 | import okhttp3.Request; 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | public final class GetConceptByIDRequest extends ClarifaiRequest.Builder { 16 | 17 | @NotNull private final String conceptID; 18 | 19 | public GetConceptByIDRequest(@NotNull final BaseClarifaiClient helper, @NotNull String conceptID) { 20 | super(helper); 21 | this.conceptID = conceptID; 22 | } 23 | 24 | @NotNull @Override protected String method() { 25 | return "GET"; 26 | } 27 | 28 | @NotNull @Override protected String subUrl() { 29 | return "v2/concepts/" + conceptID; 30 | } 31 | 32 | @NotNull @Override protected DeserializedRequest request() { 33 | return new DeserializedRequest() { 34 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 35 | return stub() 36 | .getConcept(ConceptOuterClass.GetConceptRequest.newBuilder().build()); 37 | } 38 | 39 | @NotNull @Override public Concept unmarshalerGrpc(Object returnedObject) { 40 | ConceptOuterClass.SingleConceptResponse conceptResponse = 41 | (ConceptOuterClass.SingleConceptResponse) returnedObject; 42 | ConceptOuterClass.Concept concept = conceptResponse.getConcept(); 43 | 44 | return Concept.deserialize(concept); 45 | } 46 | }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/concept/GetConceptsRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.concept; 2 | 3 | import clarifai2.internal.grpc.api.ConceptOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiPaginatedRequest; 6 | import clarifai2.dto.prediction.Concept; 7 | import com.google.common.util.concurrent.ListenableFuture; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public final class GetConceptsRequest extends ClarifaiPaginatedRequest.Builder, GetConceptsRequest> { 14 | 15 | public GetConceptsRequest(@NotNull final BaseClarifaiClient helper) { 16 | super(helper); 17 | } 18 | 19 | @NotNull @Override protected String method() { 20 | return "GET"; 21 | } 22 | 23 | @NotNull @Override protected String subUrl(final int page) { 24 | return buildURL("v2/concepts", page); 25 | } 26 | 27 | @NotNull @Override protected List unmarshalerGrpc(Object returnedObject) { 28 | ConceptOuterClass.MultiConceptResponse conceptsResponse = (ConceptOuterClass.MultiConceptResponse) returnedObject; 29 | 30 | List concepts = new ArrayList<>(); 31 | for (ConceptOuterClass.Concept concept : conceptsResponse.getConceptsList()) { 32 | concepts.add(Concept.deserialize(concept)); 33 | } 34 | 35 | return concepts; 36 | } 37 | 38 | @NotNull @Override protected ListenableFuture buildRequestGrpc(int page) { 39 | return stub(page).listConcepts(ConceptOuterClass.ListConceptsRequest.newBuilder().build()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/concept/ModifyConceptsRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.concept; 2 | 3 | import clarifai2.internal.grpc.api.ConceptOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import clarifai2.dto.prediction.Concept; 7 | import com.google.common.util.concurrent.ListenableFuture; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Arrays; 12 | import java.util.Collection; 13 | import java.util.List; 14 | 15 | public final class ModifyConceptsRequest extends ClarifaiRequest.Builder> { 16 | @NotNull private final String action; 17 | @NotNull private final List concepts = new ArrayList<>(); 18 | 19 | public ModifyConceptsRequest(@NotNull BaseClarifaiClient client, @NotNull String action) { 20 | super(client); 21 | this.action = action; 22 | } 23 | 24 | @NotNull public ModifyConceptsRequest plus(@NotNull Concept... concepts) { 25 | return plus(Arrays.asList(concepts)); 26 | } 27 | 28 | @NotNull public ModifyConceptsRequest plus(@NotNull Collection concepts) { 29 | this.concepts.addAll(concepts); 30 | return this; 31 | } 32 | 33 | @NotNull @Override protected String method() { 34 | return "PATCH"; 35 | } 36 | 37 | @NotNull @Override protected String subUrl() { 38 | return "v2/concepts"; 39 | } 40 | 41 | @NotNull @Override protected DeserializedRequest> request() { 42 | return new DeserializedRequest>() { 43 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 44 | List conceptsGrpc = new ArrayList<>(); 45 | for (Concept concept : concepts) { 46 | conceptsGrpc.add(concept.serialize()); 47 | } 48 | return stub().patchConcepts( 49 | ConceptOuterClass.PatchConceptsRequest.newBuilder().setAction(action).addAllConcepts(conceptsGrpc).build() 50 | ); 51 | } 52 | 53 | @NotNull @Override public List unmarshalerGrpc(Object returnedObject) { 54 | ConceptOuterClass.MultiConceptResponse conceptsResponse = 55 | (ConceptOuterClass.MultiConceptResponse) returnedObject; 56 | List conceptsResult = new ArrayList<>(); 57 | for (ConceptOuterClass.Concept concept : conceptsResponse.getConceptsList()) { 58 | conceptsResult.add(Concept.deserialize(concept)); 59 | } 60 | return conceptsResult; 61 | } 62 | }; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/concept/SearchConceptsRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.concept; 2 | 3 | import clarifai2.internal.grpc.api.ConceptOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiPaginatedRequest; 6 | import clarifai2.dto.prediction.Concept; 7 | import com.google.common.util.concurrent.ListenableFuture; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.jetbrains.annotations.Nullable; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | public final class SearchConceptsRequest 15 | extends ClarifaiPaginatedRequest.Builder, SearchConceptsRequest> { 16 | 17 | 18 | @NotNull private final String conceptSearchQuery; 19 | 20 | @Nullable private String language = null; 21 | 22 | public SearchConceptsRequest(@NotNull final BaseClarifaiClient client, @NotNull String conceptSearchQuery) { 23 | super(client); 24 | this.conceptSearchQuery = conceptSearchQuery; 25 | } 26 | 27 | @NotNull public SearchConceptsRequest withLanguage(@NotNull String language) { 28 | this.language = language; 29 | return this; 30 | } 31 | 32 | @NotNull @Override protected String method() { 33 | return "POST"; 34 | } 35 | 36 | @NotNull @Override protected String subUrl(int page) { 37 | return buildURL("v2/concepts/searches", page); 38 | } 39 | 40 | @NotNull @Override protected List unmarshalerGrpc(Object returnedObject) { 41 | ConceptOuterClass.MultiConceptResponse conceptsResponse = (ConceptOuterClass.MultiConceptResponse) returnedObject; 42 | 43 | List concepts = new ArrayList<>(); 44 | for (ConceptOuterClass.Concept concept : conceptsResponse.getConceptsList()) { 45 | concepts.add(Concept.deserialize(concept)); 46 | } 47 | 48 | return concepts; 49 | } 50 | 51 | @NotNull @Override protected ListenableFuture buildRequestGrpc(int page) { 52 | ConceptOuterClass.ConceptQuery.Builder conceptQuery = ConceptOuterClass.ConceptQuery.newBuilder() 53 | .setName(conceptSearchQuery); 54 | if (language != null) { 55 | conceptQuery.setLanguage(language); 56 | } 57 | return stub(page).postConceptsSearches( 58 | ConceptOuterClass.PostConceptsSearchesRequest.newBuilder().setConceptQuery(conceptQuery).build() 59 | ); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/input/DeleteAllInputsRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.input; 2 | 3 | import clarifai2.internal.grpc.api.InputOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import com.google.common.util.concurrent.ListenableFuture; 7 | import com.google.gson.JsonNull; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | public class DeleteAllInputsRequest extends ClarifaiRequest.Builder { 11 | 12 | 13 | public DeleteAllInputsRequest(@NotNull BaseClarifaiClient client) { 14 | super(client); 15 | } 16 | 17 | @NotNull @Override protected String method() { 18 | return "DELETE"; 19 | } 20 | 21 | @NotNull @Override protected String subUrl() { 22 | return "v2/inputs"; 23 | } 24 | 25 | @NotNull @Override protected DeserializedRequest request() { 26 | return new DeserializedRequest() { 27 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 28 | return stub().deleteInputs(InputOuterClass.DeleteInputsRequest.newBuilder().setDeleteAll(true).build()); 29 | } 30 | 31 | @NotNull @Override public JsonNull unmarshalerGrpc(Object returnedObject) { 32 | return JsonNull.INSTANCE; 33 | } 34 | }; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/input/DeleteInputRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.input; 2 | 3 | import clarifai2.internal.grpc.api.InputOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import com.google.common.util.concurrent.ListenableFuture; 7 | import com.google.gson.JsonNull; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | public final class DeleteInputRequest extends ClarifaiRequest.Builder { 11 | 12 | private final String inputID; 13 | 14 | public DeleteInputRequest(@NotNull BaseClarifaiClient client, @NotNull String inputID) { 15 | super(client); 16 | this.inputID = inputID; 17 | } 18 | 19 | @NotNull @Override protected String method() { 20 | return "DELETE"; 21 | } 22 | 23 | @NotNull @Override protected String subUrl() { 24 | return "v2/inputs/" + inputID; 25 | } 26 | 27 | @NotNull @Override protected DeserializedRequest request() { 28 | return new DeserializedRequest() { 29 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 30 | return stub().deleteInput(InputOuterClass.DeleteInputRequest.newBuilder().build()); 31 | } 32 | 33 | @NotNull @Override public JsonNull unmarshalerGrpc(Object returnedObject) { 34 | return JsonNull.INSTANCE; 35 | } 36 | }; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/input/DeleteInputsBatchRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.input; 2 | 3 | import clarifai2.internal.grpc.api.InputOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import com.google.common.util.concurrent.ListenableFuture; 7 | import com.google.gson.JsonNull; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Arrays; 12 | import java.util.Collection; 13 | import java.util.List; 14 | 15 | public class DeleteInputsBatchRequest extends ClarifaiRequest.Builder { 16 | 17 | @NotNull private final List inputIDs = new ArrayList<>(); 18 | 19 | public DeleteInputsBatchRequest(@NotNull BaseClarifaiClient client) { 20 | super(client); 21 | } 22 | 23 | @NotNull @Override protected String method() { 24 | return "DELETE"; 25 | } 26 | 27 | @NotNull @Override protected String subUrl() { 28 | return "v2/inputs"; 29 | } 30 | 31 | @NotNull public DeleteInputsBatchRequest plus(@NotNull String... inputIDs) { 32 | return plus(Arrays.asList(inputIDs)); 33 | } 34 | 35 | @NotNull public DeleteInputsBatchRequest plus(@NotNull Collection inputIDs) { 36 | this.inputIDs.addAll(inputIDs); 37 | return this; 38 | } 39 | 40 | @NotNull @Override protected DeserializedRequest request() { 41 | return new DeserializedRequest() { 42 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 43 | return stub().deleteInputs(InputOuterClass.DeleteInputsRequest.newBuilder().addAllIds(inputIDs).build()); 44 | } 45 | 46 | @NotNull @Override public JsonNull unmarshalerGrpc(Object returnedObject) { 47 | return JsonNull.INSTANCE; 48 | } 49 | }; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/input/GetInputRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.input; 2 | 3 | import clarifai2.internal.grpc.api.InputOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import clarifai2.dto.input.ClarifaiInput; 7 | import com.google.common.util.concurrent.ListenableFuture; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | public final class GetInputRequest extends ClarifaiRequest.Builder { 11 | 12 | @NotNull private final String inputID; 13 | 14 | public GetInputRequest(@NotNull final BaseClarifaiClient helper, @NotNull String inputID) { 15 | super(helper); 16 | this.inputID = inputID; 17 | } 18 | 19 | @NotNull @Override protected String method() { 20 | return "GET"; 21 | } 22 | 23 | @NotNull @Override protected String subUrl() { 24 | return "v2/inputs/" + inputID; 25 | } 26 | 27 | @NotNull @Override protected DeserializedRequest request() { 28 | return new DeserializedRequest() { 29 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 30 | return stub() 31 | .getInput(InputOuterClass.GetInputRequest.newBuilder().build()); 32 | } 33 | 34 | @NotNull @Override public ClarifaiInput unmarshalerGrpc(Object returnedObject) { 35 | InputOuterClass.SingleInputResponse inputResponse = (InputOuterClass.SingleInputResponse) returnedObject; 36 | return ClarifaiInput.deserialize(inputResponse.getInput()); 37 | } 38 | }; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/input/GetInputsRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.input; 2 | 3 | import clarifai2.internal.grpc.api.InputOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiPaginatedRequest; 6 | import clarifai2.dto.input.ClarifaiInput; 7 | import com.google.common.util.concurrent.ListenableFuture; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public final class GetInputsRequest extends ClarifaiPaginatedRequest.Builder, GetInputsRequest> { 14 | public GetInputsRequest(@NotNull final BaseClarifaiClient client) { 15 | super(client); 16 | } 17 | 18 | @NotNull @Override protected String method() { 19 | return "GET"; 20 | } 21 | 22 | @NotNull @Override protected String subUrl(final int page) { 23 | return buildURL("v2/inputs", page); 24 | } 25 | 26 | @NotNull @Override protected List unmarshalerGrpc(Object returnedObject) { 27 | InputOuterClass.MultiInputResponse inputsResponse = (InputOuterClass.MultiInputResponse) returnedObject; 28 | List inputs = new ArrayList<>(); 29 | for (InputOuterClass.Input input : inputsResponse.getInputsList()) { 30 | inputs.add(ClarifaiInput.deserialize(input)); 31 | } 32 | return inputs; 33 | } 34 | 35 | @NotNull @Override protected ListenableFuture buildRequestGrpc(int page) { 36 | return stub(page).listInputs( 37 | InputOuterClass.ListInputsRequest.newBuilder() 38 | .build() 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/input/GetInputsStatusRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.input; 2 | 3 | import clarifai2.internal.grpc.api.InputOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import clarifai2.dto.input.ClarifaiInputsStatus; 7 | import com.google.common.util.concurrent.ListenableFuture; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | public final class GetInputsStatusRequest extends ClarifaiRequest.Builder { 11 | 12 | public GetInputsStatusRequest(@NotNull final BaseClarifaiClient helper) { 13 | super(helper); 14 | } 15 | 16 | @NotNull @Override protected String method() { 17 | return "GET"; 18 | } 19 | 20 | @NotNull @Override protected String subUrl() { 21 | return "v2/inputs/status"; 22 | } 23 | 24 | @NotNull @Override protected DeserializedRequest request() { 25 | return new DeserializedRequest() { 26 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 27 | return stub().getInputCount(InputOuterClass.GetInputCountRequest.newBuilder().build()); 28 | } 29 | 30 | @NotNull @Override public ClarifaiInputsStatus unmarshalerGrpc(Object returnedObject) { 31 | InputOuterClass.SingleInputCountResponse inputCountResponse = 32 | (InputOuterClass.SingleInputCountResponse) returnedObject; 33 | return ClarifaiInputsStatus.deserialize(inputCountResponse.getCounts()); 34 | } 35 | }; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/input/PatchInputMetadataRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.input; 2 | 3 | import clarifai2.internal.grpc.api.DataOuterClass; 4 | import clarifai2.internal.grpc.api.InputOuterClass; 5 | import clarifai2.api.BaseClarifaiClient; 6 | import clarifai2.api.request.ClarifaiRequest; 7 | import clarifai2.dto.input.ClarifaiInput; 8 | import clarifai2.grpc.MetadataConverter; 9 | import clarifai2.internal.InternalUtil; 10 | import com.google.common.util.concurrent.ListenableFuture; 11 | import com.google.gson.JsonObject; 12 | import com.google.protobuf.Struct; 13 | import org.jetbrains.annotations.NotNull; 14 | 15 | public final class PatchInputMetadataRequest extends ClarifaiRequest.Builder { 16 | 17 | @NotNull private final String inputID; 18 | @NotNull private final JsonObject metadata; 19 | 20 | public PatchInputMetadataRequest( 21 | @NotNull BaseClarifaiClient client, 22 | @NotNull String inputID, 23 | @NotNull JsonObject metadata 24 | ) { 25 | super(client); 26 | this.inputID = inputID; 27 | this.metadata = metadata; 28 | InternalUtil.assertMetadataHasNoNulls(metadata); 29 | } 30 | 31 | @NotNull @Override protected String method() { 32 | return "PATCH"; 33 | } 34 | 35 | @NotNull @Override protected String subUrl() { 36 | return "v2/inputs"; 37 | } 38 | 39 | @NotNull @Override protected DeserializedRequest request() { 40 | return new DeserializedRequest() { 41 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 42 | Struct metadataGrpc = MetadataConverter.jsonObjectToStruct(metadata); 43 | 44 | InputOuterClass.Input.Builder inputGrpc = InputOuterClass.Input.newBuilder() 45 | .setId(inputID) 46 | .setData(DataOuterClass.Data.newBuilder().setMetadata(metadataGrpc)); 47 | return stub().patchInputs( 48 | InputOuterClass.PatchInputsRequest.newBuilder().setAction("overwrite").addInputs(inputGrpc).build() 49 | ); 50 | } 51 | 52 | @NotNull @Override public ClarifaiInput unmarshalerGrpc(Object returnedObject) { 53 | InputOuterClass.MultiInputResponse inputsResponse = (InputOuterClass.MultiInputResponse) returnedObject; 54 | return ClarifaiInput.deserialize(inputsResponse.getInputs(0)); 55 | } 56 | }; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/CreateModelGenericRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.internal.grpc.api.ModelOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import clarifai2.dto.model.Model; 7 | import clarifai2.dto.model.output_info.OutputInfo; 8 | import com.google.common.util.concurrent.ListenableFuture; 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | public final class CreateModelGenericRequest> extends ClarifaiRequest.Builder { 13 | 14 | @NotNull private final String id; 15 | @Nullable private OutputInfo outputInfo; 16 | @Nullable private String name = null; 17 | 18 | public CreateModelGenericRequest(@NotNull final BaseClarifaiClient helper, @NotNull final String id) { 19 | super(helper); 20 | this.id = id; 21 | } 22 | 23 | @NotNull public CreateModelGenericRequest withOutputInfo(@Nullable OutputInfo outputInfo) { 24 | this.outputInfo = outputInfo; 25 | return this; 26 | } 27 | 28 | @NotNull public CreateModelGenericRequest withName(@Nullable String name) { 29 | this.name = name; 30 | return this; 31 | } 32 | 33 | @NotNull @Override protected String method() { 34 | return "POST"; 35 | } 36 | 37 | @NotNull @Override protected String subUrl() { 38 | return "v2/models"; 39 | } 40 | 41 | @NotNull @Override protected DeserializedRequest request() { 42 | return new DeserializedRequest() { 43 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 44 | ModelOuterClass.Model.Builder modelBuilder = ModelOuterClass.Model.newBuilder() 45 | .setId(id); 46 | if (name != null) { 47 | modelBuilder.setName(name); 48 | } 49 | if (outputInfo != null) { 50 | modelBuilder.setOutputInfo(outputInfo.serialize()); 51 | } 52 | return stub().postModels(ModelOuterClass.PostModelsRequest.newBuilder().addModels(modelBuilder).build()); 53 | } 54 | 55 | @NotNull @Override public T unmarshalerGrpc(Object returnedObject) { 56 | ModelOuterClass.SingleModelResponse modelResponse = (ModelOuterClass.SingleModelResponse) returnedObject; 57 | return (T) Model.deserialize(modelResponse.getModel(), client); 58 | } 59 | }; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/CreateModelRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.internal.grpc.api.ModelOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import clarifai2.dto.model.ConceptModel; 7 | import clarifai2.dto.model.Model; 8 | import clarifai2.dto.model.output_info.ConceptOutputInfo; 9 | import com.google.common.util.concurrent.ListenableFuture; 10 | import org.jetbrains.annotations.NotNull; 11 | import org.jetbrains.annotations.Nullable; 12 | 13 | public final class CreateModelRequest extends ClarifaiRequest.Builder { 14 | 15 | @NotNull private final String id; 16 | @Nullable private ConceptOutputInfo outputInfo; 17 | @Nullable private String name = null; 18 | 19 | public CreateModelRequest(@NotNull final BaseClarifaiClient helper, @NotNull final String id) { 20 | super(helper); 21 | this.id = id; 22 | } 23 | 24 | @NotNull public CreateModelRequest withOutputInfo(@Nullable ConceptOutputInfo outputInfo) { 25 | this.outputInfo = outputInfo; 26 | return this; 27 | } 28 | 29 | @NotNull public CreateModelRequest withName(@Nullable String name) { 30 | this.name = name; 31 | return this; 32 | } 33 | 34 | @NotNull @Override protected String method() { 35 | return "POST"; 36 | } 37 | 38 | @NotNull @Override protected String subUrl() { 39 | return "v2/models"; 40 | } 41 | 42 | @NotNull @Override protected DeserializedRequest request() { 43 | return new DeserializedRequest() { 44 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 45 | ModelOuterClass.Model.Builder modelBuilder = ModelOuterClass.Model.newBuilder() 46 | .setId(id); 47 | if (name != null) { 48 | modelBuilder.setName(name); 49 | } 50 | if (outputInfo != null) { 51 | modelBuilder.setOutputInfo(outputInfo.serialize()); 52 | } 53 | return stub().postModels(ModelOuterClass.PostModelsRequest.newBuilder().addModels(modelBuilder).build()); 54 | } 55 | 56 | @NotNull @Override public ConceptModel unmarshalerGrpc(Object returnedObject) { 57 | ModelOuterClass.SingleModelResponse modelResponse = (ModelOuterClass.SingleModelResponse) returnedObject; 58 | return Model.deserialize(modelResponse.getModel(), client).asConceptModel(); 59 | } 60 | }; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/DeleteAllModelsRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.internal.grpc.api.ModelOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import com.google.common.util.concurrent.ListenableFuture; 7 | import com.google.gson.JsonNull; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | public final class DeleteAllModelsRequest extends ClarifaiRequest.Builder { 11 | 12 | public DeleteAllModelsRequest(@NotNull final BaseClarifaiClient helper) { 13 | super(helper); 14 | } 15 | 16 | @NotNull @Override protected String method() { 17 | return "DELETE"; 18 | } 19 | 20 | @NotNull @Override protected String subUrl() { 21 | return "v2/models"; 22 | } 23 | 24 | @NotNull @Override protected DeserializedRequest request() { 25 | return new DeserializedRequest() { 26 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 27 | return stub().deleteModels(ModelOuterClass.DeleteModelsRequest.newBuilder().setDeleteAll(true).build()); 28 | } 29 | 30 | @NotNull @Override public JsonNull unmarshalerGrpc(Object returnedObject) { 31 | return JsonNull.INSTANCE; 32 | } 33 | }; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/DeleteModelRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.internal.grpc.api.ModelOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import com.google.common.util.concurrent.ListenableFuture; 7 | import com.google.gson.JsonNull; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | public final class DeleteModelRequest extends ClarifaiRequest.Builder { 11 | 12 | @NotNull private final String modelID; 13 | 14 | public DeleteModelRequest(@NotNull final BaseClarifaiClient helper, @NotNull String modelID) { 15 | super(helper); 16 | this.modelID = modelID; 17 | } 18 | 19 | @NotNull @Override protected String method() { 20 | return "DELETE"; 21 | } 22 | 23 | @NotNull @Override protected String subUrl() { 24 | return "v2/models/" + modelID; 25 | } 26 | 27 | @NotNull @Override protected DeserializedRequest request() { 28 | return new DeserializedRequest() { 29 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 30 | return stub().deleteModel(ModelOuterClass.DeleteModelRequest.newBuilder().build()); 31 | } 32 | 33 | @NotNull @Override public JsonNull unmarshalerGrpc(Object returnedObject) { 34 | return JsonNull.INSTANCE; 35 | } 36 | }; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/DeleteModelVersionRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.internal.grpc.api.ModelVersionOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import clarifai2.dto.model.ModelVersion; 7 | import com.google.common.util.concurrent.ListenableFuture; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import java.util.Collections; 11 | import java.util.List; 12 | 13 | // The returned object here should be JsonNull since the response does not actually return any ModelVersions. 14 | // But changing this would break client code. 15 | public final class DeleteModelVersionRequest extends ClarifaiRequest.Builder> { 16 | 17 | @NotNull private final String modelID; 18 | @NotNull private final String versionID; 19 | 20 | public DeleteModelVersionRequest( 21 | @NotNull BaseClarifaiClient client, 22 | @NotNull String modelID, 23 | @NotNull String versionID 24 | ) { 25 | super(client); 26 | this.modelID = modelID; 27 | this.versionID = versionID; 28 | } 29 | 30 | @NotNull @Override protected String method() { 31 | return "DELETE"; 32 | } 33 | 34 | @NotNull @Override protected String subUrl() { 35 | return String.format("v2/models/%s/versions/%s", modelID, versionID); 36 | } 37 | 38 | @NotNull @Override protected DeserializedRequest> request() { 39 | return new DeserializedRequest>() { 40 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 41 | return stub().deleteModelVersion(ModelVersionOuterClass.DeleteModelVersionRequest.newBuilder().build()); 42 | } 43 | 44 | @NotNull @Override public List unmarshalerGrpc(Object returnedObject) { 45 | return Collections.emptyList(); 46 | } 47 | }; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/DeleteModelsBatchRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.internal.grpc.api.ModelOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import com.google.common.util.concurrent.ListenableFuture; 7 | import com.google.gson.JsonNull; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Arrays; 12 | import java.util.Collection; 13 | import java.util.List; 14 | 15 | public final class DeleteModelsBatchRequest extends ClarifaiRequest.Builder { 16 | 17 | @NotNull private final List modelIDs = new ArrayList<>(); 18 | 19 | public DeleteModelsBatchRequest(@NotNull BaseClarifaiClient client) { 20 | super(client); 21 | } 22 | 23 | @NotNull @Override protected String method() { 24 | return "DELETE"; 25 | } 26 | 27 | @NotNull @Override protected String subUrl() { 28 | return "v2/models"; 29 | } 30 | 31 | @NotNull public DeleteModelsBatchRequest plus(@NotNull String... modelIDs) { 32 | return plus(Arrays.asList(modelIDs)); 33 | } 34 | 35 | @NotNull public DeleteModelsBatchRequest plus(@NotNull Collection modelIDs) { 36 | this.modelIDs.addAll(modelIDs); 37 | return this; 38 | } 39 | 40 | @NotNull @Override protected DeserializedRequest request() { 41 | return new DeserializedRequest() { 42 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 43 | return stub().deleteModels(ModelOuterClass.DeleteModelsRequest.newBuilder().addAllIds(modelIDs).build()); 44 | } 45 | 46 | @NotNull @Override public JsonNull unmarshalerGrpc(Object returnedObject) { 47 | return JsonNull.INSTANCE; 48 | } 49 | }; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/FindModelRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.api.BaseClarifaiClient; 4 | import clarifai2.api.request.ClarifaiPaginatedRequest; 5 | import clarifai2.dto.model.Model; 6 | import clarifai2.dto.model.ModelType; 7 | import com.google.common.util.concurrent.ListenableFuture; 8 | import clarifai2.internal.grpc.api.ModelOuterClass; 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | public final class FindModelRequest extends ClarifaiPaginatedRequest.Builder>, FindModelRequest> { 16 | 17 | @Nullable private String name; 18 | @Nullable private ModelType modelType; 19 | 20 | public FindModelRequest(@NotNull final BaseClarifaiClient client) { 21 | super(client); 22 | } 23 | 24 | @NotNull @Override protected String method() { 25 | return "POST"; 26 | } 27 | 28 | @NotNull @Override protected String subUrl(final int page) { 29 | return buildURL("v2/models/searches", page); 30 | } 31 | 32 | @NotNull public FindModelRequest withName(@Nullable String name) { 33 | this.name = name; 34 | return this; 35 | } 36 | 37 | @NotNull public FindModelRequest withModelType(@NotNull ModelType modelType) { 38 | this.modelType = modelType; 39 | return this; 40 | } 41 | 42 | @NotNull @Override protected List> unmarshalerGrpc(Object returnedObject) { 43 | ModelOuterClass.MultiModelResponse modelsResponse = (ModelOuterClass.MultiModelResponse) returnedObject; 44 | List> models = new ArrayList<>(); 45 | for (ModelOuterClass.Model model : modelsResponse.getModelsList()) { 46 | models.add(Model.deserialize(model, client)); 47 | } 48 | return models; 49 | } 50 | 51 | @NotNull @Override protected ListenableFuture buildRequestGrpc(int page) { 52 | ModelOuterClass.ModelQuery.Builder modelQuery = ModelOuterClass.ModelQuery.newBuilder(); 53 | if (name != null) { 54 | modelQuery.setName(name); 55 | } 56 | if (modelType != null) { 57 | modelQuery.setType(modelType.typeExt()); 58 | } 59 | return stub(page).postModelsSearches( 60 | ModelOuterClass.PostModelsSearchesRequest.newBuilder().setModelQuery(modelQuery).build() 61 | ); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/GetModelInputsRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.internal.grpc.api.InputOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiPaginatedRequest; 6 | import clarifai2.dto.input.ClarifaiInput; 7 | import clarifai2.dto.model.ModelVersion; 8 | import com.google.common.util.concurrent.ListenableFuture; 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | public final class GetModelInputsRequest 16 | extends ClarifaiPaginatedRequest.Builder, GetModelInputsRequest> { 17 | 18 | @NotNull private final String modelID; 19 | 20 | @Nullable private String modelVersionID; 21 | 22 | public GetModelInputsRequest(@NotNull final BaseClarifaiClient client, @NotNull String modelID) { 23 | super(client); 24 | this.modelID = modelID; 25 | } 26 | 27 | @NotNull public GetModelInputsRequest fromSpecificModelVersion(@NotNull String modelVersionID) { 28 | this.modelVersionID = modelVersionID; 29 | return this; 30 | } 31 | 32 | @NotNull public GetModelInputsRequest fromSpecificModelVersion(@NotNull ModelVersion modelVersion) { 33 | return fromSpecificModelVersion(modelVersion.id()); 34 | } 35 | 36 | @NotNull @Override protected String method() { 37 | return "GET"; 38 | } 39 | 40 | @NotNull @Override protected String subUrl(final int page) { 41 | String url; 42 | if (modelVersionID != null) { 43 | url = "v2/models/" + modelID + "/versions/" + modelVersionID + "/inputs"; 44 | } else { 45 | url = "v2/models/" + modelID + "/inputs"; 46 | } 47 | return buildURL(url, page); 48 | } 49 | 50 | @NotNull @Override protected List unmarshalerGrpc(Object returnedObject) { 51 | InputOuterClass.MultiInputResponse inputsResponse = (InputOuterClass.MultiInputResponse) returnedObject; 52 | List inputs = new ArrayList<>(); 53 | for (InputOuterClass.Input input : inputsResponse.getInputsList()) { 54 | inputs.add(ClarifaiInput.deserialize(input)); 55 | } 56 | return inputs; 57 | } 58 | 59 | @NotNull @Override protected ListenableFuture buildRequestGrpc(int page) { 60 | return stub(page).listModelInputs(InputOuterClass.ListModelInputsRequest.newBuilder().build()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/GetModelRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.dto.model.ModelVersion; 4 | import clarifai2.internal.grpc.api.ModelOuterClass; 5 | import clarifai2.api.BaseClarifaiClient; 6 | import clarifai2.api.request.ClarifaiRequest; 7 | import clarifai2.dto.model.Model; 8 | import com.google.common.util.concurrent.ListenableFuture; 9 | import org.jetbrains.annotations.NotNull; 10 | import org.jetbrains.annotations.Nullable; 11 | 12 | public final class GetModelRequest extends ClarifaiRequest.Builder> { 13 | 14 | @NotNull private final String modelID; 15 | @Nullable private String modelVersionID; 16 | 17 | public GetModelRequest( 18 | @NotNull final BaseClarifaiClient helper, 19 | @NotNull String modelID 20 | ) { 21 | super(helper); 22 | this.modelID = modelID; 23 | } 24 | 25 | @NotNull public GetModelRequest withVersion(@NotNull ModelVersion version) { 26 | return withVersion(version.id()); 27 | } 28 | 29 | @NotNull public GetModelRequest withVersion(@NotNull String versionID) { 30 | this.modelVersionID = versionID; 31 | return this; 32 | } 33 | 34 | 35 | @NotNull @Override protected String method() { 36 | return "GET"; 37 | } 38 | 39 | @NotNull @Override protected String subUrl() { 40 | if (modelVersionID == null) { 41 | return "v2/models/" + modelID + "/output_info"; 42 | } 43 | return "v2/models/" + modelID + "/versions/" + modelVersionID + "/output_info"; 44 | } 45 | 46 | @NotNull @Override protected DeserializedRequest> request() { 47 | return new DeserializedRequest>() { 48 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 49 | return stub().getModel(ModelOuterClass.GetModelRequest.newBuilder().build()); 50 | } 51 | 52 | @NotNull @Override public Model unmarshalerGrpc(Object returnedObject) { 53 | ModelOuterClass.SingleModelResponse modelResponse = (ModelOuterClass.SingleModelResponse) returnedObject; 54 | return Model.deserialize(modelResponse.getModel(), client); 55 | } 56 | }; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/GetModelVersionRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.internal.grpc.api.ModelVersionOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import clarifai2.dto.model.ModelVersion; 7 | import com.google.common.util.concurrent.ListenableFuture; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | public final class GetModelVersionRequest extends ClarifaiRequest.Builder { 11 | 12 | @NotNull private final String modelID; 13 | @NotNull private final String versionID; 14 | 15 | public GetModelVersionRequest( 16 | @NotNull BaseClarifaiClient client, 17 | @NotNull String modelID, 18 | @NotNull String versionID 19 | ) { 20 | super(client); 21 | this.modelID = modelID; 22 | this.versionID = versionID; 23 | } 24 | 25 | @NotNull @Override protected String method() { 26 | return "GET"; 27 | } 28 | 29 | @NotNull @Override protected String subUrl() { 30 | return String.format("v2/models/%s/versions/%s", modelID, versionID); 31 | } 32 | 33 | @NotNull @Override protected DeserializedRequest request() { 34 | return new DeserializedRequest() { 35 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 36 | return stub().getModelVersion(ModelVersionOuterClass.GetModelVersionRequest.newBuilder().build()); 37 | } 38 | 39 | @NotNull @Override public ModelVersion unmarshalerGrpc(Object returnedObject) { 40 | ModelVersionOuterClass.SingleModelVersionResponse modelVersionResponse = 41 | (ModelVersionOuterClass.SingleModelVersionResponse) returnedObject; 42 | return ModelVersion.deserialize(modelVersionResponse.getModelVersion()); 43 | } 44 | }; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/GetModelVersionsRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.internal.grpc.api.ModelVersionOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiPaginatedRequest; 6 | import clarifai2.dto.model.ModelVersion; 7 | import com.google.common.util.concurrent.ListenableFuture; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public final class GetModelVersionsRequest 14 | extends ClarifaiPaginatedRequest.Builder, GetModelVersionsRequest> { 15 | 16 | @NotNull private final String modelID; 17 | 18 | public GetModelVersionsRequest(@NotNull final BaseClarifaiClient client, @NotNull String modelID) { 19 | super(client); 20 | this.modelID = modelID; 21 | } 22 | 23 | @NotNull @Override protected String method() { 24 | return "GET"; 25 | } 26 | 27 | @NotNull @Override protected String subUrl(int page) { 28 | return buildURL("v2/models/" + modelID + "/versions", page); 29 | } 30 | 31 | @NotNull @Override protected List unmarshalerGrpc(Object returnedObject) { 32 | ModelVersionOuterClass.MultiModelVersionResponse modelVersionsResponse = 33 | (ModelVersionOuterClass.MultiModelVersionResponse) returnedObject; 34 | 35 | List modelVersions = new ArrayList<>(); 36 | for (ModelVersionOuterClass.ModelVersion modelVersion : modelVersionsResponse.getModelVersionsList()) { 37 | modelVersions.add(ModelVersion.deserialize(modelVersion)); 38 | } 39 | 40 | return modelVersions; 41 | } 42 | 43 | @NotNull @Override protected ListenableFuture buildRequestGrpc(int page) { 44 | return stub(page).listModelVersions(ModelVersionOuterClass.ListModelVersionsRequest.newBuilder().build()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/GetModelsRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.internal.grpc.api.ModelOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiPaginatedRequest; 6 | import clarifai2.dto.model.Model; 7 | import com.google.common.util.concurrent.ListenableFuture; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | public final class GetModelsRequest extends ClarifaiPaginatedRequest.Builder>, GetModelsRequest> { 14 | 15 | public GetModelsRequest(@NotNull final BaseClarifaiClient client) { 16 | super(client); 17 | } 18 | 19 | @NotNull @Override protected String method() { 20 | return "GET"; 21 | } 22 | 23 | @NotNull @Override protected String subUrl(int page) { 24 | return buildURL("v2/models", page); 25 | } 26 | 27 | @NotNull @Override protected List> unmarshalerGrpc(Object returnedObject) { 28 | ModelOuterClass.MultiModelResponse modelsResponse = (ModelOuterClass.MultiModelResponse) returnedObject; 29 | List> models = new ArrayList<>(); 30 | for (ModelOuterClass.Model model : modelsResponse.getModelsList()) { 31 | models.add(Model.deserialize(model, client)); 32 | } 33 | return models; 34 | } 35 | 36 | @NotNull @Override protected ListenableFuture buildRequestGrpc(int page) { 37 | return stub(page).listModels(ModelOuterClass.ListModelsRequest.newBuilder().build()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/PatchModelRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.api.BaseClarifaiClient; 4 | import clarifai2.api.request.ClarifaiRequest; 5 | import clarifai2.dto.model.ConceptModel; 6 | import clarifai2.dto.prediction.Concept; 7 | import org.jetbrains.annotations.NotNull; 8 | import org.jetbrains.annotations.Nullable; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Arrays; 12 | import java.util.Collection; 13 | import java.util.List; 14 | 15 | /** 16 | * @deprecated use {@link ModifyModelRequest} 17 | */ 18 | @Deprecated 19 | public final class PatchModelRequest extends ClarifaiRequest.Builder { 20 | 21 | @NotNull private final String modelID; 22 | @NotNull private final Action action; 23 | @NotNull private final List concepts = new ArrayList<>(); 24 | 25 | @Nullable private String language = null; 26 | 27 | public PatchModelRequest( 28 | @NotNull final BaseClarifaiClient helper, 29 | @NotNull String modelID, 30 | @NotNull Action action 31 | ) { 32 | super(helper); 33 | this.modelID = modelID; 34 | this.action = action; 35 | } 36 | 37 | @NotNull public PatchModelRequest plus(@NotNull Concept... concepts) { 38 | return plus(Arrays.asList(concepts)); 39 | } 40 | 41 | @NotNull public PatchModelRequest plus(@NotNull Collection concepts) { 42 | this.concepts.addAll(concepts); 43 | return this; 44 | } 45 | 46 | @NotNull public PatchModelRequest withLanguage(@NotNull String language) { 47 | this.language = language; 48 | return this; 49 | } 50 | 51 | @NotNull @Override protected ClarifaiRequest build() { 52 | if (language != null) { 53 | return new ModifyModelRequest(client, modelID).withConcepts(action, concepts).withLanguage(language); 54 | } else { 55 | return new ModifyModelRequest(client, modelID).withConcepts(action, concepts); 56 | } 57 | } 58 | 59 | // Because this class is just a wrapper around ModifyModelRequest. 60 | @NotNull @Override protected String method() { return null; } 61 | @NotNull @Override protected String subUrl() { return null; } 62 | 63 | @NotNull @Override protected DeserializedRequest request() { 64 | throw new UnsupportedOperationException(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/RunModelEvaluationRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.internal.grpc.api.ModelVersionOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import clarifai2.api.request.ClarifaiRequest; 6 | import clarifai2.dto.model.ModelVersion; 7 | import com.google.common.util.concurrent.ListenableFuture; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | public final class RunModelEvaluationRequest extends ClarifaiRequest.Builder { 11 | @NotNull private String modelID; 12 | @NotNull private String versionID; 13 | 14 | public RunModelEvaluationRequest(@NotNull BaseClarifaiClient client, @NotNull String modelID, 15 | @NotNull String versionID) { 16 | super(client); 17 | this.modelID = modelID; 18 | this.versionID = versionID; 19 | } 20 | 21 | @NotNull @Override protected String method() { 22 | return "POST"; 23 | } 24 | 25 | @NotNull @Override protected String subUrl() { 26 | return "v2/models/" + modelID + "/versions/" + versionID + "/metrics"; 27 | } 28 | 29 | @NotNull @Override protected DeserializedRequest request() { 30 | return new DeserializedRequest() { 31 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 32 | return stub().postModelVersionMetrics( 33 | ModelVersionOuterClass.PostModelVersionMetricsRequest.newBuilder().build() 34 | ); 35 | } 36 | 37 | @NotNull @Override public ModelVersion unmarshalerGrpc(Object returnedObject) { 38 | ModelVersionOuterClass.SingleModelVersionResponse modelVersionResponse = 39 | (ModelVersionOuterClass.SingleModelVersionResponse) returnedObject; 40 | return ModelVersion.deserialize(modelVersionResponse.getModelVersion()); 41 | } 42 | }; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/api/request/model/TrainModelRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.api.request.model; 2 | 3 | import clarifai2.internal.grpc.api.ModelOuterClass; 4 | import clarifai2.internal.grpc.api.ModelVersionOuterClass; 5 | import clarifai2.api.BaseClarifaiClient; 6 | import clarifai2.api.request.ClarifaiRequest; 7 | import clarifai2.dto.model.Model; 8 | import com.google.common.util.concurrent.ListenableFuture; 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | public final class TrainModelRequest extends ClarifaiRequest.Builder> { 12 | 13 | @NotNull private final String modelID; 14 | 15 | public TrainModelRequest(@NotNull final BaseClarifaiClient helper, @NotNull String modelID) { 16 | super(helper); 17 | this.modelID = modelID; 18 | } 19 | 20 | @NotNull @Override protected String method() { 21 | return "POST"; 22 | } 23 | 24 | @NotNull @Override protected String subUrl() { 25 | return "v2/models/" + modelID + "/versions"; 26 | } 27 | 28 | @NotNull @Override protected DeserializedRequest> request() { 29 | return new DeserializedRequest>() { 30 | @NotNull @Override public ListenableFuture httpRequestGrpc() { 31 | return stub().postModelVersions(ModelVersionOuterClass.PostModelVersionsRequest.newBuilder().build()); 32 | } 33 | 34 | @NotNull @Override public Model unmarshalerGrpc(Object returnedObject) { 35 | ModelOuterClass.SingleModelResponse modelResponse = (ModelOuterClass.SingleModelResponse) returnedObject; 36 | return Model.deserialize(modelResponse.getModel(), client); 37 | } 38 | }; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/HasClarifaiID.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto; 2 | 3 | import org.jetbrains.annotations.Nullable; 4 | 5 | public interface HasClarifaiID { 6 | @Nullable String id(); 7 | } 8 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/HasClarifaiIDRequired.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | public interface HasClarifaiIDRequired extends HasClarifaiID { 6 | @NotNull @Override String id(); 7 | } 8 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/PointF.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto; 2 | 3 | import com.google.auto.value.AutoValue; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | @SuppressWarnings("NullableProblems") 7 | @AutoValue 8 | public abstract class PointF { 9 | 10 | PointF() {} // AutoValue instances only 11 | 12 | @NotNull public static PointF at(float x, float y) { 13 | return new AutoValue_PointF(x, y); 14 | } 15 | 16 | public abstract float x(); 17 | 18 | public abstract float y(); 19 | 20 | @NotNull public final PointF translated(float translateX, float translateY) { 21 | return new AutoValue_PointF(x() + translateX, y() + translateY); 22 | } 23 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/Radius.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto; 2 | 3 | import com.google.auto.value.AutoValue; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | @SuppressWarnings("NullableProblems") 7 | @AutoValue 8 | public abstract class Radius { 9 | 10 | Radius() {} // AutoValue instances only 11 | 12 | @NotNull public static Radius of(float value, @NotNull Unit unit) { 13 | return new AutoValue_Radius(value, unit); 14 | } 15 | 16 | public abstract float value(); 17 | @NotNull public abstract Unit unit(); 18 | 19 | public enum Unit { 20 | MILE("withinMiles"), 21 | KILOMETER("withinKilometers"), 22 | DEGREE("withinDegrees"), 23 | RADIAN("withinRadians"),; 24 | 25 | @NotNull private final String str; 26 | 27 | Unit(@NotNull String str) { 28 | this.str = str; 29 | } 30 | 31 | @Override public String toString() { 32 | return str; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/Rectangle.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto; 2 | 3 | import com.google.auto.value.AutoValue; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | @SuppressWarnings("NullableProblems") 7 | @AutoValue 8 | public abstract class Rectangle { 9 | 10 | Rectangle() {} // AutoValue instances only 11 | 12 | @NotNull public static Rectangle of(@NotNull PointF topLeft, @NotNull PointF bottomRight) { 13 | return new AutoValue_Rectangle(topLeft, bottomRight); 14 | } 15 | 16 | @NotNull public abstract PointF topLeft(); 17 | 18 | @NotNull public abstract PointF bottomRight(); 19 | 20 | @NotNull public final PointF topRight() { 21 | return PointF.at(right(), top()); 22 | } 23 | 24 | @NotNull public final PointF bottomLeft() { 25 | return PointF.at(left(), bottom()); 26 | } 27 | 28 | public final float width() { 29 | return Math.abs(right() - left()); 30 | } 31 | 32 | public final float height() { 33 | return Math.abs(bottom() - top()); 34 | } 35 | 36 | public final float left() { 37 | return topLeft().x(); 38 | } 39 | 40 | public final float top() { 41 | return topLeft().y(); 42 | } 43 | 44 | public final float right() { 45 | return bottomRight().x(); 46 | } 47 | 48 | public final float bottom() { 49 | return bottomRight().y(); 50 | } 51 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/input/ClarifaiFileVideo.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.input; 2 | 3 | import clarifai2.internal.grpc.api.VideoOuterClass; 4 | import clarifai2.exception.ClarifaiException; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.util.Arrays; 9 | 10 | @SuppressWarnings("NullableProblems") 11 | @AutoValue 12 | public abstract class ClarifaiFileVideo extends ClarifaiVideo { 13 | 14 | ClarifaiFileVideo() {} // AutoValue instances only 15 | 16 | @NotNull public final byte[] videoBytes() { 17 | // Return a defensive copy so that the underlying data can't be modified 18 | final byte[] bytes = bytes(); 19 | return Arrays.copyOf(bytes, bytes.length); 20 | } 21 | 22 | @SuppressWarnings("mutable") @NotNull abstract byte[] bytes(); 23 | 24 | @NotNull @Override public VideoOuterClass.Video serialize(boolean allowDuplicateUrl) { 25 | VideoOuterClass.Video video = VideoOuterClass.Video.newBuilder() 26 | .setBase64(com.google.protobuf.ByteString.copyFrom(bytes())) 27 | .build(); 28 | return video; 29 | } 30 | 31 | @NotNull public static ClarifaiFileVideo deserializeInner(VideoOuterClass.Video video) { 32 | throw new ClarifaiException( 33 | "Deserialization of file videos is not supported by the backend, so this should never occur" 34 | ); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/input/ClarifaiInputValue.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.input; 2 | 3 | public interface ClarifaiInputValue { 4 | } 5 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/input/ClarifaiInputsStatus.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.input; 2 | 3 | import clarifai2.internal.grpc.api.InputOuterClass; 4 | import com.google.auto.value.AutoValue; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | @SuppressWarnings("NullableProblems") 8 | @AutoValue 9 | public abstract class ClarifaiInputsStatus { 10 | 11 | ClarifaiInputsStatus() {} // AutoValue instances only 12 | 13 | @NotNull public abstract int processed(); 14 | 15 | @NotNull public abstract int toProcess(); 16 | 17 | @NotNull public abstract int errors(); 18 | 19 | @NotNull public abstract int processing(); 20 | 21 | @AutoValue.Builder 22 | public interface Builder { 23 | @NotNull Builder processed(int processed); 24 | @NotNull Builder toProcess(int toProcess); 25 | @NotNull Builder errors(int errors); 26 | @NotNull Builder processing(int processing); 27 | @NotNull ClarifaiInputsStatus build(); 28 | } 29 | 30 | public static ClarifaiInputsStatus deserialize(InputOuterClass.InputCount inputCount) { 31 | return new AutoValue_ClarifaiInputsStatus.Builder() 32 | .processed(inputCount.getProcessed()) 33 | .toProcess(inputCount.getToProcess()) 34 | .errors(inputCount.getErrors()) 35 | .processing(inputCount.getProcessing()) 36 | .build(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/input/ClarifaiURLVideo.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.input; 2 | 3 | import clarifai2.internal.grpc.api.VideoOuterClass; 4 | import com.google.auto.value.AutoValue; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.net.URL; 8 | 9 | @SuppressWarnings("NullableProblems") 10 | @AutoValue 11 | public abstract class ClarifaiURLVideo extends ClarifaiVideo { 12 | 13 | @NotNull public abstract URL url(); 14 | 15 | @NotNull @Override public VideoOuterClass.Video serialize(boolean allowDuplicateUrl) { 16 | VideoOuterClass.Video video = VideoOuterClass.Video.newBuilder() 17 | .setUrl(url().toString()) 18 | .setAllowDuplicateUrl(allowDuplicateUrl) 19 | .build(); 20 | return video; 21 | } 22 | 23 | @NotNull public static ClarifaiURLVideo deserializeInner(VideoOuterClass.Video videoResponse) { 24 | ClarifaiURLVideo video = ClarifaiURLVideo.of(videoResponse.getUrl()); 25 | return video; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/input/ClarifaiVideo.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.input; 2 | 3 | import clarifai2.internal.grpc.api.VideoOuterClass; 4 | import clarifai2.exception.ClarifaiException; 5 | import clarifai2.internal.InternalUtil; 6 | import org.jetbrains.annotations.NotNull; 7 | import org.jetbrains.annotations.Nullable; 8 | 9 | import java.io.File; 10 | import java.net.MalformedURLException; 11 | import java.net.URL; 12 | 13 | @SuppressWarnings("NullableProblems") 14 | public abstract class ClarifaiVideo implements ClarifaiInputValue { 15 | 16 | @Nullable public Crop crop() { 17 | throw new ClarifaiException("The `crop` method is not used/supported by ClarifaiVideo."); 18 | } 19 | 20 | @NotNull public ClarifaiImage withCrop(@NotNull Crop crop) { 21 | throw new ClarifaiException("The `withCrop` method is not used/supported by ClarifaiVideo."); 22 | } 23 | 24 | @NotNull public static ClarifaiURLVideo of(@NotNull URL videoURL) { 25 | return new AutoValue_ClarifaiURLVideo(videoURL); 26 | } 27 | 28 | @NotNull public static ClarifaiURLVideo of(@NotNull String videoURL) { 29 | final URL result; 30 | try { 31 | result = new URL(videoURL); 32 | } catch (MalformedURLException e) { 33 | throw new ClarifaiException("Could not parse URL " + videoURL, e); 34 | } 35 | return of(result); 36 | } 37 | 38 | @NotNull public static ClarifaiFileVideo of(@NotNull byte[] videoBytes) { 39 | return new AutoValue_ClarifaiFileVideo(videoBytes); 40 | } 41 | 42 | @NotNull public static ClarifaiFileVideo of(@NotNull File videoFile) { 43 | return of(InternalUtil.read(videoFile)); 44 | } 45 | 46 | public static ClarifaiVideo deserialize(VideoOuterClass.Video video) { 47 | return !video.getUrl().equals("") ? 48 | ClarifaiURLVideo.deserializeInner(video) : 49 | ClarifaiFileVideo.deserializeInner(video); 50 | } 51 | 52 | @NotNull public abstract VideoOuterClass.Video serialize(boolean allowDuplicateURLs); 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/input/Crop.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.input; 2 | 3 | import clarifai2.internal.grpc.api.DataOuterClass; 4 | import com.google.auto.value.AutoValue; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.util.List; 8 | 9 | @SuppressWarnings("NullableProblems") 10 | @AutoValue 11 | public abstract class Crop { 12 | 13 | Crop() {} // AutoValue instances only 14 | 15 | @NotNull public static Crop create() { 16 | return new AutoValue_Crop(0.0F, 0.0F, 1.0F, 1.0F); 17 | } 18 | 19 | @NotNull public abstract float top(); 20 | 21 | @NotNull public abstract float left(); 22 | 23 | @NotNull public abstract float bottom(); 24 | 25 | @NotNull public abstract float right(); 26 | 27 | @NotNull public final Crop top(@NotNull float top) { 28 | return withTop(top); 29 | } 30 | 31 | @NotNull public final Crop left(@NotNull float left) { 32 | return withLeft(left); 33 | } 34 | 35 | @NotNull public final Crop bottom(@NotNull float bottom) { 36 | return withBottom(bottom); 37 | } 38 | 39 | @NotNull public final Crop right(@NotNull float right) { 40 | return withRight(right); 41 | } 42 | 43 | // These are not great method names, so we'll alias them above 44 | @NotNull abstract Crop withTop(@NotNull float top); 45 | 46 | @NotNull abstract Crop withLeft(@NotNull float left); 47 | 48 | @NotNull abstract Crop withBottom(@NotNull float bottom); 49 | 50 | @NotNull abstract Crop withRight(@NotNull float right); 51 | 52 | @NotNull public static Crop deserialize(List cropList) { 53 | return new AutoValue_Crop( 54 | cropList.get(0), 55 | cropList.get(1), 56 | cropList.get(2), 57 | cropList.get(3) 58 | ); 59 | } 60 | 61 | @NotNull public static Crop deserialize(DataOuterClass.BoundingBox boundingBox) { 62 | return new AutoValue_Crop( 63 | boundingBox.getTopRow(), 64 | boundingBox.getLeftCol(), 65 | boundingBox.getBottomRow(), 66 | boundingBox.getRightCol() 67 | ); 68 | } 69 | 70 | public DataOuterClass.BoundingBox serializeBoundingBox() { 71 | return DataOuterClass.BoundingBox.newBuilder() 72 | .setTopRow(top()) 73 | .setLeftCol(left()) 74 | .setBottomRow(bottom()) 75 | .setRightCol(right()) 76 | .build(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/input/SearchHit.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.input; 2 | 3 | import clarifai2.internal.grpc.api.Search; 4 | import com.google.auto.value.AutoValue; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | @SuppressWarnings("NullableProblems") 8 | @AutoValue 9 | public abstract class SearchHit { 10 | 11 | SearchHit() {} // AutoValue instances only 12 | 13 | @NotNull public abstract float score(); 14 | 15 | @NotNull public abstract ClarifaiInput input(); 16 | 17 | 18 | public static SearchHit deserialize(Search.Hit hit) { 19 | return new AutoValue_SearchHit( 20 | hit.getScore(), 21 | ClarifaiInput.deserialize(hit.getInput()) 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/ClusterModel.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model; 2 | 3 | import clarifai2.dto.model.output_info.ClusterOutputInfo; 4 | import clarifai2.dto.prediction.Cluster; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | @SuppressWarnings("NullableProblems") 9 | @AutoValue 10 | public abstract class ClusterModel extends Model { 11 | 12 | ClusterModel() {} // AutoValue instances only 13 | 14 | @NotNull @Override public final ModelType modelType() { return modelTypeStatic(); } 15 | public static ModelType modelTypeStatic() { return ModelType.CLUSTER; } 16 | 17 | @SuppressWarnings("ConstantConditions") 18 | @NotNull 19 | @Override 20 | public final ClusterOutputInfo outputInfo() { 21 | return (ClusterOutputInfo) super.outputInfo(); 22 | } 23 | 24 | @AutoValue.Builder 25 | public interface Builder extends Model.Builder { 26 | @NotNull @Override ClusterModel build(); 27 | } 28 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/ColorModel.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model; 2 | 3 | import clarifai2.dto.model.output_info.ColorOutputInfo; 4 | import clarifai2.dto.prediction.Color; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | @SuppressWarnings("NullableProblems") 9 | @AutoValue 10 | public abstract class ColorModel extends Model { 11 | 12 | ColorModel() {} // AutoValue instances only 13 | 14 | @NotNull @Override public final ModelType modelType() { return modelTypeStatic(); } 15 | public static ModelType modelTypeStatic() { return ModelType.COLOR; } 16 | 17 | @SuppressWarnings("ConstantConditions") 18 | @NotNull 19 | @Override 20 | public final ColorOutputInfo outputInfo() { 21 | return (ColorOutputInfo) super.outputInfo(); 22 | } 23 | 24 | @AutoValue.Builder 25 | public interface Builder extends Model.Builder { 26 | @NotNull @Override ColorModel build(); 27 | } 28 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/ConceptModel.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model; 2 | 3 | import clarifai2.api.ClarifaiClient; 4 | import clarifai2.api.request.model.ModifyModelRequest; 5 | import clarifai2.api.request.model.PatchModelRequest; 6 | import clarifai2.dto.model.output_info.ConceptOutputInfo; 7 | import clarifai2.dto.prediction.Concept; 8 | import com.google.auto.value.AutoValue; 9 | import org.jetbrains.annotations.NotNull; 10 | 11 | @SuppressWarnings("NullableProblems") 12 | @AutoValue 13 | public abstract class ConceptModel extends Model { 14 | 15 | ConceptModel() {} // AutoValue instances only 16 | 17 | /** 18 | * @see ClarifaiClient#mergeConceptsForModel(String) 19 | * @deprecated use {@link #modify()} 20 | */ 21 | @Deprecated 22 | @NotNull 23 | public final PatchModelRequest mergeConcepts() { 24 | return client().mergeConceptsForModel(id()); 25 | } 26 | 27 | /** 28 | * @see ClarifaiClient#setConceptsForModel(String) 29 | * @deprecated use {@link #modify()} 30 | */ 31 | @Deprecated 32 | @NotNull 33 | public final PatchModelRequest setConcepts() { 34 | return client().setConceptsForModel(id()); 35 | } 36 | 37 | /** 38 | * @see ClarifaiClient#removeConceptsForModel(String) 39 | * @deprecated use {@link #modify()} 40 | */ 41 | @Deprecated 42 | @NotNull 43 | public final PatchModelRequest removeConcepts() { 44 | return client().removeConceptsForModel(id()); 45 | } 46 | 47 | @NotNull public final ModifyModelRequest modify() { 48 | return client().modifyModel(id()); 49 | } 50 | 51 | @NotNull @Override public final ModelType modelType() { return modelTypeStatic(); } 52 | public static ModelType modelTypeStatic() { return ModelType.CONCEPT; } 53 | 54 | @SuppressWarnings("ConstantConditions") 55 | @NotNull 56 | @Override 57 | public final ConceptOutputInfo outputInfo() { 58 | return (ConceptOutputInfo) super.outputInfo(); 59 | } 60 | 61 | @AutoValue.Builder 62 | public interface Builder extends Model.Builder { 63 | @NotNull @Override ConceptModel build(); 64 | } 65 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/DetectionModel.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model; 2 | 3 | import clarifai2.dto.model.output_info.DetectionOutputInfo; 4 | import clarifai2.dto.prediction.Detection; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | @SuppressWarnings("NullableProblems") 9 | @AutoValue 10 | public abstract class DetectionModel extends Model { 11 | DetectionModel() {} 12 | 13 | @NotNull @Override public final ModelType modelType() { return modelTypeStatic(); } 14 | public static ModelType modelTypeStatic() { return ModelType.DETECT_CONCEPT; } 15 | 16 | @SuppressWarnings("ConstantConditions") 17 | @NotNull 18 | @Override 19 | public final DetectionOutputInfo outputInfo() { 20 | return (DetectionOutputInfo) super.outputInfo(); 21 | } 22 | 23 | @AutoValue.Builder 24 | public interface Builder extends Model.Builder { 25 | @NotNull @Override DetectionModel build(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/EmbeddingModel.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model; 2 | 3 | import clarifai2.dto.model.output_info.EmbeddingOutputInfo; 4 | import clarifai2.dto.prediction.Embedding; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | @SuppressWarnings("NullableProblems") 9 | @AutoValue 10 | public abstract class EmbeddingModel extends Model { 11 | 12 | EmbeddingModel() {} // AutoValue instances only 13 | 14 | @NotNull @Override public final ModelType modelType() { return modelTypeStatic(); } 15 | public static ModelType modelTypeStatic() { return ModelType.EMBEDDING; } 16 | 17 | @SuppressWarnings("ConstantConditions") 18 | @NotNull 19 | @Override 20 | public final EmbeddingOutputInfo outputInfo() { 21 | return (EmbeddingOutputInfo) super.outputInfo(); 22 | } 23 | 24 | @AutoValue.Builder 25 | public interface Builder extends Model.Builder { 26 | @NotNull @Override EmbeddingModel build(); 27 | } 28 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/FaceEmbeddingModel.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model; 2 | 3 | import clarifai2.dto.model.output_info.FaceEmbeddingOutputInfo; 4 | import clarifai2.dto.prediction.FaceEmbedding; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | @SuppressWarnings("NullableProblems") 9 | @AutoValue 10 | public abstract class FaceEmbeddingModel extends Model { 11 | 12 | FaceEmbeddingModel() {} // AutoValue instances only 13 | 14 | @NotNull @Override public final ModelType modelType() { return modelTypeStatic(); } 15 | public static ModelType modelTypeStatic() { return ModelType.FACE_EMBEDDING; } 16 | 17 | @SuppressWarnings("ConstantConditions") 18 | @NotNull 19 | @Override 20 | public final FaceEmbeddingOutputInfo outputInfo() { 21 | return (FaceEmbeddingOutputInfo) super.outputInfo(); 22 | } 23 | 24 | @AutoValue.Builder 25 | public interface Builder extends Model.Builder { 26 | @NotNull @Override FaceEmbeddingModel build(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/StatusCode.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model; 2 | 3 | public enum StatusCode { 4 | /** 5 | * API key has insufficient scope.s 6 | */ 7 | INSUFFICIENT_SCOPES(11007); 8 | 9 | private final int statusCode; 10 | 11 | StatusCode(int statusCode) { 12 | this.statusCode = statusCode; 13 | } 14 | 15 | /** 16 | * Returns the numeric value of the status enum. 17 | * @return numeric value 18 | */ 19 | public int getValue() { 20 | return this.statusCode; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/UnknownModel.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model; 2 | 3 | 4 | import clarifai2.dto.model.output_info.UnknownOutputInfo; 5 | import clarifai2.dto.prediction.Unknown; 6 | import com.google.auto.value.AutoValue; 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | @SuppressWarnings("NullableProblems") 10 | @AutoValue 11 | public abstract class UnknownModel extends Model { 12 | 13 | UnknownModel() {} // AutoValue instances only 14 | 15 | @NotNull @Override public final ModelType modelType() { return ModelType.UNKNOWN; } 16 | 17 | @SuppressWarnings("ConstantConditions") 18 | @NotNull 19 | @Override 20 | public final UnknownOutputInfo outputInfo() { 21 | return (UnknownOutputInfo) super.outputInfo(); 22 | } 23 | 24 | @AutoValue.Builder 25 | public interface Builder extends Model.Builder { 26 | @NotNull @Override UnknownModel build(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/VideoModel.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model; 2 | 3 | import clarifai2.dto.model.output_info.VideoOutputInfo; 4 | import clarifai2.dto.prediction.Frame; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | @SuppressWarnings("NullableProblems") 9 | @AutoValue 10 | public abstract class VideoModel extends Model { 11 | 12 | VideoModel() {} // AutoValue instances only 13 | 14 | @NotNull @Override public final ModelType modelType() { return modelTypeStatic(); } 15 | public static ModelType modelTypeStatic() { return ModelType.VIDEO; } 16 | 17 | @SuppressWarnings("ConstantConditions") 18 | @NotNull 19 | @Override 20 | public final VideoOutputInfo outputInfo() { 21 | return (VideoOutputInfo) super.outputInfo(); 22 | } 23 | 24 | @AutoValue.Builder 25 | public interface Builder extends Model.Builder { 26 | @NotNull @Override VideoModel build(); 27 | } 28 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/output_info/BlurOutputInfo.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model.output_info; 2 | 3 | import clarifai2.internal.grpc.api.ModelOuterClass; 4 | import clarifai2.exception.ClarifaiException; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | @SuppressWarnings("NullableProblems") 9 | @AutoValue 10 | public abstract class BlurOutputInfo extends OutputInfo { 11 | 12 | BlurOutputInfo() {} // AutoValue instances only 13 | 14 | @Override @NotNull public ModelOuterClass.OutputInfo serialize() { 15 | throw new ClarifaiException(this.getClass().getSimpleName() + " is not serializable"); 16 | } 17 | 18 | @NotNull public static BlurOutputInfo deserializeInner(ModelOuterClass.OutputInfo outputInfo) { 19 | return new AutoValue_BlurOutputInfo(); 20 | } 21 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/output_info/ClusterOutputInfo.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model.output_info; 2 | 3 | import clarifai2.internal.grpc.api.ModelOuterClass; 4 | import clarifai2.exception.ClarifaiException; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | @SuppressWarnings("NullableProblems") 9 | @AutoValue 10 | public abstract class ClusterOutputInfo extends OutputInfo { 11 | 12 | ClusterOutputInfo() {} // AutoValue instances only 13 | 14 | @Override @NotNull public ModelOuterClass.OutputInfo serialize() { 15 | throw new ClarifaiException(this.getClass().getSimpleName() + " is not serializable"); 16 | } 17 | 18 | @NotNull public static ClusterOutputInfo deserializeInner(ModelOuterClass.OutputInfo outputInfo) { 19 | return new AutoValue_ClusterOutputInfo(); 20 | } 21 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/output_info/ColorOutputInfo.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model.output_info; 2 | 3 | import clarifai2.internal.grpc.api.ConceptOuterClass; 4 | import clarifai2.internal.grpc.api.ModelOuterClass; 5 | import clarifai2.dto.prediction.Concept; 6 | import clarifai2.exception.ClarifaiException; 7 | import com.google.auto.value.AutoValue; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | @SuppressWarnings("NullableProblems") 14 | @AutoValue 15 | public abstract class ColorOutputInfo extends OutputInfo { 16 | 17 | ColorOutputInfo() {} // AutoValue instances only 18 | 19 | @NotNull public abstract String type(); 20 | 21 | @NotNull public abstract String typeExt(); 22 | 23 | @NotNull public abstract List concepts(); 24 | 25 | @Override @NotNull public ModelOuterClass.OutputInfo serialize() { 26 | throw new ClarifaiException(this.getClass().getSimpleName() + " is not serializable"); 27 | } 28 | 29 | @NotNull public static ColorOutputInfo deserializeInner(ModelOuterClass.OutputInfo outputInfo) { 30 | List concepts = new ArrayList<>(); 31 | for (ConceptOuterClass.Concept concept : outputInfo.getData().getConceptsList()) { 32 | concepts.add(Concept.deserialize(concept)); 33 | } 34 | return new AutoValue_ColorOutputInfo(outputInfo.getType(), outputInfo.getTypeExt(), concepts); 35 | } 36 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/output_info/DetectionOutputInfo.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model.output_info; 2 | 3 | import clarifai2.internal.grpc.api.ConceptOuterClass; 4 | import clarifai2.internal.grpc.api.ModelOuterClass; 5 | import clarifai2.dto.prediction.Concept; 6 | import clarifai2.exception.ClarifaiException; 7 | import com.google.auto.value.AutoValue; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.jetbrains.annotations.Nullable; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | @SuppressWarnings("NullableProblems") 15 | @AutoValue 16 | public abstract class DetectionOutputInfo extends OutputInfo { 17 | 18 | DetectionOutputInfo() {} // AutoValue instances only 19 | 20 | @NotNull public abstract String type(); 21 | 22 | @NotNull public abstract String typeExt(); 23 | 24 | @Nullable public abstract List concepts(); 25 | 26 | @Override @NotNull public ModelOuterClass.OutputInfo serialize() { 27 | throw new ClarifaiException(this.getClass().getSimpleName() + " is not serializable"); 28 | } 29 | 30 | @NotNull public static DetectionOutputInfo deserializeInner(ModelOuterClass.OutputInfo outputInfo) { 31 | List concepts = new ArrayList<>(); 32 | for (ConceptOuterClass.Concept concept : outputInfo.getData().getConceptsList()) { 33 | concepts.add(Concept.deserialize(concept)); 34 | } 35 | return new AutoValue_DetectionOutputInfo(outputInfo.getType(), outputInfo.getTypeExt(), concepts); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/output_info/EmbeddingOutputInfo.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model.output_info; 2 | 3 | import clarifai2.internal.grpc.api.ModelOuterClass; 4 | import clarifai2.exception.ClarifaiException; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | @SuppressWarnings("NullableProblems") 9 | @AutoValue 10 | public abstract class EmbeddingOutputInfo extends OutputInfo { 11 | 12 | EmbeddingOutputInfo() {} // AutoValue instances only 13 | 14 | @NotNull public abstract String type(); 15 | 16 | @NotNull public abstract String typeExt(); 17 | 18 | @Override @NotNull public ModelOuterClass.OutputInfo serialize() { 19 | throw new ClarifaiException(this.getClass().getSimpleName() + " is not serializable"); 20 | } 21 | 22 | @NotNull public static EmbeddingOutputInfo deserializeInner(ModelOuterClass.OutputInfo outputInfo) { 23 | return new AutoValue_EmbeddingOutputInfo(outputInfo.getType(), outputInfo.getTypeExt()); 24 | } 25 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/output_info/FaceEmbeddingOutputInfo.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model.output_info; 2 | 3 | import clarifai2.internal.grpc.api.ModelOuterClass; 4 | import clarifai2.exception.ClarifaiException; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | @SuppressWarnings("NullableProblems") 9 | @AutoValue 10 | public abstract class FaceEmbeddingOutputInfo extends OutputInfo { 11 | 12 | FaceEmbeddingOutputInfo() {} // AutoValue instances only 13 | 14 | @NotNull public abstract String type(); 15 | 16 | @NotNull public abstract String typeExt(); 17 | 18 | @Override @NotNull public ModelOuterClass.OutputInfo serialize() { 19 | throw new ClarifaiException(this.getClass().getSimpleName() + " is not serializable"); 20 | } 21 | 22 | @NotNull public static FaceEmbeddingOutputInfo deserializeInner(ModelOuterClass.OutputInfo outputInfo) { 23 | return new AutoValue_FaceEmbeddingOutputInfo(outputInfo.getType(), outputInfo.getTypeExt()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/output_info/UnknownOutputInfo.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model.output_info; 2 | 3 | import clarifai2.internal.grpc.api.ModelOuterClass; 4 | import clarifai2.exception.ClarifaiException; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | @SuppressWarnings("NullableProblems") 9 | @AutoValue 10 | public abstract class UnknownOutputInfo extends OutputInfo { 11 | 12 | UnknownOutputInfo() {} // AutoValue instances only 13 | 14 | @Override @NotNull public ModelOuterClass.OutputInfo serialize() { 15 | throw new ClarifaiException(this.getClass().getSimpleName() + " is not serializable"); 16 | } 17 | 18 | @NotNull public static UnknownOutputInfo deserializeInner(ModelOuterClass.OutputInfo outputInfo) { 19 | return new AutoValue_UnknownOutputInfo(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/model/output_info/VideoOutputInfo.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.model.output_info; 2 | 3 | import clarifai2.internal.grpc.api.ModelOuterClass; 4 | import clarifai2.exception.ClarifaiException; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | @SuppressWarnings("NullableProblems") 9 | @AutoValue 10 | public abstract class VideoOutputInfo extends OutputInfo { 11 | 12 | VideoOutputInfo() {} // AutoValue instances only 13 | 14 | @NotNull public abstract String type(); 15 | 16 | @NotNull public abstract String typeExt(); 17 | 18 | @Override @NotNull public ModelOuterClass.OutputInfo serialize() { 19 | throw new ClarifaiException(this.getClass().getSimpleName() + " is not serializable"); 20 | } 21 | 22 | @NotNull public static VideoOutputInfo deserializeInner(ModelOuterClass.OutputInfo outputInfo) { 23 | return new AutoValue_VideoOutputInfo(outputInfo.getType(), outputInfo.getTypeExt()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/prediction/Blur.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.prediction; 2 | 3 | import com.google.auto.value.AutoValue; 4 | 5 | @SuppressWarnings("NullableProblems") 6 | @AutoValue 7 | public abstract class Blur extends Prediction { 8 | 9 | Blur() {} // AutoValue instances only 10 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/prediction/Cluster.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.prediction; 2 | 3 | import clarifai2.dto.HasClarifaiIDRequired; 4 | import com.google.auto.value.AutoValue; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | @SuppressWarnings("NullableProblems") 8 | @AutoValue 9 | public abstract class Cluster extends Prediction implements HasClarifaiIDRequired { 10 | 11 | Cluster() {} // AutoValue instances only 12 | 13 | @NotNull public abstract int numClusters(); 14 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/prediction/Color.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.prediction; 2 | 3 | import clarifai2.internal.grpc.api.ColorOuterClass; 4 | import com.google.auto.value.AutoValue; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | @SuppressWarnings("NullableProblems") 8 | @AutoValue 9 | public abstract class Color extends Prediction { 10 | 11 | Color() {} // AutoValue instances only 12 | 13 | @NotNull public abstract String hex(); 14 | 15 | @NotNull public abstract String webSafeHex(); 16 | 17 | @NotNull public abstract String webSafeColorName(); 18 | 19 | @NotNull public abstract float value(); 20 | 21 | 22 | @NotNull public static Color deserialize(ColorOuterClass.Color color) { 23 | return new AutoValue_Color( 24 | color.getRawHex(), 25 | color.getW3C().getHex(), 26 | color.getW3C().getName(), 27 | color.getValue() 28 | ); 29 | } 30 | } -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/prediction/Detection.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.prediction; 2 | 3 | import clarifai2.internal.grpc.api.ConceptOuterClass; 4 | import clarifai2.internal.grpc.api.DataOuterClass; 5 | import clarifai2.dto.input.Crop; 6 | import clarifai2.internal.grpc.api.FaceOuterClass; 7 | import com.google.auto.value.AutoValue; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | @SuppressWarnings("NullableProblems") 14 | @AutoValue 15 | public abstract class Detection extends Prediction { 16 | 17 | Detection() {} // AutoValue instances only 18 | 19 | @NotNull public abstract Crop crop(); 20 | 21 | @NotNull public abstract List concepts(); 22 | 23 | @NotNull public abstract List ageAppearances(); 24 | 25 | @NotNull public abstract List genderAppearances(); 26 | 27 | @NotNull public abstract List multiculturalAppearances(); 28 | 29 | 30 | @NotNull public static Detection deserialize(DataOuterClass.Region detection) { 31 | Crop crop = Crop.deserialize(detection.getRegionInfo().getBoundingBox()); 32 | 33 | List concepts = new ArrayList<>(); 34 | for (ConceptOuterClass.Concept concept : detection.getData().getConceptsList()) { 35 | concepts.add(Concept.deserialize(concept)); 36 | } 37 | 38 | List ageAppearanceConcepts = new ArrayList<>(); 39 | List genderAppearanceConcepts = new ArrayList<>(); 40 | List multiculturalAppearanceConcepts = new ArrayList<>(); 41 | 42 | FaceOuterClass.Face face = detection.getData().getFace(); 43 | if (face != null) { 44 | for (ConceptOuterClass.Concept concept : face.getAgeAppearance().getConceptsList()) { 45 | ageAppearanceConcepts.add(Concept.deserialize(concept)); 46 | } 47 | for (ConceptOuterClass.Concept concept : face.getGenderAppearance().getConceptsList()) { 48 | genderAppearanceConcepts.add(Concept.deserialize(concept)); 49 | } 50 | for (ConceptOuterClass.Concept concept : face.getMulticulturalAppearance().getConceptsList()) { 51 | multiculturalAppearanceConcepts.add(Concept.deserialize(concept)); 52 | } 53 | } 54 | 55 | return new AutoValue_Detection( 56 | crop, concepts, ageAppearanceConcepts, genderAppearanceConcepts, multiculturalAppearanceConcepts 57 | ); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/prediction/Embedding.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.prediction; 2 | 3 | import clarifai2.internal.grpc.api.EmbeddingOuterClass; 4 | import com.google.auto.value.AutoValue; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | @SuppressWarnings("NullableProblems") 11 | @AutoValue 12 | public abstract class Embedding extends Prediction { 13 | 14 | Embedding() {} // AutoValue instances only 15 | 16 | @NotNull public final float[] embedding() { 17 | // Return a defensive copy so that they can't modify the original byte-array 18 | final float[] embedding = _embedding(); 19 | return Arrays.copyOf(embedding, embedding.length); 20 | } 21 | 22 | @SuppressWarnings("PMD.MethodNamingConventions") 23 | @NotNull abstract float[] _embedding(); 24 | 25 | @NotNull public abstract int numDimensions(); 26 | 27 | 28 | @NotNull public static Embedding deserialize(EmbeddingOuterClass.Embedding embeddingResponse) { 29 | List vectorList = embeddingResponse.getVectorList(); 30 | float[] embedding = new float[vectorList.size()]; 31 | for (int i = 0; i < vectorList.size(); i++) { 32 | embedding[i] = vectorList.get(i); 33 | } 34 | return new AutoValue_Embedding( 35 | embedding, 36 | embeddingResponse.getNumDimensions() 37 | ); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/prediction/FaceEmbedding.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.prediction; 2 | 3 | import clarifai2.internal.grpc.api.DataOuterClass; 4 | import clarifai2.internal.grpc.api.EmbeddingOuterClass; 5 | import clarifai2.dto.input.Crop; 6 | import com.google.auto.value.AutoValue; 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | @SuppressWarnings("NullableProblems") 13 | @AutoValue 14 | public abstract class FaceEmbedding extends Prediction { 15 | 16 | FaceEmbedding() {} // AutoValue instances only 17 | 18 | @NotNull public abstract Crop crop(); 19 | 20 | @NotNull public abstract List embeddings(); 21 | 22 | 23 | @NotNull public static FaceEmbedding deserialize(DataOuterClass.Region region) { 24 | List embeddings = new ArrayList<>(); 25 | for (EmbeddingOuterClass.Embedding embedding : region.getData().getEmbeddingsList()) { 26 | embeddings.add(Embedding.deserialize(embedding)); 27 | } 28 | return new AutoValue_FaceEmbedding(Crop.deserialize(region.getRegionInfo().getBoundingBox()), embeddings); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/prediction/Frame.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.prediction; 2 | 3 | import clarifai2.internal.grpc.api.ConceptOuterClass; 4 | import clarifai2.internal.grpc.api.DataOuterClass; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | @SuppressWarnings("NullableProblems") 12 | @AutoValue 13 | public abstract class Frame extends Prediction { 14 | 15 | Frame() {} // AutoValue instances only 16 | 17 | public abstract int index(); 18 | 19 | public abstract long time(); 20 | 21 | @NotNull public abstract List concepts(); 22 | 23 | 24 | @NotNull public static Frame deserialize(DataOuterClass.Frame frame) { 25 | List concepts = new ArrayList<>(); 26 | for (ConceptOuterClass.Concept concept : frame.getData().getConceptsList()) { 27 | concepts.add(Concept.deserialize(concept)); 28 | } 29 | return new AutoValue_Frame( 30 | frame.getFrameInfo().getIndex(), 31 | frame.getFrameInfo().getTime(), 32 | concepts 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/prediction/Prediction.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.prediction; 2 | 3 | import org.jetbrains.annotations.NotNull; 4 | 5 | public abstract class Prediction { 6 | Prediction() {} 7 | 8 | public final boolean isConcept() { 9 | return this instanceof Concept; 10 | } 11 | 12 | @NotNull public final Concept asConcept() { 13 | return (Concept) this; 14 | } 15 | 16 | public final boolean isColor() { 17 | return this instanceof Color; 18 | } 19 | 20 | @NotNull public final Color asColor() { 21 | return (Color) this; 22 | } 23 | 24 | @NotNull public final FaceEmbedding asFaceEmbedding() { 25 | return (FaceEmbedding) this; 26 | } 27 | 28 | @NotNull public final Detection asDetection() { 29 | return (Detection) this; 30 | } 31 | 32 | public final boolean isBlur() { 33 | return this instanceof Blur; 34 | } 35 | 36 | @NotNull public final Blur asBlur() { 37 | return (Blur) this; 38 | } 39 | 40 | public final boolean isEmbedding() { 41 | return this instanceof Embedding; 42 | } 43 | 44 | @NotNull public final Embedding asEmbedding() { 45 | return (Embedding) this; 46 | } 47 | 48 | public final boolean isCluster() { 49 | return this instanceof Cluster; 50 | } 51 | 52 | @NotNull public final Cluster asCluster() { 53 | return (Cluster) this; 54 | } 55 | 56 | @NotNull public final Region asRegion() { 57 | return (Region) this; 58 | } 59 | 60 | public final boolean isFrame() { 61 | return this instanceof Frame; 62 | } 63 | 64 | @NotNull public final Frame asFrame() { 65 | return (Frame) this; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/prediction/Region.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.prediction; 2 | 3 | import clarifai2.internal.grpc.api.ConceptOuterClass; 4 | import clarifai2.internal.grpc.api.DataOuterClass; 5 | import clarifai2.internal.grpc.api.FaceOuterClass; 6 | import clarifai2.dto.input.Crop; 7 | import com.google.auto.value.AutoValue; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | @SuppressWarnings("NullableProblems") 14 | @AutoValue 15 | public abstract class Region extends Prediction { 16 | 17 | Region() {} // AutoValue instances only 18 | 19 | @NotNull public abstract String id(); 20 | 21 | @NotNull public abstract Crop crop(); 22 | 23 | @NotNull public abstract List ageAppearances(); 24 | 25 | @NotNull public abstract List genderAppearances(); 26 | 27 | @NotNull public abstract List multiculturalAppearances(); 28 | 29 | 30 | // Unfortunately, the demographics model returns a list of Region instances instead of Demographics instances. 31 | // In order to remain backwards compatible we cannot change that return type. So we are forced to have this 32 | // demographics deserialization here instead of in Demographics. 33 | @NotNull public static Region deserialize(DataOuterClass.Region region) { 34 | FaceOuterClass.Face face = region.getData().getFace(); 35 | List ageAppearanceConcepts = new ArrayList<>(); 36 | for (ConceptOuterClass.Concept concept : face.getAgeAppearance().getConceptsList()) { 37 | ageAppearanceConcepts.add(Concept.deserialize(concept)); 38 | } 39 | List genderAppearanceConcepts = new ArrayList<>(); 40 | for (ConceptOuterClass.Concept concept : face.getGenderAppearance().getConceptsList()) { 41 | genderAppearanceConcepts.add(Concept.deserialize(concept)); 42 | } 43 | List multiculturalAppearanceConcepts = new ArrayList<>(); 44 | for (ConceptOuterClass.Concept concept : face.getMulticulturalAppearance().getConceptsList()) { 45 | multiculturalAppearanceConcepts.add(Concept.deserialize(concept)); 46 | } 47 | return new AutoValue_Region( 48 | region.getId(), 49 | Crop.deserialize(region.getRegionInfo().getBoundingBox()), 50 | ageAppearanceConcepts, 51 | genderAppearanceConcepts, 52 | multiculturalAppearanceConcepts 53 | ); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/prediction/Unknown.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.prediction; 2 | 3 | import com.google.auto.value.AutoValue; 4 | 5 | @SuppressWarnings("NullableProblems") 6 | @AutoValue 7 | public abstract class Unknown extends Prediction { 8 | 9 | Unknown() {} 10 | 11 | ; // make sure this is actually right (won't let anyone access this) 12 | } 13 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/search/SearchInputsResult.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.search; 2 | 3 | import clarifai2.internal.grpc.api.Search; 4 | import clarifai2.dto.input.SearchHit; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | @SuppressWarnings("NullableProblems") 12 | @AutoValue 13 | public abstract class SearchInputsResult { 14 | 15 | SearchInputsResult() {} // AutoValue instances only 16 | 17 | @NotNull public abstract String id(); 18 | 19 | @NotNull public abstract List searchHits(); 20 | 21 | 22 | public static SearchInputsResult deserialize(Search.MultiSearchResponse searchesResponse) { 23 | List hits = new ArrayList<>(); 24 | for (Search.Hit hit : searchesResponse.getHitsList()) { 25 | hits.add(SearchHit.deserialize(hit)); 26 | } 27 | return new AutoValue_SearchInputsResult(searchesResponse.getId(), hits); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/workflow/Workflow.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.workflow; 2 | 3 | import clarifai2.internal.grpc.api.WorkflowOuterClass; 4 | import clarifai2.grpc.DateTimeConverter; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.Nullable; 7 | 8 | import java.util.Date; 9 | 10 | @SuppressWarnings("NullableProblems") 11 | @AutoValue 12 | public abstract class Workflow { 13 | 14 | Workflow() {} // AutoValue instances only 15 | 16 | @Nullable public abstract String id(); 17 | @Nullable public abstract String appId(); 18 | @Nullable public abstract Date createdAt(); 19 | 20 | 21 | public static Workflow deserialize(WorkflowOuterClass.Workflow workflow) { 22 | return new AutoValue_Workflow( 23 | workflow.getId(), 24 | workflow.getAppId(), 25 | DateTimeConverter.timestampToDate(workflow.getCreatedAt()) 26 | ); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/workflow/WorkflowPredictResult.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.workflow; 2 | 3 | import clarifai2.internal.grpc.api.WorkflowOuterClass; 4 | import clarifai2.api.BaseClarifaiClient; 5 | import com.google.auto.value.AutoValue; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | @SuppressWarnings("NullableProblems") 12 | @AutoValue 13 | public abstract class WorkflowPredictResult { 14 | 15 | WorkflowPredictResult() {} // AutoValue instances only 16 | 17 | @NotNull public abstract Workflow workflow(); 18 | @NotNull public abstract List workflowResults(); 19 | 20 | 21 | public static WorkflowPredictResult deserialize( 22 | WorkflowOuterClass.PostWorkflowResultsResponse workflowResultsResponse, BaseClarifaiClient client 23 | ) { 24 | Workflow workflow = Workflow.deserialize(workflowResultsResponse.getWorkflow()); 25 | List predictions = new ArrayList<>(); 26 | for (WorkflowOuterClass.WorkflowResult workflowResult : workflowResultsResponse.getResultsList()) { 27 | predictions.add(WorkflowResult.deserialize(workflowResult, client)); 28 | } 29 | 30 | return new AutoValue_WorkflowPredictResult(workflow, predictions); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/dto/workflow/WorkflowResult.java: -------------------------------------------------------------------------------- 1 | package clarifai2.dto.workflow; 2 | 3 | import clarifai2.internal.grpc.api.OutputOuterClass; 4 | import clarifai2.internal.grpc.api.WorkflowOuterClass; 5 | import clarifai2.api.BaseClarifaiClient; 6 | import clarifai2.dto.ClarifaiStatus; 7 | import clarifai2.dto.input.ClarifaiInput; 8 | import clarifai2.dto.model.output.ClarifaiOutput; 9 | import clarifai2.dto.prediction.Prediction; 10 | import com.google.auto.value.AutoValue; 11 | import org.jetbrains.annotations.NotNull; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | @SuppressWarnings("NullableProblems") 17 | @AutoValue 18 | public abstract class WorkflowResult { 19 | 20 | WorkflowResult() {} // AutoValue instances only 21 | 22 | @NotNull public abstract ClarifaiStatus status(); 23 | @NotNull public abstract ClarifaiInput input(); 24 | @NotNull public abstract List> predictions(); 25 | 26 | 27 | public static WorkflowResult deserialize( 28 | WorkflowOuterClass.WorkflowResult workflowResult, BaseClarifaiClient client 29 | ) { 30 | List> predictions = new ArrayList<>(); 31 | for (OutputOuterClass.Output output : workflowResult.getOutputsList()) { 32 | predictions.add(ClarifaiOutput.deserialize(output, client)); 33 | } 34 | return new AutoValue_WorkflowResult( 35 | ClarifaiStatus.deserialize(workflowResult.getStatus()), 36 | ClarifaiInput.deserialize(workflowResult.getInput()), 37 | predictions 38 | ); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/exception/ClarifaiClientClosedException.java: -------------------------------------------------------------------------------- 1 | package clarifai2.exception; 2 | 3 | public final class ClarifaiClientClosedException extends ClarifaiException { 4 | 5 | public ClarifaiClientClosedException(String message) { 6 | super(message); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/exception/ClarifaiException.java: -------------------------------------------------------------------------------- 1 | package clarifai2.exception; 2 | 3 | public class ClarifaiException extends RuntimeException { 4 | 5 | public ClarifaiException(Throwable cause) { 6 | super(cause); 7 | } 8 | 9 | public ClarifaiException(String message) { 10 | super(message); 11 | } 12 | 13 | public ClarifaiException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/exception/DeprecationException.java: -------------------------------------------------------------------------------- 1 | package clarifai2.exception; 2 | 3 | public final class DeprecationException extends RuntimeException { 4 | 5 | public DeprecationException(String message) { 6 | super(message); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/exception/NetworkException.java: -------------------------------------------------------------------------------- 1 | package clarifai2.exception; 2 | 3 | public final class NetworkException extends RuntimeException { 4 | 5 | public NetworkException(Throwable cause) { 6 | super(cause); 7 | } 8 | 9 | public NetworkException(String message) { 10 | super(message); 11 | } 12 | 13 | public NetworkException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/grpc/ClarifaiHttpClient.java: -------------------------------------------------------------------------------- 1 | package clarifai2.grpc; 2 | 3 | import okhttp3.OkHttpClient; 4 | 5 | public interface ClarifaiHttpClient { 6 | String apiKey(); 7 | String executeRequest(String url, String method, String requestString); 8 | void client(OkHttpClient client); 9 | } 10 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/grpc/ClarifaiHttpClientImpl.java: -------------------------------------------------------------------------------- 1 | package clarifai2.grpc; 2 | 3 | import clarifai2.exception.ClarifaiException; 4 | import okhttp3.OkHttpClient; 5 | import okhttp3.Request; 6 | import okhttp3.RequestBody; 7 | import okhttp3.Response; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | import java.io.IOException; 11 | 12 | import static clarifai2.internal.InternalUtil.MEDIA_TYPE_JSON; 13 | 14 | public class ClarifaiHttpClientImpl implements ClarifaiHttpClient { 15 | private final String apiKey; 16 | private OkHttpClient okHttpClient; 17 | 18 | public ClarifaiHttpClientImpl(@NotNull String apiKey) { 19 | this.apiKey = apiKey; 20 | this.okHttpClient = new OkHttpClient(); 21 | } 22 | 23 | @Override @NotNull public String apiKey() { 24 | return this.apiKey; 25 | } 26 | 27 | @Override public void client(OkHttpClient client) { 28 | this.okHttpClient = client; 29 | } 30 | 31 | @Override @NotNull public String executeRequest(String url, String method, String requestString) { 32 | RequestBody body = null; 33 | if (!method.toUpperCase().equals("GET")) { 34 | body = RequestBody.create(MEDIA_TYPE_JSON, requestString); 35 | } 36 | 37 | // RequestBody.create(MEDIA_TYPE_JSON, requestString); 38 | Request request = new Request.Builder() 39 | .url(url) 40 | .method(method, body) 41 | .build(); 42 | 43 | String responseString; 44 | try { 45 | Response response = okHttpClient.newCall(request).execute(); 46 | responseString = response.body().string(); 47 | } catch (IOException e) { 48 | throw new ClarifaiException(e); 49 | } 50 | return responseString; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/grpc/DateTimeConverter.java: -------------------------------------------------------------------------------- 1 | package clarifai2.grpc; 2 | 3 | import com.google.protobuf.Timestamp; 4 | import com.google.protobuf.util.Timestamps; 5 | 6 | import java.util.Date; 7 | 8 | 9 | public class DateTimeConverter { 10 | public static Date timestampToDate(Timestamp timestamp) { 11 | return new Date(timestamp.getSeconds() * 1000); 12 | } 13 | 14 | public static Timestamp dateToTimestamp(Date dateTime) { 15 | // return Timestamps.fromMillis(dateTime.getTime()) 16 | return Timestamp.newBuilder() 17 | .setSeconds(dateTime.getTime()) 18 | .build(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/grpc/FkClarifaiHttpClient.java: -------------------------------------------------------------------------------- 1 | package clarifai2.grpc; 2 | 3 | import okhttp3.OkHttpClient; 4 | import org.jetbrains.annotations.NotNull; 5 | 6 | public class FkClarifaiHttpClient implements ClarifaiHttpClient { 7 | private final String response; 8 | private String requestUrl; 9 | private String requestMethod; 10 | private String requestBody; 11 | 12 | public FkClarifaiHttpClient(String response) { 13 | this.response = response; 14 | } 15 | 16 | @NotNull public String requestUrl() { 17 | return requestUrl; 18 | } 19 | 20 | @NotNull public String requestMethod() { 21 | return requestMethod; 22 | } 23 | 24 | @NotNull public String requestBody() { 25 | return requestBody; 26 | } 27 | 28 | @Override public String apiKey() { 29 | return "FAKE-API-KEY"; 30 | } 31 | 32 | @Override public void client(OkHttpClient client) { 33 | } 34 | 35 | @Override @NotNull public String executeRequest(String url, String method, String body) { 36 | requestUrl = url; 37 | requestMethod = method; 38 | requestBody = body; 39 | return response; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/internal/AutoValueTypeAdapterFactory.java: -------------------------------------------------------------------------------- 1 | package clarifai2.internal; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.TypeAdapter; 5 | import com.google.gson.TypeAdapterFactory; 6 | import com.google.gson.annotations.JsonAdapter; 7 | import com.google.gson.reflect.TypeToken; 8 | 9 | import java.lang.reflect.Type; 10 | 11 | /** 12 | * A {@link TypeAdapterFactory} that attempts to delegate any serialization/deserialization of an AutoValue class to the 13 | * adapter that is registered for the base class. 14 | *

15 | * For example, this allows use of {@link JsonAdapter} on the base AutoValue class. Proper serialization will still 16 | * occur according to that {@link JsonAdapter} when the class is passed through Gson. Otherwise, Gson would always use 17 | * default serialization on AutoValue classes, because technically, the generated class has no custom serializer. 18 | */ 19 | public final class AutoValueTypeAdapterFactory implements TypeAdapterFactory { 20 | 21 | private static final String AUTO_VALUE_CLASS_PREFIX = "AutoValue_"; 22 | 23 | @Override public TypeAdapter create(final Gson gson, final TypeToken typeToken) { 24 | final Type type = typeToken.getType(); 25 | if (!(type instanceof Class)) { 26 | return null; 27 | } 28 | final String typeName = ((Class) type).getName(); 29 | if (!typeName.contains(AUTO_VALUE_CLASS_PREFIX)) { 30 | return null; 31 | } 32 | try { 33 | final Class nonAutoValueType = Class.forName(typeName.replace(AUTO_VALUE_CLASS_PREFIX, "")); 34 | //noinspection unchecked 35 | return ((TypeAdapter) gson.getAdapter(nonAutoValueType)); 36 | } catch (ClassNotFoundException e) { 37 | throw new IllegalStateException("Tried to get the non-AutoValue version of " + typeName, e); 38 | } 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/internal/JSONUnmarshaler.java: -------------------------------------------------------------------------------- 1 | package clarifai2.internal; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.JsonElement; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | public interface JSONUnmarshaler { 8 | @NotNull T fromJSON(@NotNull Gson gson, @NotNull JsonElement json); 9 | } 10 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/solutions/Solutions.java: -------------------------------------------------------------------------------- 1 | package clarifai2.solutions; 2 | 3 | import clarifai2.api.BaseClarifaiClient; 4 | import clarifai2.api.ClarifaiBuilder; 5 | import clarifai2.solutions.moderation.Moderation; 6 | import org.jetbrains.annotations.NotNull; 7 | 8 | public class Solutions { 9 | @NotNull private final Moderation moderation; 10 | 11 | public Solutions(@NotNull String apiKey) { 12 | this.moderation = new Moderation(apiKey); 13 | } 14 | 15 | public Moderation moderation() { 16 | return this.moderation; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/solutions/moderation/Moderation.java: -------------------------------------------------------------------------------- 1 | package clarifai2.solutions.moderation; 2 | 3 | import clarifai2.api.BaseClarifaiClient; 4 | import clarifai2.api.ClarifaiBuilder; 5 | import clarifai2.dto.prediction.Concept; 6 | import clarifai2.solutions.moderation.api.request.input.GetModerationStatusRequest; 7 | import clarifai2.solutions.moderation.api.request.model.ModerationPredictRequest; 8 | import org.jetbrains.annotations.NotNull; 9 | 10 | public class Moderation { 11 | 12 | @NotNull private final BaseClarifaiClient client; 13 | 14 | public Moderation(@NotNull String apiKey) { 15 | this.client = (BaseClarifaiClient) new ClarifaiBuilder(apiKey) 16 | .baseURL("https://api.clarifai-moderation.com") 17 | .buildSync(); 18 | } 19 | 20 | @NotNull public ModerationPredictRequest predict(@NotNull String modelID) { 21 | return new ModerationPredictRequest<>(this.client, modelID); 22 | } 23 | 24 | @NotNull public GetModerationStatusRequest getModerationStatus(@NotNull String inputID) { 25 | return new GetModerationStatusRequest(this.client, inputID); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/solutions/moderation/api/request/input/GetModerationStatusRequest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.solutions.moderation.api.request.input; 2 | 3 | import clarifai2.api.BaseClarifaiClient; 4 | import clarifai2.api.request.ClarifaiJsonRequest; 5 | import clarifai2.internal.InternalUtil; 6 | import clarifai2.internal.JSONUnmarshaler; 7 | import clarifai2.solutions.moderation.dto.ModerationStatus; 8 | import com.google.gson.Gson; 9 | import com.google.gson.JsonElement; 10 | import com.google.gson.JsonObject; 11 | import com.google.gson.reflect.TypeToken; 12 | import okhttp3.MediaType; 13 | import okhttp3.Request; 14 | import org.jetbrains.annotations.NotNull; 15 | 16 | import static clarifai2.internal.InternalUtil.assertJsonIs; 17 | 18 | public class GetModerationStatusRequest extends ClarifaiJsonRequest.Builder { 19 | @NotNull private final String inputID; 20 | 21 | public GetModerationStatusRequest(@NotNull BaseClarifaiClient client, @NotNull String inputID) { 22 | // TODO(Rok) LOW: Once backend supports the utf-8 charset header, remove this MediaType argument. 23 | super(client, MediaType.parse("application/json")); 24 | this.inputID = inputID; 25 | } 26 | 27 | @NotNull @Override protected DeserializedRequest request() { 28 | return new DeserializedRequest() { 29 | @NotNull @Override public Request httpRequest() { 30 | return getRequest("/v2/inputs/" + inputID + "/outputs"); 31 | } 32 | 33 | @NotNull @Override public JSONUnmarshaler unmarshaler() { 34 | return new JSONUnmarshaler() { 35 | @NotNull @Override 36 | public ModerationStatus fromJSON(@NotNull Gson gson, @NotNull JsonElement json) { 37 | final JsonObject root = assertJsonIs(json, JsonObject.class); 38 | return InternalUtil.fromJson( 39 | gson, 40 | root.getAsJsonObject("moderation").getAsJsonObject("status"), 41 | new TypeToken() {} 42 | ); 43 | } 44 | }; 45 | } 46 | }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /core/src/main/java/clarifai2/solutions/moderation/dto/ModerationDetail.java: -------------------------------------------------------------------------------- 1 | package clarifai2.solutions.moderation.dto; 2 | 3 | import clarifai2.dto.prediction.Concept; 4 | import clarifai2.internal.JSONAdapterFactory; 5 | import com.google.auto.value.AutoValue; 6 | import com.google.gson.Gson; 7 | import com.google.gson.JsonElement; 8 | import com.google.gson.JsonObject; 9 | import com.google.gson.annotations.JsonAdapter; 10 | import com.google.gson.reflect.TypeToken; 11 | import org.jetbrains.annotations.NotNull; 12 | import org.jetbrains.annotations.Nullable; 13 | 14 | import static clarifai2.internal.InternalUtil.assertJsonIs; 15 | 16 | @AutoValue 17 | @JsonAdapter(ModerationDetail.Adapter.class) 18 | public abstract class ModerationDetail { 19 | ModerationDetail() {} // AutoValue instances only 20 | 21 | @NotNull public abstract Concept concept(); 22 | public abstract int code(); 23 | @NotNull public abstract String description(); 24 | public abstract float thresholdMin(); 25 | public abstract float thresholdMax(); 26 | 27 | static class Adapter extends JSONAdapterFactory { 28 | @Nullable @Override protected Deserializer deserializer() { 29 | return new Deserializer() { 30 | @Nullable @Override 31 | public ModerationDetail deserialize( 32 | @NotNull JsonElement json, 33 | @NotNull TypeToken type, 34 | @NotNull Gson gson 35 | ) { 36 | final JsonObject root = assertJsonIs(json, JsonObject.class); 37 | return new AutoValue_ModerationDetail( 38 | gson.fromJson(root.get("concept"), Concept.class), 39 | root.get("code").getAsInt(), 40 | root.get("description").getAsString(), 41 | root.get("threshold_min").getAsFloat(), 42 | root.get("threshold_max").getAsFloat() 43 | ); 44 | } 45 | }; 46 | } 47 | 48 | @NotNull @Override protected TypeToken typeToken() { 49 | return new TypeToken() {}; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /gradle.properties.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clarifai/clarifai-java/8c1a278c32f67dab7d2188c7bc0e2e62eb9f4dae/gradle.properties.enc -------------------------------------------------------------------------------- /gradle/pmd.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'pmd' 2 | check.dependsOn('pmd') 3 | 4 | task pmd(type: Pmd) { 5 | ruleSetFiles = files("${project.rootDir}/pmd-ruleset.xml") 6 | ignoreFailures = true 7 | 8 | 9 | source 'src' 10 | include '**/*.java' 11 | exclude '**/gen/**' 12 | 13 | reports { 14 | xml.enabled = true 15 | html.enabled = true 16 | } 17 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clarifai/clarifai-java/8c1a278c32f67dab7d2188c7bc0e2e62eb9f4dae/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jan 06 15:59:14 EST 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip 7 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clarifai/clarifai-java/8c1a278c32f67dab7d2188c7bc0e2e62eb9f4dae/logo.png -------------------------------------------------------------------------------- /scripts/buildArtifacts.gradle: -------------------------------------------------------------------------------- 1 | task sourcesJar(type: Jar, dependsOn: classes) { 2 | classifier = 'sources' 3 | from sourceSets.main.allSource 4 | } 5 | 6 | task javadoc(type: Javadoc, overwrite: true) { 7 | source = sourceSets.main.allSource 8 | classpath += configurations.compile + configurations.compileOnly 9 | } 10 | 11 | task javadocJar(type: Jar, dependsOn: javadoc) { 12 | classifier = 'javadoc' 13 | //noinspection GroovyAccessibility 14 | from javadoc.destinationDir 15 | } 16 | 17 | artifacts { 18 | archives jar 19 | archives sourcesJar 20 | archives javadocJar 21 | } 22 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'core', 'tests' 2 | 3 | -------------------------------------------------------------------------------- /tests/assets/beer.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clarifai/clarifai-java/8c1a278c32f67dab7d2188c7bc0e2e62eb9f4dae/tests/assets/beer.mp4 -------------------------------------------------------------------------------- /tests/assets/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clarifai/clarifai-java/8c1a278c32f67dab7d2188c7bc0e2e62eb9f4dae/tests/assets/image.png -------------------------------------------------------------------------------- /tests/assets/metro-north.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Clarifai/clarifai-java/8c1a278c32f67dab7d2188c7bc0e2e62eb9f4dae/tests/assets/metro-north.jpg -------------------------------------------------------------------------------- /tests/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id "java" 3 | id "idea" 4 | } 5 | 6 | //noinspection GroovyUnusedAssignment 7 | sourceCompatibility = JavaVersion.VERSION_1_8 8 | //noinspection GroovyUnusedAssignment 9 | targetCompatibility = JavaVersion.VERSION_1_8 10 | 11 | apply from: rootProject.file("scripts/buildArtifacts.gradle") 12 | 13 | //noinspection GroovyMissingReturnStatement 14 | test { 15 | testLogging { 16 | exceptionFormat = 'full' 17 | showStandardStreams = true 18 | } 19 | } 20 | 21 | dependencies { 22 | testCompile( 23 | project(":core"), 24 | 25 | "junit:junit:$versions.junit", 26 | 27 | deps.nullityAnnotations, 28 | 29 | "org.slf4j:slf4j-api:$versions.slf4j", 30 | "org.slf4j:slf4j-simple:$versions.slf4j", 31 | 32 | "com.squareup.okhttp3:logging-interceptor:$versions.okhttp", 33 | 34 | "com.github.kevinmost:junit-retry-rule:$versions.junitRetryRule", 35 | ) 36 | } 37 | -------------------------------------------------------------------------------- /tests/src/test/java/clarifai2/integration_tests/ClarifaiClientIntTests.java: -------------------------------------------------------------------------------- 1 | package clarifai2.integration_tests; 2 | 3 | import clarifai2.api.ClarifaiBuilder; 4 | import clarifai2.exception.DeprecationException; 5 | import org.junit.Rule; 6 | import org.junit.Test; 7 | import org.junit.rules.ExpectedException; 8 | 9 | public class ClarifaiClientIntTests extends BaseIntTest { 10 | 11 | @Rule 12 | public final ExpectedException exception = ExpectedException.none(); 13 | 14 | @Test public void testAppIdSecretShouldBeDeprecated() { 15 | exception.expect(DeprecationException.class); 16 | new ClarifaiBuilder("some-app-id", "some-app-secret").buildSync(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/src/test/java/clarifai2/integration_tests/ConceptIntTests.java: -------------------------------------------------------------------------------- 1 | package clarifai2.integration_tests; 2 | 3 | import clarifai2.api.ClarifaiResponse; 4 | import clarifai2.dto.prediction.Concept; 5 | import org.junit.Test; 6 | 7 | import java.util.List; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | 11 | public class ConceptIntTests extends BaseIntTest { 12 | 13 | @Test public void shouldUpdateConceptNameWhenModifyConceptRequest() { 14 | final String conceptId = "conceptId1"; 15 | 16 | final String originalConceptName = "originalConceptName"; 17 | final float originalConceptValue = 0.0f; 18 | 19 | try { 20 | final String newConceptName = "newConceptName"; 21 | 22 | // Create a concept. It's fine if it already exists. 23 | client.addConcepts() 24 | .plus(Concept.forID(conceptId) 25 | .withName(originalConceptName) 26 | ).executeSync(); 27 | 28 | // Update the concept and assert fields were updated. 29 | ClarifaiResponse> setConceptsResponse = client.modifyConcepts() 30 | .plus(Concept.forID(conceptId) 31 | .withName(newConceptName) 32 | ).executeSync(); 33 | assertEquals(newConceptName, setConceptsResponse.get().get(0).name()); 34 | 35 | // Get the updated concept again to make sure fields were really updated. 36 | ClarifaiResponse getResponse = 37 | client.getConceptByID(conceptId).executeSync(); 38 | assertEquals(newConceptName, getResponse.get().name()); 39 | } finally { 40 | // Revert the concept's name & value back to the original values. 41 | client.modifyConcepts() 42 | .plus(Concept.forID(conceptId) 43 | .withName(originalConceptName) 44 | .withValue(originalConceptValue) 45 | ).executeSync(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/src/test/java/clarifai2/integration_tests/EnvVar.java: -------------------------------------------------------------------------------- 1 | package clarifai2.integration_tests; 2 | 3 | enum EnvVar { 4 | CLARIFAI_APP_ID, // Deprecated. 5 | CLARIFAI_APP_SECRET, // Deprecated. 6 | 7 | CLARIFAI_API_KEY, // all scopes 8 | CLARIFAI_API_BASE, 9 | 10 | CLARIFAI_API_KEY_NO_SCOPES, 11 | CLARIFAI_API_KEY_ALL_GET, 12 | CLARIFAI_API_KEY_INPUTS_GET_PATCH, 13 | CLARIFAI_API_KEY_INPUTS_GET_PATCH_AND_CONCEPTS_GET, 14 | CLARIFAI_API_KEY_MODELS_GET, 15 | CLARIFAI_API_KEY_MODELS_AND_CONCEPTS_GET, 16 | CLARIFAI_API_KEY_MODELS_AND_INPUTS_GET, 17 | CLARIFAI_API_KEY_PREDICT_AND_INPUTS_GET, 18 | CLARIFAI_API_KEY_PREDICT_AND_INPUTS_MODELS_CONCEPTS_GET; 19 | 20 | private final String envVarName; 21 | 22 | EnvVar() { 23 | this.envVarName = name(); 24 | } 25 | 26 | public String value() { 27 | return System.getenv(envVarName); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/src/test/java/clarifai2/integration_tests/ModelEqualityIntTests.java: -------------------------------------------------------------------------------- 1 | package clarifai2.integration_tests; 2 | 3 | import clarifai2.dto.model.ColorModel; 4 | import clarifai2.dto.model.ConceptModel; 5 | import clarifai2.dto.model.Model; 6 | import clarifai2.dto.model.ModelType; 7 | import clarifai2.dto.model.output_info.ConceptOutputInfo; 8 | import clarifai2.dto.prediction.Concept; 9 | import clarifai2.integration_tests.BaseIntTest; 10 | import org.junit.Test; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | import static org.junit.Assert.assertNotEquals; 14 | 15 | public class ModelEqualityIntTests extends BaseIntTest { 16 | 17 | @Test public void shouldBeEqualIfAllFieldsEqual() { 18 | ConceptModel model1 = Model._create(ModelType.CONCEPT, client, "id", "name", null); 19 | ConceptModel model2 = Model._create(ModelType.CONCEPT, client, "id", "name", null); 20 | 21 | assertEquals(model1, model2); 22 | } 23 | 24 | @Test public void shouldBeEqualIfDifferentName() { 25 | ConceptModel model1 = Model._create(ModelType.CONCEPT, client, "id", "name1", null); 26 | ConceptModel model2 = Model._create(ModelType.CONCEPT, client, "id", "name2", null); 27 | 28 | assertEquals(model1, model2); 29 | } 30 | 31 | @Test public void shouldBeEqualIfDifferentOutputInfo() { 32 | ConceptModel model1 = Model._create(ModelType.CONCEPT, client, "id", "name", 33 | ConceptOutputInfo.forConcepts(Concept.forID("dog"))); 34 | ConceptModel model2 = Model._create(ModelType.CONCEPT, client, "id", "name", 35 | ConceptOutputInfo.forConcepts(Concept.forID("cat"))); 36 | 37 | assertEquals(model1, model2); 38 | } 39 | 40 | @Test public void shouldNotBeEqualIfDifferentTypes() { 41 | ConceptModel conceptModel = Model._create(ModelType.CONCEPT, client, "id", "name", null); 42 | ColorModel colorModel = Model._create(ModelType.COLOR, client, "id", "name", null); 43 | 44 | assertNotEquals(conceptModel, colorModel); 45 | } 46 | 47 | @Test public void shouldNotBeEqualIfDifferentId() { 48 | ConceptModel model1 = Model._create(ModelType.CONCEPT, client, "id1", "name", null); 49 | ConceptModel model2 = Model._create(ModelType.CONCEPT, client, "id2", "name", null); 50 | 51 | assertNotEquals(model1, model2); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /tests/src/test/java/clarifai2/integration_tests/ModelOutputInfoIntTests.java: -------------------------------------------------------------------------------- 1 | package clarifai2.integration_tests; 2 | 3 | import clarifai2.api.ClarifaiResponse; 4 | import clarifai2.dto.model.ConceptModel; 5 | import clarifai2.dto.model.Model; 6 | import clarifai2.exception.ClarifaiException; 7 | import org.jetbrains.annotations.NotNull; 8 | import org.junit.Ignore; 9 | import org.junit.Rule; 10 | import org.junit.Test; 11 | import org.junit.rules.ExpectedException; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | import static org.junit.Assert.assertNotNull; 15 | import static org.junit.Assert.assertNull; 16 | import static org.junit.Assert.assertTrue; 17 | 18 | public class ModelOutputInfoIntTests extends BaseIntTest { 19 | @Rule public final ExpectedException exception = ExpectedException.none(); 20 | 21 | /** 22 | * Default models (not the ones received using GetModelRequest) shouldn't have outputInfo populated. 23 | */ 24 | @Test public void defaultModelShouldNotHaveOutputInfo() { 25 | ConceptModel model = client.getDefaultModels().apparelModel(); 26 | 27 | exception.expect(ClarifaiException.class); 28 | model.outputInfo(); 29 | } 30 | 31 | /** 32 | * Models received using GetModelsRequest should have outputInfo populated. 33 | */ 34 | @Test @Ignore public void shouldNotHaveOutputInfoAfterGetModelsRequest() { 35 | Model model = client.getModels().getPage(1).executeSync().get().get(0); 36 | 37 | assertNotNull(model.outputInfo()); 38 | } 39 | 40 | /** 41 | * When using the getModelRequest helper, outputInfo should be populated. 42 | */ 43 | @Test public void shouldHaveOutputInfoWhenUsingHelper() { 44 | ConceptModel model = client.getDefaultModels().apparelModel() 45 | .getModelRequest().executeSync().get().asConceptModel(); 46 | assertNotNull(model.outputInfo()); 47 | assertNotNull(model.outputInfo().concepts()); 48 | } 49 | 50 | @Test public void shouldGetModelWithVersion() { 51 | String modelID = client.getDefaultModels().generalModel().id(); 52 | 53 | // This is the first version of the general model. 54 | String modelVersionID = "aa9ca48295b37401f8af92ad1af0d91d"; 55 | 56 | ClarifaiResponse> response = client.getModelByID(modelID) 57 | .withVersion(modelVersionID) 58 | .executeSync(); 59 | 60 | ConceptModel model = response.get().asConceptModel(); 61 | assertTrue(model.outputInfo().concepts().size() > 0); 62 | assertEquals(modelVersionID, model.modelVersion().id()); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /tests/src/test/java/clarifai2/integration_tests/ModelVersionIntTests.java: -------------------------------------------------------------------------------- 1 | package clarifai2.integration_tests; 2 | 3 | import clarifai2.api.ClarifaiResponse; 4 | import clarifai2.dto.model.ConceptModel; 5 | import clarifai2.dto.model.Model; 6 | import clarifai2.dto.model.ModelVersion; 7 | import org.junit.Test; 8 | 9 | import java.util.List; 10 | 11 | import static clarifai2.internal.InternalUtil.assertNotNull; 12 | 13 | public class ModelVersionIntTests extends BaseIntTest { 14 | 15 | @Test public void shouldHaveFieldsPopulatedAfterGetModelById() { 16 | ConceptModel model = client.getModelByID(client.getDefaultModels().nsfwModel().id()) 17 | .executeSync().get().asConceptModel(); 18 | ModelVersion modelVersion = model.modelVersion(); 19 | assertNotNull(modelVersion.status()); 20 | assertNotNull(modelVersion.createdAt()); 21 | assertNotNull(modelVersion.totalInputCount()); 22 | assertNotNull(modelVersion.activeConceptCount()); 23 | } 24 | 25 | @Test public void shouldHaveFieldsPopulatedAfterGetModels() { 26 | ClarifaiResponse>> response = client.getModels().build().getPage(1).executeSync(); 27 | Model model = response.get().get(0); 28 | ModelVersion modelVersion = model.modelVersion(); 29 | assertNotNull(modelVersion.status()); 30 | assertNotNull(modelVersion.createdAt()); 31 | assertNotNull(modelVersion.totalInputCount()); 32 | assertNotNull(modelVersion.activeConceptCount()); 33 | } 34 | 35 | @Test public void shouldHaveFieldsPopulatedUsingGetModelVersionByID() { 36 | ConceptModel model = client.getModelByID(client.getDefaultModels().nsfwModel().id()) 37 | .executeSync().get().asConceptModel(); 38 | ModelVersion modelVersion = client.getModelVersionByID(model.id(), model.modelVersion().id()) 39 | .executeSync().get(); 40 | assertNotNull(modelVersion.status()); 41 | assertNotNull(modelVersion.createdAt()); 42 | assertNotNull(modelVersion.totalInputCount()); 43 | assertNotNull(modelVersion.activeConceptCount()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/src/test/java/clarifai2/integration_tests/SearchInputsIntTests.java: -------------------------------------------------------------------------------- 1 | package clarifai2.integration_tests; 2 | 3 | import clarifai2.api.ClarifaiResponse; 4 | import clarifai2.api.request.input.SearchClause; 5 | import clarifai2.api.request.input.SearchInputsRequest; 6 | import clarifai2.dto.input.ClarifaiImage; 7 | import clarifai2.dto.search.SearchInputsResult; 8 | import org.junit.Test; 9 | 10 | import static org.junit.Assert.assertNotNull; 11 | 12 | public class SearchInputsIntTests extends BaseIntTest { 13 | 14 | private String imageWithNoSearchHits = CONAN_GIF_URL; 15 | 16 | @Test public void allDataShouldBeExposedAndNotNull() { 17 | SearchInputsRequest request = client.searchInputs(SearchClause.matchImageURL( 18 | ClarifaiImage.of(imageWithNoSearchHits))); 19 | ClarifaiResponse response = request.getPage(1).executeSync(); 20 | assertNotNull(response.get().id()); 21 | assertNotNull(response.getStatus()); 22 | assertNotNull(response.get().searchHits()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/src/test/java/clarifai2/unit_tests/BaseUnitTest.java: -------------------------------------------------------------------------------- 1 | package clarifai2.unit_tests; 2 | 3 | import com.google.gson.JsonElement; 4 | import com.google.gson.JsonParser; 5 | import org.jetbrains.annotations.NotNull; 6 | 7 | import java.io.BufferedReader; 8 | import java.io.FileInputStream; 9 | import java.io.IOException; 10 | import java.io.InputStreamReader; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | 14 | public class BaseUnitTest { 15 | 16 | private JsonParser parser = new JsonParser(); 17 | 18 | @NotNull protected String readResourceFile(String fileName) throws IOException { 19 | ClassLoader classLoader = getClass().getClassLoader(); 20 | String filePath = classLoader.getResource(fileName).getFile(); 21 | 22 | String responseString; 23 | try(BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath)))) { 24 | StringBuilder sb = new StringBuilder(); 25 | String line = br.readLine(); 26 | 27 | while (line != null) { 28 | sb.append(line); 29 | sb.append(System.lineSeparator()); 30 | line = br.readLine(); 31 | } 32 | responseString = sb.toString(); 33 | } 34 | return responseString; 35 | } 36 | 37 | protected void assertJsonEquals(String json1, String json2) { 38 | JsonElement o1 = parser.parse(json1); 39 | JsonElement o2 = parser.parse(json2); 40 | assertEquals(o1, o2); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/src/test/java/clarifai2/unit_tests/ModelEvaluationUnitTests.java: -------------------------------------------------------------------------------- 1 | package clarifai2.unit_tests; 2 | 3 | import clarifai2.api.ClarifaiBuilder; 4 | import clarifai2.api.ClarifaiClient; 5 | import clarifai2.api.ClarifaiResponse; 6 | import clarifai2.dto.model.ModelVersion; 7 | import clarifai2.grpc.FkClarifaiHttpClient; 8 | import org.jetbrains.annotations.NotNull; 9 | import org.junit.Test; 10 | 11 | import java.io.IOException; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | import static org.junit.Assert.assertTrue; 15 | 16 | public class ModelEvaluationUnitTests extends BaseUnitTest { 17 | 18 | @Test public void runModelEvaluation() throws IOException { 19 | FkClarifaiHttpClient httpClient = new FkClarifaiHttpClient(readResourceFile("runModelEvaluation_response.json")); 20 | ClarifaiClient client = new ClarifaiBuilder(httpClient).buildSync(); 21 | 22 | @NotNull ClarifaiResponse response = client.runModelEvaluation("@modelID", "@modelVersionID") 23 | .executeSync(); 24 | 25 | assertTrue(httpClient.requestUrl().endsWith("/v2/models/@modelID/versions/@modelVersionID/metrics")); 26 | assertEquals("POST", httpClient.requestMethod()); 27 | assertJsonEquals("{}", httpClient.requestBody()); 28 | 29 | assertTrue(response.isSuccessful()); 30 | ModelVersion modelVersion = response.get(); 31 | 32 | assertEquals("@modelVersionID", modelVersion.id()); 33 | assertEquals(21100, modelVersion.status().statusCode()); 34 | assertEquals(21303, modelVersion.modelMetricsStatus().statusCode()); 35 | assertEquals(2, modelVersion.activeConceptCount()); 36 | assertEquals(30, modelVersion.totalInputCount()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/src/test/resources/addConcepts_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "concepts": [ 3 | { 4 | "id": "@conceptID1", 5 | "value": 1 6 | }, 7 | { 8 | "id": "@conceptID2", 9 | "value": 1 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /tests/src/test/resources/addConcepts_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "concepts": [ 7 | { 8 | "id": "@conceptID1", 9 | "name": "@conceptID1", 10 | "value": 1, 11 | "created_at": "2019-01-14T16:42:42.210598955Z", 12 | "language": "en", 13 | "app_id": "c102e505581f49d2956e3caa2e1a0dc9" 14 | }, 15 | { 16 | "id": "@conceptID2", 17 | "name": "@conceptID2", 18 | "value": 1, 19 | "created_at": "2019-01-14T16:42:42.210605836Z", 20 | "language": "en", 21 | "app_id": "c102e505581f49d2956e3caa2e1a0dc9" 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /tests/src/test/resources/addInputs_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "id": "@inputID1", 5 | "data": { 6 | "image": { 7 | "url": "https://some.image.url1", 8 | "allow_duplicate_url": true 9 | }, 10 | "geo": { 11 | "geo_point": { 12 | "longitude": 55, 13 | "latitude": 66 14 | } 15 | } 16 | } 17 | }, 18 | { 19 | "id": "@inputID2", 20 | "data": { 21 | "image": { 22 | "url": "https://some.image.url2", 23 | "allow_duplicate_url": true 24 | } 25 | } 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /tests/src/test/resources/addInputs_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "inputs": [ 7 | { 8 | "id": "@inputID1", 9 | "data": { 10 | "image": { 11 | "url": "https://some.image.url1" 12 | }, 13 | "geo": { 14 | "geo_point": { 15 | "longitude": 55, 16 | "latitude": 66 17 | } 18 | } 19 | }, 20 | "created_at": "2019-01-17T12:43:04.895006174Z", 21 | "modified_at": "2019-01-17T12:43:04.895006174Z", 22 | "status": { 23 | "code": 30001, 24 | "description": "Download pending" 25 | } 26 | }, 27 | { 28 | "id": "@inputID2", 29 | "data": { 30 | "image": { 31 | "url": "https://some.image.url2" 32 | } 33 | }, 34 | "created_at": "2019-01-17T12:43:04.895006174Z", 35 | "modified_at": "2019-01-17T12:43:04.895006174Z", 36 | "status": { 37 | "code": 30001, 38 | "description": "Download pending" 39 | } 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /tests/src/test/resources/addMetadataForInput_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "id": "@inputID", 5 | "data": { 6 | "metadata": { 7 | "@key1": "@value1", 8 | "@key2": "@value2" 9 | } 10 | } 11 | } 12 | ], 13 | "action":"overwrite" 14 | } 15 | -------------------------------------------------------------------------------- /tests/src/test/resources/addMetadataForInput_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "inputs": [{ 7 | "id": "@inputID", 8 | "data": { 9 | "image": { 10 | "url": "https://some-image-url" 11 | }, 12 | "concepts": [{ 13 | "id": "concept1", 14 | "name": "concept1", 15 | "value": 1, 16 | "app_id": "@appID" 17 | }], 18 | "metadata": { 19 | "@key1": "@value1", 20 | "@key2": "@value2" 21 | } 22 | }, 23 | "created_at": "2017-11-02T15:08:22.005157Z", 24 | "modified_at": "2017-11-02T15:08:23.071624222Z", 25 | "status": { 26 | "code": 30200, 27 | "description": "Input image modification success" 28 | } 29 | }] 30 | } 31 | -------------------------------------------------------------------------------- /tests/src/test/resources/batchPredictWithArguments_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url1" 7 | } 8 | } 9 | }, 10 | { 11 | "data": { 12 | "image": { 13 | "url": "https://some-image-url2" 14 | } 15 | } 16 | } 17 | ], 18 | "model": { 19 | "output_info": { 20 | "output_config": { 21 | "language": "de", 22 | "max_concepts": 2, 23 | "min_value": 0.98 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/src/test/resources/batchPredictWithOneInvalidURL_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-valid-url" 7 | } 8 | } 9 | }, 10 | { 11 | "data": { 12 | "image": { 13 | "url": "https://some-invalid-url" 14 | } 15 | } 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /tests/src/test/resources/batchPredict_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url1" 7 | } 8 | } 9 | }, 10 | { 11 | "data": { 12 | "image": { 13 | "url": "https://some-image-url2" 14 | } 15 | } 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /tests/src/test/resources/createModelGeneric_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "models": [{ 3 | "id": "@modelID", 4 | "name": "@modelName" 5 | }] 6 | } -------------------------------------------------------------------------------- /tests/src/test/resources/createModelGeneric_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model": { 7 | "id": "@modelID", 8 | "name": "@modelName", 9 | "created_at": "2019-01-18T13:51:40.798977081Z", 10 | "app_id": "@appID", 11 | "output_info": { 12 | "output_config": { 13 | "concepts_mutually_exclusive": false, 14 | "closed_environment": false, 15 | "max_concepts": 0, 16 | "min_value": 0 17 | }, 18 | "message": "Show output_info with: GET /models/{model_id}/output_info", 19 | "type": "concept", 20 | "type_ext": "concept" 21 | }, 22 | "model_version": { 23 | "id": "@modelVersionID", 24 | "created_at": "2019-01-18T13:51:40.818805581Z", 25 | "status": { 26 | "code": 21102, 27 | "description": "Model not yet trained" 28 | }, 29 | "train_stats": {} 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/src/test/resources/createModel_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "models": [{ 3 | "id": "@modelID", 4 | "name": "@modelName", 5 | "output_info": { 6 | "data": { 7 | "concepts": [ 8 | { 9 | "id": "dog", 10 | "value": 1 11 | }, 12 | { 13 | "id": "cat", 14 | "value": 1 15 | } 16 | ] 17 | }, 18 | "output_config": {} 19 | } 20 | }] 21 | } 22 | -------------------------------------------------------------------------------- /tests/src/test/resources/createModel_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model": { 7 | "id": "@modelID", 8 | "name": "@modelName", 9 | "created_at": "2019-01-22T11:54:12.375436048Z", 10 | "app_id": "@appID", 11 | "output_info": { 12 | "output_config": { 13 | "concepts_mutually_exclusive": false, 14 | "closed_environment": false, 15 | "max_concepts": 0, 16 | "min_value": 0 17 | }, 18 | "message": "Show output_info with: GET /models/{model_id}/output_info", 19 | "type": "concept", 20 | "type_ext": "concept" 21 | }, 22 | "model_version": { 23 | "id": "@modelVersionID", 24 | "created_at": "2019-01-22T11:54:12.406406642Z", 25 | "status": { 26 | "code": 21102, 27 | "description": "Model not yet trained" 28 | }, 29 | "active_concept_count": 2, 30 | "train_stats": {} 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/src/test/resources/deleteAllInputs_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "delete_all": true 3 | } 4 | -------------------------------------------------------------------------------- /tests/src/test/resources/deleteAllInputs_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test/resources/deleteAllModels_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test/resources/deleteInput_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test/resources/deleteInputsBatch_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "ids": [ 3 | "@inputID1", 4 | "@inputID2" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test/resources/deleteInputsBatch_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test/resources/deleteModelVersion_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test/resources/deleteModel_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test/resources/deleteModelsBatch_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "ids": [ 3 | "@modelID1", 4 | "@modelID2" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test/resources/deleteModelsBatch_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test/resources/findModelByNameAndType_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "model_query": { 3 | "name": "*", 4 | "type": "color" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test/resources/findModelByNameAndType_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "models": [ 7 | { 8 | "id": "@modelID", 9 | "name": "color", 10 | "created_at": "2016-05-11T18:05:45.924367Z", 11 | "app_id": "main", 12 | "output_info": { 13 | "message": "Show output_info with: GET /models/{model_id}/output_info", 14 | "type": "color", 15 | "type_ext": "color" 16 | }, 17 | "model_version": { 18 | "id": "@modelVersionID", 19 | "created_at": "2016-07-13T01:19:12.147644Z", 20 | "status": { 21 | "code": 21100, 22 | "description": "Model is trained and ready" 23 | } 24 | }, 25 | "display_name": "Color" 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /tests/src/test/resources/findModelByName_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "model_query": { 3 | "name": "celeb*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/src/test/resources/findModelByName_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "models": [{ 7 | "id": "@modelID", 8 | "name": "celeb-v1.3", 9 | "created_at": "2016-10-25T19:30:38.541073Z", 10 | "app_id": "main", 11 | "output_info": { 12 | "message": "Show output_info with: GET /models/{model_id}/output_info", 13 | "type": "concept", 14 | "type_ext": "facedetect-identity" 15 | }, 16 | "model_version": { 17 | "id": "@modelVersionID", 18 | "created_at": "2016-10-25T19:30:38.541073Z", 19 | "status": { 20 | "code": 21100, 21 | "description": "Model trained successfully" 22 | }, 23 | "active_concept_count": 10554 24 | }, 25 | "display_name": "Celebrity" 26 | }] 27 | } 28 | -------------------------------------------------------------------------------- /tests/src/test/resources/getColorModel_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model": { 7 | "id": "@modelID", 8 | "name": "color", 9 | "created_at": "2016-05-11T18:05:45.924367Z", 10 | "app_id": "main", 11 | "output_info": { 12 | "data": { 13 | "concepts": [ 14 | { 15 | "id": "@conceptID1", 16 | "name": "AliceBlue", 17 | "value": 1, 18 | "created_at": "2017-06-15T20:40:52.248062Z", 19 | "language": "en", 20 | "app_id": "main" 21 | }, 22 | { 23 | "id": "@conceptID2", 24 | "name": "AntiqueWhite", 25 | "value": 1, 26 | "created_at": "2017-06-15T20:40:52.248062Z", 27 | "language": "en", 28 | "app_id": "main" 29 | } 30 | ] 31 | }, 32 | "type": "color", 33 | "type_ext": "color" 34 | }, 35 | "model_version": { 36 | "id": "@modelVersionID", 37 | "created_at": "2016-07-13T01:19:12.147644Z", 38 | "status": { 39 | "code": 21100, 40 | "description": "Model trained successfully" 41 | }, 42 | "active_concept_count": 140, 43 | "train_stats": {} 44 | }, 45 | "display_name": "Color" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/src/test/resources/getConceptModel_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model": { 7 | "id": "@modelID", 8 | "name": "@modelName", 9 | "created_at": "2017-05-16T19:20:38.733764Z", 10 | "app_id": "main", 11 | "output_info": { 12 | "data": { 13 | "concepts": [ 14 | { 15 | "id": "@conceptID1", 16 | "name": "@conceptNAME1", 17 | "value": 1, 18 | "created_at": "2016-10-25T19:28:34.869737Z", 19 | "language": "en", 20 | "app_id": "main" 21 | }, 22 | { 23 | "id": "@conceptID2", 24 | "name": "@conceptNAME2", 25 | "value": 1, 26 | "created_at": "2016-10-25T19:28:34.869737Z", 27 | "language": "en", 28 | "app_id": "main" 29 | }, 30 | { 31 | "id": "@conceptID3", 32 | "name": "@conceptNAME3", 33 | "value": 1, 34 | "created_at": "2016-10-25T19:28:34.869737Z", 35 | "language": "en", 36 | "app_id": "main" 37 | } 38 | ] 39 | }, 40 | "type": "concept", 41 | "type_ext": "concept" 42 | }, 43 | "model_version": { 44 | "id": "@modelVersionID", 45 | "created_at": "2016-10-25T19:30:38.541073Z", 46 | "status": { 47 | "code": 21100, 48 | "description": "Model trained successfully" 49 | }, 50 | "active_concept_count": 10553, 51 | "train_stats": {} 52 | }, 53 | "display_name": "Concept" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/src/test/resources/getConcept_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "concept": { 7 | "id": "@conceptID", 8 | "name": "@conceptName", 9 | "created_at": "2017-10-02T11:34:20.419915Z", 10 | "language": "en", 11 | "app_id": "@appID" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/src/test/resources/getConcepts_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "concepts": [{ 7 | "id": "@conceptID1", 8 | "name": "@conceptName1", 9 | "created_at": "2017-10-15T16:28:28.901994Z", 10 | "language": "en", 11 | "app_id": "@appID" 12 | }, { 13 | "id": "@conceptID2", 14 | "name": "@conceptName2", 15 | "created_at": "2017-10-15T16:26:46.667104Z", 16 | "language": "en", 17 | "app_id": "@appID" 18 | }] 19 | } 20 | -------------------------------------------------------------------------------- /tests/src/test/resources/getDemographicsModel_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok", 5 | "req_id": "1fb47f5db0c64f1b8bd3cca36fbddb47" 6 | }, 7 | "model": { 8 | "id": "@modelID", 9 | "name": "demographics", 10 | "created_at": "2016-12-23T06:08:44.271674Z", 11 | "app_id": "main", 12 | "output_info": { 13 | "data": { 14 | "concepts": [ 15 | { 16 | "id": "@conceptID1", 17 | "name": "0", 18 | "value": 1, 19 | "created_at": "2017-03-28T22:11:16.610298Z", 20 | "language": "en", 21 | "app_id": "main" 22 | }, 23 | { 24 | "id": "@conceptID2", 25 | "name": "1", 26 | "value": 1, 27 | "created_at": "2017-03-28T22:11:16.610298Z", 28 | "language": "en", 29 | "app_id": "main" 30 | } 31 | ] 32 | }, 33 | "type": "detect-concept", 34 | "type_ext": "detect-concept" 35 | }, 36 | "model_version": { 37 | "id": "f783f0807c52474c8c6ad20c8cf45fc0", 38 | "created_at": "2016-12-23T06:08:44.271674Z", 39 | "status": { 40 | "code": 21100, 41 | "description": "Model is trained and ready" 42 | }, 43 | "active_concept_count": 104, 44 | "worker_id": "ea769b45b38d4455b400ca949cd70d9e" 45 | }, 46 | "display_name": "Demographics" 47 | } 48 | } -------------------------------------------------------------------------------- /tests/src/test/resources/getEmbeddingModel_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model": { 7 | "id": "@modelID", 8 | "name": "general", 9 | "created_at": "2016-06-17T22:01:04.144732Z", 10 | "app_id": "main", 11 | "output_info": { 12 | "type": "embed", 13 | "type_ext": "embed" 14 | }, 15 | "model_version": { 16 | "id": "@modelVersionID", 17 | "created_at": "2016-07-13T01:19:12.147644Z", 18 | "status": { 19 | "code": 21100, 20 | "description": "Model trained successfully" 21 | }, 22 | "train_stats": {} 23 | }, 24 | "display_name": "General Embedding" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/src/test/resources/getFaceConceptsModel_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model": { 7 | "id": "@modelID", 8 | "name": "@modelName", 9 | "created_at": "2017-05-16T19:20:38.733764Z", 10 | "app_id": "main", 11 | "output_info": { 12 | "data": { 13 | "concepts": [ 14 | { 15 | "id": "@conceptID1", 16 | "name": "deborah kagan", 17 | "value": 1, 18 | "created_at": "2016-10-25T19:28:34.869737Z", 19 | "language": "en", 20 | "app_id": "main" 21 | }, 22 | { 23 | "id": "@conceptID2", 24 | "name": "deborah kara unger", 25 | "value": 1, 26 | "created_at": "2016-10-25T19:28:34.869737Z", 27 | "language": "en", 28 | "app_id": "main" 29 | }, 30 | { 31 | "id": "@conceptID3", 32 | "name": "deborah kerr", 33 | "value": 1, 34 | "created_at": "2016-10-25T19:28:34.869737Z", 35 | "language": "en", 36 | "app_id": "main" 37 | } 38 | ] 39 | }, 40 | "type": "concept", 41 | "type_ext": "facedetect-identity" 42 | }, 43 | "model_version": { 44 | "id": "@modelVersionID", 45 | "created_at": "2016-10-25T19:30:38.541073Z", 46 | "status": { 47 | "code": 21100, 48 | "description": "Model trained successfully" 49 | }, 50 | "active_concept_count": 10553, 51 | "train_stats": {} 52 | }, 53 | "display_name": "Celebrity" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/src/test/resources/getFaceEmbeddingModel_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model": { 7 | "id": "@modelID", 8 | "name": "face", 9 | "created_at": "2016-10-25T19:30:38.541073Z", 10 | "app_id": "main", 11 | "output_info": { 12 | "type": "embed", 13 | "type_ext": "detect-embed" 14 | }, 15 | "model_version": { 16 | "id": "@modelVersionID", 17 | "created_at": "2016-10-25T19:30:38.541073Z", 18 | "status": { 19 | "code": 21100, 20 | "description": "Model trained successfully" 21 | }, 22 | "train_stats": {} 23 | }, 24 | "display_name": "Face Embedding" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/src/test/resources/getInput_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "input": { 7 | "id": "@inputID", 8 | "data": { 9 | "image": { 10 | "url": "https://some.image.url" 11 | }, 12 | "geo": { 13 | "geo_point": { 14 | "longitude": 55, 15 | "latitude": 66 16 | } 17 | } 18 | }, 19 | "created_at": "2019-01-17T14:02:21.216473Z", 20 | "modified_at": "2019-01-17T14:02:21.800792Z", 21 | "status": { 22 | "code": 30000, 23 | "description": "Download complete" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tests/src/test/resources/getInputsStatus_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "counts": { 7 | "processed": 1, 8 | "to_process": 2, 9 | "errors": 3, 10 | "processing": 4, 11 | "reindexed": 5, 12 | "to_reindex": 6, 13 | "reindex_errors": 7, 14 | "reindexing": 8 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/src/test/resources/getInputs_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "inputs": [ 7 | { 8 | "id": "@inputID1", 9 | "data": { 10 | "image": { 11 | "url": "https://some.image.url1" 12 | }, 13 | "geo": { 14 | "geo_point": { 15 | "longitude": 55, 16 | "latitude": 66 17 | } 18 | } 19 | }, 20 | "created_at": "2019-01-17T14:02:21.216473Z", 21 | "modified_at": "2019-01-17T14:02:21.800792Z", 22 | "status": { 23 | "code": 30000, 24 | "description": "Download complete" 25 | } 26 | }, 27 | { 28 | "id": "@inputID2", 29 | "data": { 30 | "image": { 31 | "url": "https://some.image.url2" 32 | } 33 | }, 34 | "created_at": "2019-01-17T14:02:21.216473Z", 35 | "modified_at": "2019-01-17T14:02:21.800792Z", 36 | "status": { 37 | "code": 30000, 38 | "description": "Download complete" 39 | } 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /tests/src/test/resources/getLogoModel_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model": { 7 | "id": "@modelID", 8 | "name": "logo", 9 | "created_at": "2017-03-06T22:57:00.707216Z", 10 | "app_id": "main", 11 | "output_info": { 12 | "data": { 13 | "concepts": [ 14 | { 15 | "id": "@conceptID1", 16 | "name": "3M", 17 | "value": 1, 18 | "created_at": "2017-05-22T18:13:37.682503Z", 19 | "language": "en", 20 | "app_id": "main" 21 | }, 22 | { 23 | "id": "@conceptID2", 24 | "name": "3Musketeers", 25 | "value": 1, 26 | "created_at": "2017-05-22T18:13:37.682503Z", 27 | "language": "en", 28 | "app_id": "main" 29 | } 30 | ] 31 | }, 32 | "type": "detect-concept", 33 | "type_ext": "detect-concept" 34 | }, 35 | "model_version": { 36 | "id": "@modelVersionID", 37 | "created_at": "2017-03-06T22:57:05.625525Z", 38 | "status": { 39 | "code": 21100, 40 | "description": "Model trained successfully" 41 | }, 42 | "active_concept_count": 561, 43 | "train_stats": {} 44 | }, 45 | "display_name": "Logo" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/src/test/resources/getModelInputs_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "inputs": [{ 7 | "id": "@inputID", 8 | "data": { 9 | "image": { 10 | "url": "https://imageURL" 11 | }, 12 | "concepts": [{ 13 | "id": "@conceptID", 14 | "name": "@conceptName", 15 | "value": 1, 16 | "app_id": "@conceptAppID" 17 | }] 18 | }, 19 | "created_at": "2017-10-15T16:30:52.964888Z", 20 | "status": { 21 | "code": 30000, 22 | "description": "Download complete" 23 | } 24 | }] 25 | } 26 | -------------------------------------------------------------------------------- /tests/src/test/resources/getModelVersion_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model_version": { 7 | "id": "@modelVersionID", 8 | "created_at": "2017-10-31T16:30:31.226185Z", 9 | "status": { 10 | "code": 21100, 11 | "description": "Model trained successfully" 12 | }, 13 | "active_concept_count": 5, 14 | "train_stats": {} 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /tests/src/test/resources/getModelVersions_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model_versions": [ 7 | { 8 | "id": "@modelVersionID1", 9 | "created_at": "2017-10-31T16:30:31.226185Z", 10 | "status": { 11 | "code": 21100, 12 | "description": "Model trained successfully" 13 | }, 14 | "active_concept_count": 5, 15 | "train_stats": {} 16 | }, 17 | { 18 | "id": "@modelVersionID2", 19 | "created_at": "2017-05-16T19:20:38.733764Z", 20 | "status": { 21 | "code": 21100, 22 | "description": "Model trained successfully" 23 | }, 24 | "active_concept_count": 5, 25 | "train_stats": {} 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /tests/src/test/resources/getModel_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model": { 7 | "id": "@modelID", 8 | "name": "@modelName", 9 | "created_at": "2017-05-16T19:20:38.733764Z", 10 | "app_id": "main", 11 | "output_info": { 12 | "data": { 13 | "concepts": [{ 14 | "id": "@conceptID", 15 | "name": "safe", 16 | "created_at": "2017-05-16T19:20:38.450157Z", 17 | "language": "en", 18 | "app_id": "main" 19 | }] 20 | }, 21 | "type": "concept", 22 | "type_ext": "concept" 23 | }, 24 | "model_version": { 25 | "id": "@modelVersionID", 26 | "created_at": "2017-05-16T19:20:38.733764Z", 27 | "status": { 28 | "code": 21100, 29 | "description": "Model trained successfully" 30 | }, 31 | "active_concept_count": 5 32 | }, 33 | "display_name": "Moderation" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/src/test/resources/getModels_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "models": [ 7 | { 8 | "id": "@modelID1", 9 | "name": "@modelName1", 10 | "created_at": "2019-01-16T23:33:46.605294Z", 11 | "app_id": "main", 12 | "output_info": { 13 | "message": "Show output_info with: GET /models/{model_id}/output_info", 14 | "type": "concept", 15 | "type_ext": "concept" 16 | }, 17 | "model_version": { 18 | "id": "28b2ff6148684aa2b18a34cd004b4fac", 19 | "created_at": "2019-01-16T23:33:46.605294Z", 20 | "status": { 21 | "code": 21100, 22 | "description": "Model trained successfully" 23 | }, 24 | "train_stats": {} 25 | }, 26 | "display_name": "Moderation" 27 | }, 28 | { 29 | "id": "@modelID2", 30 | "name": "@modelName2", 31 | "created_at": "2019-01-16T23:33:46.605294Z", 32 | "app_id": "main", 33 | "output_info": { 34 | "message": "Show output_info with: GET /models/{model_id}/output_info", 35 | "type": "embed", 36 | "type_ext": "detect-embed" 37 | }, 38 | "model_version": { 39 | "id": "fc6999e5eb274dfdba826f6b1c7ffdab", 40 | "created_at": "2019-01-16T23:33:46.605294Z", 41 | "status": { 42 | "code": 21100, 43 | "description": "Model trained successfully" 44 | }, 45 | "train_stats": {} 46 | }, 47 | "display_name": "Face Embedding" 48 | } 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /tests/src/test/resources/getVideoModel_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model": { 7 | "id": "@modelID", 8 | "name": "nsfw-v1.0", 9 | "created_at": "2016-09-17T22:18:59.955626Z", 10 | "app_id": "main", 11 | "output_info": { 12 | "data": { 13 | "concepts": [ 14 | { 15 | "id": "@conceptID1", 16 | "name": "nsfw", 17 | "value": 1, 18 | "created_at": "2016-09-17T22:18:50.338072Z", 19 | "language": "en", 20 | "app_id": "main" 21 | }, 22 | { 23 | "id": "@conceptID2", 24 | "name": "sfw", 25 | "value": 1, 26 | "created_at": "2016-09-17T22:18:50.338072Z", 27 | "language": "en", 28 | "app_id": "main" 29 | } 30 | ] 31 | }, 32 | "type": "concept", 33 | "type_ext": "concept" 34 | }, 35 | "model_version": { 36 | "id": "@modelVersionID", 37 | "created_at": "2018-01-23T19:25:09.618692Z", 38 | "status": { 39 | "code": 21100, 40 | "description": "Model trained successfully" 41 | }, 42 | "active_concept_count": 2, 43 | "train_stats": {} 44 | }, 45 | "display_name": "NSFW" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/src/test/resources/invalidJson_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model": { 7 | -------------------------------------------------------------------------------- /tests/src/test/resources/mergeConceptsForInput_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "id": "@inputID", 5 | "data": { 6 | "concepts": [ 7 | { 8 | "id": "@positiveConcept1", 9 | "name": "@positiveConceptName1", 10 | "value": 1.0 11 | }, 12 | { 13 | "id": "@positiveConcept2", 14 | "value": 1.0 15 | }, 16 | { 17 | "id": "@negativeConcept1", 18 | "name": "@negativeConceptName1", 19 | "value": 0.0 20 | }, 21 | { 22 | "id": "@negativeConcept2", 23 | "value": 0.0 24 | } 25 | ] 26 | } 27 | } 28 | ], 29 | "action":"merge" 30 | } 31 | -------------------------------------------------------------------------------- /tests/src/test/resources/mergeConceptsForInput_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "inputs": [{ 7 | "id": "@inputID", 8 | "data": { 9 | "image": { 10 | "url": "https://some-image-url" 11 | }, 12 | "concepts": [ 13 | { 14 | "id": "@positiveConcept1", 15 | "name": "@positiveConceptName1", 16 | "value": 1 17 | }, 18 | { 19 | "id": "@positiveConcept2", 20 | "value": 1 21 | }, 22 | { 23 | "id": "@negativeConcept1", 24 | "name": "@negativeConceptName1", 25 | "value": 0 26 | }, 27 | { 28 | "id": "@negativeConcept2", 29 | "value": 0 30 | } 31 | ] 32 | }, 33 | "created_at": "2017-10-13T20:53:00.253139Z", 34 | "modified_at": "2017-10-13T20:53:00.868659782Z", 35 | "status": { 36 | "code": 30200, 37 | "description": "Input image modification success" 38 | } 39 | }] 40 | } 41 | -------------------------------------------------------------------------------- /tests/src/test/resources/modifyConcepts_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "concepts": [ 3 | { 4 | "id": "@conceptID", 5 | "name": "@newConceptName", 6 | "value": 1 7 | } 8 | ], 9 | "action": "overwrite" 10 | } 11 | -------------------------------------------------------------------------------- /tests/src/test/resources/modifyConcepts_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "concepts": [ 7 | { 8 | "id": "@conceptID", 9 | "name": "@newConceptName", 10 | "value": 1, 11 | "created_at": "2019-01-15T14:11:43.864812079Z", 12 | "language": "en", 13 | "app_id": "@appID" 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /tests/src/test/resources/modifyModel_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "models": [ 3 | { 4 | "id": "@modelID", 5 | "name": "@newModelName", 6 | "output_info": { 7 | "data": { 8 | "concepts": [ 9 | { 10 | "id": "@conceptID1", 11 | "value": 1 12 | } 13 | ] 14 | }, 15 | "output_config": { 16 | "concepts_mutually_exclusive": true, 17 | "closed_environment": true 18 | } 19 | } 20 | } 21 | ], 22 | "action": "merge" 23 | } 24 | -------------------------------------------------------------------------------- /tests/src/test/resources/modifyModel_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "models": [{ 7 | "id": "@modelID", 8 | "name": "@newModelName", 9 | "created_at": "2017-11-27T08:35:13.911899Z", 10 | "app_id": "@appID", 11 | "output_info": { 12 | "output_config": { 13 | "concepts_mutually_exclusive": true, 14 | "closed_environment": true 15 | }, 16 | "message": "Show output_info with: GET /models/{model_id}/output_info", 17 | "type": "concept", 18 | "type_ext": "concept" 19 | }, 20 | "model_version": { 21 | "id": "@modelVersionID", 22 | "created_at": "2017-11-27T08:35:14.298376733Z", 23 | "status": { 24 | "code": 21102, 25 | "description": "Model not yet trained" 26 | } 27 | } 28 | }] 29 | } 30 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictColor_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url" 7 | } 8 | } 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictColor_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "outputs": [ 7 | { 8 | "id": "@outputID", 9 | "status": { 10 | "code": 10000, 11 | "description": "Ok" 12 | }, 13 | "created_at": "2019-01-30T10:17:40.806851955Z", 14 | "model": { 15 | "id": "@modelID", 16 | "name": "color", 17 | "created_at": "2016-05-11T18:05:45.924367Z", 18 | "app_id": "main", 19 | "output_info": { 20 | "message": "Show output_info with: GET /models/{model_id}/output_info", 21 | "type": "color", 22 | "type_ext": "color" 23 | }, 24 | "model_version": { 25 | "id": "@modelVersionID", 26 | "created_at": "2016-07-13T01:19:12.147644Z", 27 | "status": { 28 | "code": 21100, 29 | "description": "Model trained successfully" 30 | }, 31 | "train_stats": {} 32 | }, 33 | "display_name": "Color" 34 | }, 35 | "input": { 36 | "id": "@inputID", 37 | "data": { 38 | "image": { 39 | "url": "https://some-image-url" 40 | } 41 | } 42 | }, 43 | "data": { 44 | "colors": [ 45 | { 46 | "raw_hex": "#f2f2f2", 47 | "w3c": { 48 | "hex": "#f5f5f5", 49 | "name": "WhiteSmoke" 50 | }, 51 | "value": 0.929 52 | }, 53 | { 54 | "raw_hex": "#686078", 55 | "w3c": { 56 | "hex": "#708090", 57 | "name": "SlateGray" 58 | }, 59 | "value": 0.02675 60 | } 61 | ] 62 | } 63 | } 64 | ] 65 | } 66 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictConcept_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url" 7 | } 8 | } 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictConcept_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "outputs": [ 7 | { 8 | "id": "@outputID", 9 | "status": { 10 | "code": 10000, 11 | "description": "Ok" 12 | }, 13 | "created_at": "2019-01-30T16:52:30.993694779Z", 14 | "model": { 15 | "id": "@modelID", 16 | "name": "concept-v1.0", 17 | "created_at": "2016-09-17T22:18:59.955626Z", 18 | "app_id": "main", 19 | "output_info": { 20 | "message": "Show output_info with: GET /models/{model_id}/output_info", 21 | "type": "concept", 22 | "type_ext": "concept" 23 | }, 24 | "model_version": { 25 | "id": "@modelVersionID", 26 | "created_at": "2018-01-23T19:25:09.618692Z", 27 | "status": { 28 | "code": 21100, 29 | "description": "Model trained successfully" 30 | }, 31 | "train_stats": {} 32 | }, 33 | "display_name": "Concept" 34 | }, 35 | "input": { 36 | "id": "@inputID", 37 | "data": { 38 | "video": { 39 | "url": "https://some-image-url" 40 | } 41 | } 42 | }, 43 | "data": { 44 | "frames": [ 45 | { 46 | "frame_info": { 47 | "index": 0, 48 | "time": 0 49 | }, 50 | "data": { 51 | "concepts": [ 52 | { 53 | "id": "@conceptID1", 54 | "name": "@conceptNAME1", 55 | "value": 0.99452126, 56 | "app_id": "main" 57 | }, 58 | { 59 | "id": "@conceptID2", 60 | "name": "@conceptNAME1", 61 | "value": 0.005478708, 62 | "app_id": "main" 63 | } 64 | ] 65 | } 66 | } 67 | ] 68 | } 69 | } 70 | ] 71 | } 72 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictDemographics_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url" 7 | } 8 | } 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictEmbedding_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url" 7 | } 8 | } 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictEmbedding_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "outputs": [ 7 | { 8 | "id": "@outputID", 9 | "status": { 10 | "code": 10000, 11 | "description": "Ok" 12 | }, 13 | "created_at": "2019-01-30T15:53:21.949095428Z", 14 | "model": { 15 | "id": "@modelID", 16 | "name": "general", 17 | "created_at": "2016-06-17T22:01:04.144732Z", 18 | "app_id": "main", 19 | "output_info": { 20 | "message": "Show output_info with: GET /models/{model_id}/output_info", 21 | "type": "embed", 22 | "type_ext": "embed" 23 | }, 24 | "model_version": { 25 | "id": "@modelVersionID", 26 | "created_at": "2016-07-13T01:19:12.147644Z", 27 | "status": { 28 | "code": 21100, 29 | "description": "Model trained successfully" 30 | }, 31 | "train_stats": {} 32 | }, 33 | "display_name": "General Embedding" 34 | }, 35 | "input": { 36 | "id": "@inputID", 37 | "data": { 38 | "image": { 39 | "url": "https://some-image-url" 40 | } 41 | } 42 | }, 43 | "data": { 44 | "embeddings": [ 45 | { 46 | "vector": [ 47 | 0.1, 48 | 0.2, 49 | 0.3 50 | ], 51 | "num_dimensions": 3 52 | } 53 | ] 54 | } 55 | } 56 | ] 57 | } 58 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictFaceConcepts_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url" 7 | } 8 | } 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictFaceEmbedding_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url" 7 | } 8 | } 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictFaceEmbedding_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "outputs": [ 7 | { 8 | "id": "@outputID", 9 | "status": { 10 | "code": 10000, 11 | "description": "Ok" 12 | }, 13 | "created_at": "2019-01-30T16:28:58.518441695Z", 14 | "model": { 15 | "id": "@modelID", 16 | "name": "face", 17 | "created_at": "2016-10-25T19:30:38.541073Z", 18 | "app_id": "main", 19 | "output_info": { 20 | "message": "Show output_info with: GET /models/{model_id}/output_info", 21 | "type": "embed", 22 | "type_ext": "detect-embed" 23 | }, 24 | "model_version": { 25 | "id": "@modelVersionID", 26 | "created_at": "2016-10-25T19:30:38.541073Z", 27 | "status": { 28 | "code": 21100, 29 | "description": "Model trained successfully" 30 | }, 31 | "train_stats": {} 32 | }, 33 | "display_name": "Face Embedding" 34 | }, 35 | "input": { 36 | "id": "@inputID", 37 | "data": { 38 | "image": { 39 | "url": "https://some-image-url" 40 | } 41 | } 42 | }, 43 | "data": { 44 | "regions": [ 45 | { 46 | "id": "@regionID", 47 | "region_info": { 48 | "bounding_box": { 49 | "top_row": 0.1, 50 | "left_col": 0.2, 51 | "bottom_row": 0.3, 52 | "right_col": 0.4 53 | } 54 | }, 55 | "data": { 56 | "embeddings": [ 57 | { 58 | "vector": [ 59 | 0.1, 60 | 0.2, 61 | 0.3 62 | ], 63 | "num_dimensions": 3 64 | } 65 | ] 66 | } 67 | } 68 | ] 69 | } 70 | } 71 | ] 72 | } 73 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictLogo_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url" 7 | } 8 | } 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictLogo_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "outputs": [ 7 | { 8 | "id": "@outputID", 9 | "status": { 10 | "code": 10000, 11 | "description": "Ok" 12 | }, 13 | "created_at": "2019-01-30T16:45:27.083256618Z", 14 | "model": { 15 | "id": "@modelID", 16 | "name": "logo", 17 | "created_at": "2017-03-06T22:57:00.707216Z", 18 | "app_id": "main", 19 | "output_info": { 20 | "message": "Show output_info with: GET /models/{model_id}/output_info", 21 | "type": "detect-concept", 22 | "type_ext": "detect-concept" 23 | }, 24 | "model_version": { 25 | "id": "@modelVersionID", 26 | "created_at": "2017-03-06T22:57:05.625525Z", 27 | "status": { 28 | "code": 21100, 29 | "description": "Model trained successfully" 30 | }, 31 | "train_stats": {} 32 | }, 33 | "display_name": "Logo" 34 | }, 35 | "input": { 36 | "id": "@inputID", 37 | "data": { 38 | "image": { 39 | "url": "https://some-image-url" 40 | } 41 | } 42 | }, 43 | "data": { 44 | "regions": [ 45 | { 46 | "id": "@regionID", 47 | "region_info": { 48 | "bounding_box": { 49 | "top_row": 0.1, 50 | "left_col": 0.2, 51 | "bottom_row": 0.3, 52 | "right_col": 0.4 53 | } 54 | }, 55 | "data": { 56 | "concepts": [ 57 | { 58 | "id": "@conceptID1", 59 | "name": "I Can't Believe It's Not Butter", 60 | "value": 0.092014045 61 | }, 62 | { 63 | "id": "@conceptID2", 64 | "name": "Pepsi", 65 | "value": 0.06332539 66 | } 67 | ] 68 | } 69 | } 70 | ] 71 | } 72 | } 73 | ] 74 | } 75 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictVideo_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url" 7 | } 8 | } 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictVideo_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "outputs": [ 7 | { 8 | "id": "@outputID", 9 | "status": { 10 | "code": 10000, 11 | "description": "Ok" 12 | }, 13 | "created_at": "2019-01-30T16:52:30.993694779Z", 14 | "model": { 15 | "id": "@modelID", 16 | "name": "nsfw-v1.0", 17 | "created_at": "2016-09-17T22:18:59.955626Z", 18 | "app_id": "main", 19 | "output_info": { 20 | "message": "Show output_info with: GET /models/{model_id}/output_info", 21 | "type": "concept", 22 | "type_ext": "concept" 23 | }, 24 | "model_version": { 25 | "id": "@modelVersionID", 26 | "created_at": "2018-01-23T19:25:09.618692Z", 27 | "status": { 28 | "code": 21100, 29 | "description": "Model trained successfully" 30 | }, 31 | "train_stats": {} 32 | }, 33 | "display_name": "NSFW" 34 | }, 35 | "input": { 36 | "id": "@inputID", 37 | "data": { 38 | "video": { 39 | "url": "https://some-image-url" 40 | } 41 | } 42 | }, 43 | "data": { 44 | "frames": [ 45 | { 46 | "frame_info": { 47 | "index": 0, 48 | "time": 0 49 | }, 50 | "data": { 51 | "concepts": [ 52 | { 53 | "id": "@conceptID1", 54 | "name": "sfw", 55 | "value": 0.99452126, 56 | "app_id": "main" 57 | }, 58 | { 59 | "id": "@conceptID2", 60 | "name": "nsfw", 61 | "value": 0.005478708, 62 | "app_id": "main" 63 | } 64 | ] 65 | } 66 | } 67 | ] 68 | } 69 | } 70 | ] 71 | } 72 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictWithArguments_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url" 7 | } 8 | } 9 | } 10 | ], 11 | "model": { 12 | "output_info": { 13 | "output_config": { 14 | "language": "de", 15 | "max_concepts": 3, 16 | "min_value": 0.98 17 | } 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictWithArguments_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "outputs": [ 7 | { 8 | "id": "@outputID", 9 | "status": { 10 | "code": 10000, 11 | "description": "Ok" 12 | }, 13 | "created_at": "2019-01-29T17:15:32.450063489Z", 14 | "model": { 15 | "id": "@modelID", 16 | "name": "@modelName", 17 | "created_at": "2016-03-09T17:11:39.608845Z", 18 | "app_id": "main", 19 | "output_info": { 20 | "message": "Show output_info with: GET /models/{model_id}/output_info", 21 | "type": "concept", 22 | "type_ext": "concept" 23 | }, 24 | "model_version": { 25 | "id": "@modelVersionID", 26 | "created_at": "2016-07-13T01:19:12.147644Z", 27 | "status": { 28 | "code": 21100, 29 | "description": "Model trained successfully" 30 | }, 31 | "train_stats": {} 32 | }, 33 | "display_name": "General" 34 | }, 35 | "input": { 36 | "id": "@inputID", 37 | "data": { 38 | "image": { 39 | "url": "https://some-image-url" 40 | } 41 | } 42 | }, 43 | "data": { 44 | "concepts": [ 45 | { 46 | "id": "@conceptID1", 47 | "name": "menschen", 48 | "value": 0.9963381, 49 | "app_id": "main" 50 | }, 51 | { 52 | "id": "@conceptID2", 53 | "name": "ein", 54 | "value": 0.9879057, 55 | "app_id": "main" 56 | }, 57 | { 58 | "id": "@conceptID3", 59 | "name": "Porträt", 60 | "value": 0.98490834, 61 | "app_id": "main" 62 | } 63 | ] 64 | } 65 | } 66 | ] 67 | } 68 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictWithInvalidURL_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-invalid-url" 7 | } 8 | } 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictWithInvalidURL_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10020, 4 | "description": "Failure" 5 | }, 6 | "outputs": [ 7 | { 8 | "id": "@outputID", 9 | "status": { 10 | "code": 30002, 11 | "description": "Download failed; check URL", 12 | "details": "404 Client Error: Not Found for url: https://some-invalid-url" 13 | }, 14 | "created_at": "2019-01-20T19:39:15.460417224Z", 15 | "model": { 16 | "id": "@modelID", 17 | "name": "color", 18 | "created_at": "2016-05-11T18:05:45.924367Z", 19 | "app_id": "main", 20 | "output_info": { 21 | "message": "Show output_info with: GET /models/{model_id}/output_info", 22 | "type": "color", 23 | "type_ext": "color" 24 | }, 25 | "model_version": { 26 | "id": "@modelVersionID", 27 | "created_at": "2016-07-13T01:19:12.147644Z", 28 | "status": { 29 | "code": 21100, 30 | "description": "Model trained successfully" 31 | }, 32 | "train_stats": {} 33 | }, 34 | "display_name": "Color" 35 | }, 36 | "input": { 37 | "id": "@inputID", 38 | "data": { 39 | "image": { 40 | "url": "https://some-invalid-url" 41 | } 42 | } 43 | }, 44 | "data": {} 45 | } 46 | ] 47 | } 48 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictWithUnknownFields_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url" 7 | } 8 | } 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test/resources/predictWithUnknownFields_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok", 5 | "unknown_field": "val" 6 | }, 7 | "outputs": [{ 8 | "id": "@outputID", 9 | "status": { 10 | "code": 10000, 11 | "description": "Ok" 12 | }, 13 | "created_at": "2017-11-17T19:32:58.760477937Z", 14 | "model": { 15 | "id": "@modelID", 16 | "name": "@modelName", 17 | "created_at": "2016-03-09T17:11:39.608845Z", 18 | "app_id": "main", 19 | "output_info": { 20 | "message": "Show output_info with: GET /models/{model_id}/output_info", 21 | "type": "concept", 22 | "type_ext": "concept", 23 | "unknown_field": "val" 24 | }, 25 | "model_version": { 26 | "id": "@modelVersionID", 27 | "created_at": "2016-07-13T01:19:12.147644Z", 28 | "status": { 29 | "code": 21100, 30 | "description": "Model trained successfully" 31 | }, 32 | "unknown_field": "val" 33 | }, 34 | "display_name": "@modelDisplayName", 35 | "unknown_field": "val" 36 | }, 37 | "input": { 38 | "id": "@inputID", 39 | "data": { 40 | "image": { 41 | "url": "https://some-image-url", 42 | "unknown_field": "val" 43 | }, 44 | "unknown_field": "val" 45 | }, 46 | "unknown_field": "val" 47 | }, 48 | "data": { 49 | "concepts": [{ 50 | "id": "@conceptID1", 51 | "name": "@conceptName1", 52 | "value": 0.99, 53 | "app_id": "main", 54 | "unknown_field": "val" 55 | }, { 56 | "id": "@conceptID2", 57 | "name": "@conceptName2", 58 | "value": 0.98, 59 | "app_id": "main", 60 | "unknown_field": "val" 61 | }], 62 | "unknown_field": "val" 63 | }, 64 | "unknown_field": "val" 65 | }] 66 | } 67 | -------------------------------------------------------------------------------- /tests/src/test/resources/predict_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url" 7 | } 8 | } 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test/resources/predict_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "outputs": [{ 7 | "id": "@outputID", 8 | "status": { 9 | "code": 10000, 10 | "description": "Ok" 11 | }, 12 | "created_at": "2017-11-17T19:32:58.760477937Z", 13 | "model": { 14 | "id": "@modelID", 15 | "name": "@modelName", 16 | "created_at": "2016-03-09T17:11:39.608845Z", 17 | "app_id": "main", 18 | "output_info": { 19 | "message": "Show output_info with: GET /models/{model_id}/output_info", 20 | "type": "concept", 21 | "type_ext": "concept" 22 | }, 23 | "model_version": { 24 | "id": "@modelVersionID", 25 | "created_at": "2016-07-13T01:19:12.147644Z", 26 | "status": { 27 | "code": 21100, 28 | "description": "Model trained successfully" 29 | } 30 | }, 31 | "display_name": "@modelDisplayName" 32 | }, 33 | "input": { 34 | "id": "@inputID", 35 | "data": { 36 | "image": { 37 | "url": "https://some-image-url" 38 | } 39 | } 40 | }, 41 | "data": { 42 | "concepts": [{ 43 | "id": "@conceptID1", 44 | "name": "@conceptName1", 45 | "value": 0.99, 46 | "app_id": "main" 47 | }, { 48 | "id": "@conceptID2", 49 | "name": "@conceptName2", 50 | "value": 0.98, 51 | "app_id": "main" 52 | }] 53 | } 54 | }] 55 | } 56 | -------------------------------------------------------------------------------- /tests/src/test/resources/removeConceptsForInputs_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "id": "@inputID", 5 | "data": { 6 | "concepts": [ 7 | { 8 | "id": "@concept2", 9 | "value": 0 10 | } 11 | ] 12 | } 13 | } 14 | ], 15 | "action": "remove" 16 | } 17 | -------------------------------------------------------------------------------- /tests/src/test/resources/removeConceptsForInputs_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "inputs": [ 7 | { 8 | "id": "@inputID", 9 | "data": { 10 | "image": { 11 | "url": "https://some-image-url" 12 | }, 13 | "concepts": [ 14 | { 15 | "id": "@concept1", 16 | "name": "@concept1", 17 | "value": 1, 18 | "app_id": "@appID" 19 | }, 20 | { 21 | "id": "@concept2", 22 | "value": 0, 23 | "app_id": "@appID" 24 | } 25 | ] 26 | }, 27 | "created_at": "2019-01-29T15:23:21.188492Z", 28 | "modified_at": "2019-01-29T15:23:21.575667Z", 29 | "status": { 30 | "code": 30200, 31 | "description": "Input image modification success" 32 | } 33 | } 34 | ] 35 | } 36 | -------------------------------------------------------------------------------- /tests/src/test/resources/runModelEvaluation_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model_version": { 7 | "id": "@modelVersionID", 8 | "created_at": "2017-01-01T00:00:00.000000Z", 9 | "status": { 10 | "code": 21100, 11 | "description": "Model trained successfully" 12 | }, 13 | "active_concept_count": 2, 14 | "metrics": { 15 | "status": { 16 | "code": 21303, 17 | "description": "Model is queued for evaluation." 18 | } 19 | }, 20 | "total_input_count": 30 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/src/test/resources/searchConceptsWithLanguage_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "concept_query": { 3 | "name": "狗*", 4 | "language": "zh" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /tests/src/test/resources/searchConceptsWithLanguage_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "concepts": [ 7 | { 8 | "id": "@conceptID1", 9 | "name": "狗", 10 | "value": 1, 11 | "created_at": "2016-03-17T11:43:01.223962Z", 12 | "language": "zh", 13 | "app_id": "main" 14 | }, 15 | { 16 | "id": "@conceptID2", 17 | "name": "狗仔队", 18 | "value": 1, 19 | "created_at": "2016-03-17T11:43:01.223962Z", 20 | "language": "zh", 21 | "app_id": "main" 22 | }, 23 | { 24 | "id": "@conceptID3", 25 | "name": "狗窝", 26 | "value": 1, 27 | "created_at": "2016-03-17T11:43:01.223962Z", 28 | "language": "zh", 29 | "app_id": "main" 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /tests/src/test/resources/searchConcepts_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "concept_query": { 3 | "name": "conc*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/src/test/resources/searchConcepts_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "concepts": [ 7 | { 8 | "id": "@conceptID1", 9 | "name": "concealer", 10 | "value": 1, 11 | "created_at": "2016-03-17T11:43:01.223962Z", 12 | "language": "en", 13 | "app_id": "main", 14 | "definition": "concealer" 15 | }, 16 | { 17 | "id": "@conceptID2", 18 | "name": "concentrate", 19 | "value": 1, 20 | "created_at": "2016-03-17T11:43:01.223962Z", 21 | "language": "en", 22 | "app_id": "main", 23 | "definition": "direct one's attention on something" 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /tests/src/test/resources/searchInputsByConceptID_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "query": { 3 | "ands": [ 4 | { 5 | "output": { 6 | "data": { 7 | "concepts": [ 8 | { 9 | "id": "@conceptID", 10 | "value": 1 11 | } 12 | ] 13 | } 14 | } 15 | } 16 | ] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/src/test/resources/searchInputsByConceptID_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "hits": [ 7 | { 8 | "score": 0.99, 9 | "input": { 10 | "id": "@inputID", 11 | "created_at": "2016-11-22T17:06:02Z", 12 | "data": { 13 | "image": { 14 | "url": "https://some-image-url" 15 | } 16 | }, 17 | "status": { 18 | "code": 30000, 19 | "description": "Download complete" 20 | } 21 | } 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /tests/src/test/resources/searchInputsByConceptName_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "query": { 3 | "ands": [ 4 | { 5 | "output": { 6 | "data": { 7 | "concepts": [ 8 | { 9 | "name": "@conceptName", 10 | "value": 1 11 | } 12 | ] 13 | } 14 | } 15 | } 16 | ] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/src/test/resources/searchInputsByConceptName_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "hits": [ 7 | { 8 | "score": 0.99, 9 | "input": { 10 | "id": "@inputID", 11 | "created_at": "2016-11-22T17:06:02Z", 12 | "data": { 13 | "image": { 14 | "url": "https://some-image-url" 15 | } 16 | }, 17 | "status": { 18 | "code": 30000, 19 | "description": "Download complete" 20 | } 21 | } 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /tests/src/test/resources/searchInputsByGeo_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "query": { 3 | "ands": [ 4 | { 5 | "input": { 6 | "data": { 7 | "geo": { 8 | "geo_point": { 9 | "longitude": 1.5, 10 | "latitude": -1 11 | }, 12 | "geo_limit": { 13 | "type": "withinKilometers", 14 | "value": 1 15 | } 16 | } 17 | } 18 | } 19 | } 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/src/test/resources/searchInputsByGeo_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "hits": [ 7 | { 8 | "score": 0.99, 9 | "input": { 10 | "id": "@inputID", 11 | "created_at": "2016-11-22T17:06:02Z", 12 | "data": { 13 | "image": { 14 | "url": "https://some-image-url" 15 | } 16 | }, 17 | "status": { 18 | "code": 30000, 19 | "description": "Download complete" 20 | } 21 | } 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /tests/src/test/resources/trainModel_request.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /tests/src/test/resources/trainModel_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "status": { 3 | "code": 10000, 4 | "description": "Ok" 5 | }, 6 | "model": { 7 | "id": "@modelID", 8 | "name": "@modelName", 9 | "created_at": "2019-01-20T15:51:21.641006Z", 10 | "app_id": "@appID", 11 | "output_info": { 12 | "output_config": { 13 | "concepts_mutually_exclusive": false, 14 | "closed_environment": false, 15 | "max_concepts": 0, 16 | "min_value": 0 17 | }, 18 | "message": "Show output_info with: GET /models/{model_id}/output_info", 19 | "type": "concept", 20 | "type_ext": "concept" 21 | }, 22 | "model_version": { 23 | "id": "@modelVersionID", 24 | "created_at": "2019-01-20T15:51:25.093744401Z", 25 | "status": { 26 | "code": 21103, 27 | "description": "Custom model is currently in queue for training, waiting on inputs to process." 28 | }, 29 | "active_concept_count": 2, 30 | "train_stats": {} 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/src/test/resources/workflowBatchPredict_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url1" 7 | } 8 | } 9 | }, 10 | { 11 | "data": { 12 | "image": { 13 | "url": "https://some-image-url2" 14 | } 15 | } 16 | } 17 | ], 18 | "output_config": { 19 | "max_concepts": 3, 20 | "min_value": 0.98 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/src/test/resources/workflowPredictWithBase64_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "base64": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z/C/HgAGgwJ/lK3Q6wAAAABJRU5ErkJggg==" 7 | } 8 | } 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tests/src/test/resources/workflowPredict_request.json: -------------------------------------------------------------------------------- 1 | { 2 | "inputs": [ 3 | { 4 | "data": { 5 | "image": { 6 | "url": "https://some-image-url" 7 | } 8 | } 9 | } 10 | ] 11 | } 12 | --------------------------------------------------------------------------------