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());
    }
  }
}

相关内容

热门资讯

普及知识!微信雀神麻将挂件开挂... 普及知识!微信雀神麻将挂件开挂辅助,微乐自建房脚本免费入口(开挂自建房)插件1、操作简单,无需微信雀...
一分钟揭秘!微乐家乡麻将自建房... 一分钟揭秘!微乐家乡麻将自建房辅助app,微乐自建房脚本免费入口(开挂自建房)脚本1、打开软件启动之...
热门推荐!微乐家乡麻将自建房辅... 热门推荐!微乐家乡麻将自建房辅助app,微乐家乡麻将自建房辅助app(开挂自建房)攻略1、微乐家乡麻...
发现一款!微乐自建房辅助工具,... 发现一款!微乐自建房辅助工具,微乐小程序免费黑科技(开挂自建房)软件1、全新机制【微乐自建房辅助工具...
揭秘一下!微乐家乡麻将自建房辅... 揭秘一下!微乐家乡麻将自建房辅助app,微乐自建房脚本免费入口(开挂自建房)攻略在进入微乐家乡麻将自...
分享给玩家!微乐自建房辅助工具... 分享给玩家!微乐自建房辅助工具挂,微乐小程序免费黑科技(开挂自建房)教程1、下载好微乐自建房辅助工具...
实测揭晓!微乐家乡麻将自建房辅... 实测揭晓!微乐家乡麻将自建房辅助app,微乐家乡麻将自建房辅助app(开挂自建房)插件1、进入游戏-...
终于知道!微信卡五星辅助器,微... 终于知道!微信卡五星辅助器,微乐小程序免费黑科技(开挂自建房)插件1、完成微信卡五星辅助器有辅助插件...
今日百科!微乐自建房辅助工具插... 今日百科!微乐自建房辅助工具插件,微乐自建房脚本免费入口(开挂自建房)工具1、微乐自建房辅助工具插件...
最新通报!微乐家乡麻将自建房辅... 最新通报!微乐家乡麻将自建房辅助app,微乐家乡麻将自建房辅助app(开挂自建房)脚本1、不需要AI...