none
在Azure 上怎样运行Python 3程序 RRS feed

  • 问题

  • 刚开始学Azure 和 Python. 打算调用 azure.cognitiveservices.language.textanalytics 里面的 TextAnalyticsClient 做一个sentiment analysis 的简单分析. 文本如下:

    from azure.cognitiveservices.language.textanalytics import TextAnalyticsClient
    from msrest.authentication import CognitiveServicesCredentials

    my_endpoint = 'END_POIND'
    subscription_key = 'KEY'
    my_credentials = CognitiveServicesCredentials(subscription_key)

    text_analytics = TextAnalyticsClient(endpoint=my_endpoint, credentials=my_credentials)

    documents = [
        {
            "id": "1",
            "language": "en",
            "text": "This the best day of my life."
        },
    {
         "id": "2",
            "language": "en",
            "text": "what a day!"
        } 
    ]

    response = text_analytics.sentiment(documents=documents)

    for document in response.documents:
        print("Document Id: ", document.id, ", Sentiment Score: ",
              "{:.2f}".format(document.score))

    怎样Azure 上跑这段程序呢? 试过 Azure Runbook, 在以下这两条import上报错了. 请指教. 多谢!

    from azure.cognitiveservices.language.textanalytics import TextAnalyticsClient
    from msrest.authentication import CognitiveServicesCredentials

    2019年10月1日 6:06