Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
Huawei Cloud Astro Canvas
Huawei Cloud Astro Zero
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Connecting to ModelArts to Recognize Images and Text

Updated on 2025-03-24 GMT+08:00

ModelArts is a one-stop AI development platform geared toward developers and data scientists of all skill levels. It enables you to rapidly build, train, and deploy models anywhere (from the cloud to the edge), and manage full-lifecycle AI workflows. ModelArts accelerates AI development and fosters AI innovation with key capabilities, including data preprocessing and auto labeling, distributed training, automated model building, and one-click workflow executing.

You can connect your applications to ModelArts to enable image and text recognition in AI scenarios, such as identifying flower varieties.

Prerequisites

  • You have obtained the access key ID (AK) and secret access key (SK). For details, see Obtaining an AK/SK.
  • You have created and deployed a flower recognition model in ModelArts.

Creating a ModelArts Connector

  1. Log in to the application designer by referring to Logging In to the Application Designer.
  2. In the navigation pane, choose Integrations.
  3. Click Connector Instance under Connector.
  4. In the navigation pane on the left, choose AI > ModelArts.
  5. In the right pane, click + and set the parameters.

    Figure 1 Creating ModelArts
    Table 1 Parameters for creating a ModelArts connector

    Parameter

    Description

    Name

    Name of the connector to be created. The naming requirements are as follows:

    • The value cannot exceed 64 characters, including the prefix namespace.

      The content before the name is the namespace. To avoid duplicate data names among different tenants in Astro Zero, a tenant needs to define a namespace when creating an application for the first time. A tenant can create only one namespace. After being created, the namespace cannot be modified.

    • Start with a letter and can contain only letters, digits, and underscores (_). Do not end with an underscore (_).

    Access Key ID

    The AK and the secret access key (SK) are used together to encrypt and sign a request. Set this parameter to the value of AK in Prerequisites.

    Secret Access Key

    Secret access key is used together with the access key ID to encrypt the request, identify the sender, and prevent the request from being tempered. Set this parameter to the value of AK in Prerequisites.

    Region

    Select the region of ModelArts.

    Project ID

    Project ID corresponding to the region where ModelArts is located.

    Description

    Enter the description of the connector.

    Value: 1–255 characters.

    Package Current Configuration

    If this parameter is selected, the connector (including the access key and key) will be packed together with applications. For example, if an application package is released to the runtime environment, the current configuration is synchronized to the runtime environment by default. If this option is not selected, the connector will not be packaged and released to the runtime environment. In this case, you need to create the corresponding connector by referring to Managing Connectors in Applications.

    This parameter is selected by default. You are advised not to select this option in information-sensitive scenarios.

  6. Click Save.
  7. (Optional) Test whether flower images can be recognized.

    1. Click Test on the connector details page.
    2. After setting the parameters, click Test.
      Choose Type: The object to be recognized can be an image or text. In this example, select Image File and upload the image.
      • Image URL: If the object to be recognized is an image, select Image URL and set the details.
      • Image File: If the object to be recognized is an image, select Image File and drag the image to the target area.
      • Text: If the object to be recognized is text, select Text and enter the specific text.
      • Is Api g Code: Used by Astro Zero to call services that have been brought online in ModelArts.
        1. The operations in Prerequisites have been performed.
        2. On the ModelArts management console and choose Service Deployment > Real-Time Services.
        3. Click the name of the target service. The service details page is displayed.
        4. On the Usage Guides tab of the service details page, check the API URL.
      • Model Id: ID of the service that has been brought online on the ModelArts console.
        1. The operations in Prerequisites have been performed.
        2. On the ModelArts management console and choose Service Deployment > Real-Time Services.
        3. Click the name of the target service. The service details page is displayed.
        4. Check the service ID.

Calling a Connector in a Script

