AutoMLJavaSDK支持私有服务端点的
创始人
2024-09-23 19:30:43
0

使用以下代码示例,使用AutoML Java SDK与私有服务终端点进行通信:

import com.google.cloud.automl.v1beta1.AutoMlClient;
import com.google.cloud.automl.v1beta1.AutoMlSettings;
import com.google.cloud.automl.v1beta1.PredictResponse;
import com.google.cloud.automl.v1beta1.PredictionServiceClient;
import com.google.cloud.automl.v1beta1.PredictionServiceSettings;
import com.google.protobuf.ByteString;

import java.util.logging.Logger;

public class AutomlPredict {

  private static final Logger LOGGER = Logger.getLogger(AutomlPredict.class.getName());
  private static final String PROJECT_ID = "YOUR_PROJECT_ID";
  private static final String MODEL_ID = "YOUR_MODEL_ID";
  private static final String CONTENT = "YOUR_CONTENT";
  private static final String REGION = "YOUR_REGION";
  private static final String ENDPOINT = "YOUR_ENDPOINT";

  public static void main(String[] args) {
    try {
      // Initialize client that will be used to send requests. This client only needs to be created
      // once, and can be reused for multiple requests. After completing all of your requests, call
      // the "close" method on the client to safely clean up any remaining background resources.
      PredictionServiceClient client;
      try {
        PredictionServiceSettings predictionServiceSettings =
            PredictionServiceSettings.newBuilder()
                .setEndpoint(ENDPOINT + ":443")
                .build();
        client = PredictionServiceClient.create(predictionServiceSettings);
      } catch (Exception e) {
        LOGGER.warning(e.getMessage());
        return;
      }

      // Get the full path of the model.
      String modelFullId = String.format("projects/%s/locations/%s/models/%s", PROJECT_ID, REGION, MODEL_ID);

      // Prepare the content to be predicted.
      ByteString content = ByteString.copyFromUtf8(CONTENT);

      // Use the client to send the prediction request.
      PredictResponse response = client.predict(modelFullId, content);

      // Print the response.
      LOGGER.info("Prediction Results:");
      LOGGER.info(response.toString());

      // Shut down the client.
      client.close();
    } catch (Exception e) {
      LOGGER.warning(e.getMessage());
    }
  }
}

相关内容

热门资讯

十分钟实锤!德扑之星猫腻(德州... 十分钟实锤!德扑之星猫腻(德州nzt)真是有挂(详细辅助2025新版教程);1、进入到德扑之星猫腻黑...
九分钟实锤!德州之星辅助(德州... 九分钟实锤!德州之星辅助(德州扑克)真是是真的有挂(详细辅助新2025教程)1、很好的工具软件,可以...
第十分钟实锤!德扑之星ai代打... 第十分钟实锤!德扑之星ai代打(wepower德州)一贯真的有挂(详细辅助辅助教程);1、构建自己的...
9分钟实锤!德州ai辅助软件(... 9分钟实锤!德州ai辅助软件(德州之星)总是是真的有挂(详细辅助规律教程)所有人都在同一条线上,像星...
2分钟实锤!德州AI智能辅助机... 2分钟实锤!德州AI智能辅助机器人(德扑ai)一贯有挂(详细辅助线上教程)1、首先打开德州AI智能辅...
九分钟实锤!智星德州菠萝有挂吗... 九分钟实锤!智星德州菠萝有挂吗(德州ai)一直真的是有挂(详细辅助介绍教程)1、智星德州菠萝有挂吗透...
九分钟实锤!德州之星有外挂(来... 九分钟实锤!德州之星有外挂(来玩德州)其实存在有挂(详细辅助科技教程)1、下载好德州之星有外挂辅助软...
第7分钟实锤!德州之星外挂(来... 第7分钟实锤!德州之星外挂(来玩德州)确实真的是有挂(详细辅助高科技教程)1、进入到德州之星外挂黑科...
三分钟实锤!德扑数据软件(德州... 三分钟实锤!德扑数据软件(德州机器人)其实是真的有挂(详细辅助新2025教程)1、许多玩家不知道德扑...
第四分钟实锤!德扑ai智能机器... 第四分钟实锤!德扑ai智能机器人(nzt德州)竟然真的有挂(详细辅助解密教程)运德扑ai智能机器人辅...