Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

ComputerVisionErrorResponseException: (InvalidRequest) Invalid request has been sent.

Não estou conseguindo rodar a linha "analise_celebridades = client.analyze_image_by_domain("celebrities", url,"en")".

Segue o código:

!pip install azure-cognitiveservices-vision-computervision

from azure.cognitiveservices.vision.computervision import ComputerVisionClient

from msrest.authentication import CognitiveServicesCredentials

credenciais = CognitiveServicesCredentials("d24e62705a3a4e925c4ceb30e04b40f6")

client = ComputerVisionClient("https://cv-test-alura.cognitiveservices.azure.com/", credenciais)

client.api_version

'3.2'

from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes

url = "http://pbs.twimg.com/media/ECx6hK-WwAAPzeE.jpg"

analise_de_imagem = client.analyze_image(url, [VisualFeatureTypes.tags])

for tag in analise_de_imagem.tags:
  print(tag)

{'additional_properties': {}, 'name': 'human face', 'confidence': 0.9983632564544678, 'hint': None}
{'additional_properties': {}, 'name': 'person', 'confidence': 0.9910241365432739, 'hint': None}
{'additional_properties': {}, 'name': 'clothing', 'confidence': 0.9850200414657593, 'hint': None}
{'additional_properties': {}, 'name': 'nightclub', 'confidence': 0.9796069264411926, 'hint': None}
{'additional_properties': {}, 'name': 'smile', 'confidence': 0.9596958160400391, 'hint': None}
{'additional_properties': {}, 'name': 'magenta', 'confidence': 0.9069244265556335, 'hint': None}
{'additional_properties': {}, 'name': 'disco', 'confidence': 0.8865774273872375, 'hint': None}
{'additional_properties': {}, 'name': 'purple', 'confidence': 0.8797036409378052, 'hint': None}
{'additional_properties': {}, 'name': 'violet', 'confidence': 0.8554173111915588, 'hint': None}
{'additional_properties': {}, 'name': 'indoor', 'confidence': 0.6854885220527649, 'hint': None}
{'additional_properties': {}, 'name': 'woman', 'confidence': 0.5566776394844055, 'hint': None}

analise_celebridades = client.analyze_image_by_domain("celebrities", url,"en")

Esse é o erro que está aparecendo:

ComputerVisionErrorResponseException      Traceback (most recent call last)
<ipython-input-71-8455effbf10c> in <module>()
----> 1 analise_celebridades = client.analyze_image_by_domain("celebrities", url,"en")

/usr/local/lib/python3.7/dist-packages/azure/cognitiveservices/vision/computervision/operations/_computer_vision_client_operations.py in analyze_image_by_domain(self, model, url, language, model_version, custom_headers, raw, **operation_config)
    422 
    423         if response.status_code not in [200]:
--> 424             raise models.ComputerVisionErrorResponseException(self._deserialize, response)
    425 
    426         deserialized = None

ComputerVisionErrorResponseException: (InvalidRequest) Invalid request has been sent.

O que pode ser?

2 respostas
solução!

Atualização:

mudei a região da instância para eastus

agora o erro está diferente:

ComputerVisionErrorResponseException      Traceback (most recent call last)
<ipython-input-10-8455effbf10c> in <module>()
----> 1 analise_celebridades = client.analyze_image_by_domain("celebrities", url,"en")

/usr/local/lib/python3.7/dist-packages/azure/cognitiveservices/vision/computervision/operations/_computer_vision_client_operations.py in analyze_image_by_domain(self, model, url, language, model_version, custom_headers, raw, **operation_config)
    422 
    423         if response.status_code not in [200]:
--> 424             raise models.ComputerVisionErrorResponseException(self._deserialize, response)
    425 
    426         deserialized = None

ComputerVisionErrorResponseException: (InvalidRequest) Feature is not supported. Please apply for access at https://aka.ms/celebrityrecognition

Ou seja, é preciso seguir as instruções encontradas em https://aka.ms/celebrityrecognition para ter acesso a essa funcionalidade.

Tive o mesmo problema. Agora parece ser obrigatório se aplicar pra poder utilizar: Insira aqui a descrição dessa imagem para ajudar na acessibilidade