Call the connector in the script to connect to ModelArts.

  1. Create an empty script by referring to Creating a Blank Script.
  2. In the script editor, enter the following code.

    import * as modelarts from 'modelarts';
    
    export class Input {
        @action.param({ type: "String", required: false, description: "the image url" })
        url: string;
    
        @action.param({ type: "String", required: false, description: "the base64 coded image" })
        image: string;
    
        @action.param({ type: "String", required: false, description: "" })
        apigCode: string
    
        @action.param({ type: "String", required: false, description: "" })
        modelId: string
    }
    
    export class Output {
        @action.param({ type: "string" })
        result: string;
    }
    
    
    export class testModelarts {
    
        @action.method({ input: "Input", output: "Output", description: "modelartspro test case" })
        run(input: Input): void {
            // Enter the name of the instantiated ModelArts Pro connector.
            let client = modelarts.newClient("testArts")
            let result = null
            result = client.modelArtsWithURL(input.url, input.apigCode, input.modelId);
            console.log(result)
            return result
        }
    }
    

    In modelarts.newClient("testArts"), "testArts" is the connector name. The code must include the namespace prefix if it is present in the connector name.

  3. Click in the upper part of the script editor to save the script.
  4. Click to execute the script.
  5. On the input parameter tab page at the bottom of the page, enter request parameters and click in the upper right corner of the test window.

    {
        "url": "https://XXXXXXXXX/testmodelarts.jpg",
        "apigCode": "bec274062225485b95fbcd4d6e8f128a",
        "modelId": "5ecac550-eefe-4437-9767-57eca07fa91f"
    }

    In the code, set url to the image URL.

  6. On the output parameter tab page, you can check the recognition result.

    {
        "predicted_label": "roses",
        "scores": [
            [
                "roses",
                "0.947"
            ],
            [
                "daisy",
                "0.050"
            ],
            [
                "tulips",
                "0.002"
            ],
            [
                "dandelion",
                "0.000"
            ],
            [
                "sunflowers",
                "0.000"
            ]
        ]
    }

  7. Click in the upper part of the script editor to activate the script.

Calling a Connector in a Flow

Call the connector in a flow to connect to ModelArts.

  1. Create a blank flow by referring to Creating a Blank Flow.
  2. Create the input and output parameters of the flow.

    The flow calls the ModelArts API. Therefore, the flow's input and output parameters must be defined and match the API's parameter types.
    Table 2 Flow variables

    Variable Type

    Parameter

    Parameter Type

    Input/Output Type

    Description

    Common

    image

    Text

    Input Only

    Base64-encoded image data.

    Common

    apigCode

    Text

    Input Only

    Model APIG code.

    Common

    modelID

    Text

    Input Only

    Model ID.

    Common

    result

    Any

    Output Only

    Output query result.

    Common

    error

    Text

    Output Only

    Error information.

    1. On the right of the flow designer, click .
    2. On the Context panel, click the plus sign (+) next to Variable.
      Figure 2 Creating a variable
    3. Change the variable name to image.
      Figure 3 Setting a variable
    4. Add other variables in Table 2, click the start diagram element , and set the input and output parameters of the flow on the right.
      Figure 4 Setting input and output parameters

  3. On the left of the flow design page, choose Connector > AI and drag the ModelArts diagram element to the canvas.

    The ModelArts diagram element is preset in the system for connecting to ModelArts.

    Figure 5 Dragging ModelArts diagram element to the canvas

  4. Select the ModelArts diagram element, click on the right, and select the testArts connector created in Creating a ModelArts Connector.
  5. Click and set action parameters.

    Figure 6 Configuring action parameters
    • Action: ModelArts API to be called. In this example, select modelarts_with_image.
      • modelarts_with_url: Identifies images based on image URLs.
      • modelarts_with_image: Identifies images based on image files.
      • modelarts_with_text: Recognizes text based on text information.
    • Input Parameters: Input parameters of the API. Select a parameter from Target and drag the corresponding variable in Context to Source.
    • Output Parameters: Output parameters of the API.
      • Select result from Source and drag result in Context to Target to receive the calling result.
      • Select error from Source and drag error in Context to Target to receive the error information.

  6. Connect the Start and ModelArts diagram elements.

    Figure 7 Connecting diagram elements

  7. Click to save the flow.
  8. Click to activate the flow.
  9. Set input parameters and click the run button.

    {
        "image": "https://XXXXXXXX/testmodelarts.jpg",
        "apigCode": "bec274062225485b95fbcd4d6e8f128a",
        "modelID": "5ecac550-eefe-4437-9767-57eca07fa91f"
    }

    In the code, image is the image URL. If the recognition result is displayed, the connector is successfully called.

    Figure 8 Output result

  10. Click in the upper part of the editor to activate the flow.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback