Wednesday, January 29, 2025

Azure AI services - Use an Azure AI Services Container

 Azure AI services - Use an Azure AI Services Container:

Source : https://github.com/MicrosoftLearning/mslearn-ai-services

Create these two services in Azure.
1. Azure AI services multi-service account
2. Azure Container Instances

2. Azure Container Instances:
az container create --resource-group <your-resource-Group> --name whizcontaineryourname --image mcr.microsoft.com/azure-cognitive-services/textanalytics/sentiment:latest --os-type Linux --cpu 1 --memory 8 --dns-name-label whizdnnsyourname --ports 5000 --location eastus --restart-policy OnFailure --secure-environment-variables ApiKey=<your-Api-key> Billing=<endpoint> --environment-variables Eula=accept --ip-address Public

az container create --resource-group rg1 --name sreecontainer1 --image mcr.microsoft.com/azure-cognitive-services/textanalytics/sentiment:latest --os-type Linux --cpu 1 --memory 8 --dns-name-label sreednns1 --ports 5000 --location eastus --restart-policy OnFailure --secure-environment-variables ApiKey=AjShjnYv3s56NZNIAkHBni7RCPQCOGAIif Billing=https://sreemultiserviceaccount1.cognitiveservices.azure.com/ --environment-variables Eula=accept --ip-address Public

For Docker:
docker run --rm -it -p 5000:5000 --memory 8g --cpus 1 mcr.microsoft.com/azure-cognitive-services/textanalytics/sentiment:latest Eula=accept Billing=<yourEndpoint> ApiKey=<yourKey>
 
Testing:
curl -X POST "http://<your_ACI_IP_address_or_FQDN>:5000/text/analytics/v3.1/sentiment" -H "Content-Type: application/json" --data-ascii "{'documents':[{'id':1,'text':'The performance was amazing! The sound could have been clearer.'},{'id':2,'text':'The food and service were unacceptable. While the host was nice, the waiter was rude and food was cold.'}]}"

curl -X POST "http://sreednns1.eastus.azurecontainer.io:5000/text/analytics/v3.1/sentiment" -H "Content-Type: application/json" --data-ascii "{'documents':[{'id':1,'text':'The performance was amazing! The sound could have been clearer.'},{'id':2,'text':'The food and service were unacceptable. While the host was nice, the waiter was rude and food was cold.'}]}"

OutPut:

{  
  "documents": [  
    {  
      "id": "1",  
      "sentiment": "positive",  
      "confidenceScores": {  
        "positive": 0.99,  
        "neutral": 0.0,  
        "negative": 0.0  
      },  
      "sentences": [  
        {  
          "sentiment": "positive",  
          "confidenceScores": {  
            "positive": 0.99,  
            "neutral": 0.0,  
            "negative": 0.0  
          },  
          "offset": 0,  
          "length": 29,  
          "text": "The performance was amazing! "  
        },  
        {  
          "sentiment": "neutral",  
          "confidenceScores": {  
            "positive": 0.19,  
            "neutral": 0.47,  
            "negative": 0.34  
          },  
          "offset": 29,  
          "length": 34,  
          "text": "The sound could have been clearer."  
        }  
      ],  
      "warnings": []  
    },  
    {  
      "id": "2",  
      "sentiment": "negative",  
      "confidenceScores": {  
        "positive": 0.0,  
        "neutral": 0.01,  
        "negative": 0.98  
      },  
      "sentences": [  
        {  
          "sentiment": "negative",  
          "confidenceScores": {  
            "positive": 0.0,  
            "neutral": 0.01,  
            "negative": 0.99  
          },  
          "offset": 0,  
          "length": 40,  
          "text": "The food and service were unacceptable. "  
        },  
        {  
          "sentiment": "negative",  
          "confidenceScores": {  
            "positive": 0.0,  
            "neutral": 0.02,  
            "negative": 0.98  
          },  
          "offset": 40,  
          "length": 63,  
          "text": "While the host was nice, the waiter was rude and food was cold."  
        }  
      ],  
      "warnings": []  
    }  
  ],  
  "errors": []  
}


No comments:

Post a Comment

Featured Post

Azure AI services - Recognize and synthesize speech

Azure AI services - Recognize and synthesize speech: 1. Create 'Speech service' in Azure C# Code: using System; using System.Threa...

Popular posts