You can use the following code to identify the product present in a given image:
import requests
API_KEY = '...'
PROJECT = '...'
URI = f'https://productstudio.googleapis.com/v1/projects/{PROJECT}'
API_ENDPOINT = f'{URI}:generateProductText'
def product_name_from_image(image_url):
payload = {}
payload |= {'output_spec': {'workflow_id': 'comprehensive_title', 'attribute_order': ['product']}}
payload |= {'product_info':{'product_attributes': {}}}
payload['product_info'] |= {'product_image':{'uri':image_url}}
response = requests.post(API_ENDPOINT, params={'key': API_KEY}, json=payload)
return response.json()['title']['text']
# Toy Horse
print(product_name_from_image('https://upload.wikimedia.org/wikipedia/commons/thumb/1/15/Little_horse_on_wheels_%28Ancient_greek_child%27s_Toy%29.jpg/255px-Little_horse_on_wheels_%28Ancient_greek_child%27s_Toy%29.jpg'))