Photo Recommendations¶
The API can recommend photos for an article. First, we need to see which photo banks are available for a given API Key:
const photos = async (config) => {
const response = await axios.get('photos', config);
return response.data;
};
photos(config).then(report);
def photos():
return requests.get(f'{BASE_URL}photos', headers=HEADERS).json()
photos()
['ctk', 'demo', 'shutterstock']
['ctk', 'demo', 'shutterstock']
We will pick the ctk
dataset and recommend photos for the same text as above:
const recommendPhotos = async (input, dataset, config) => {
const response = await axios.post(`photos/${dataset}/recommend`, input, config)
return response.data
};
const dataset = 'ctk';
const input = {
id: '1234',
title: 'Emmanuel Macron in Germany.',
text: 'Mr. Macron visited Berlin.',
recommendationCount: 2,
returnObjects: true, // Return PhotoData objects in addition to the photo IDs.
returnObjectFields: [
'name',
'description',
'url',
],
};
recommendPhotos(input, dataset, config).then(report);
def recommendPhotos(dataset: str, input: Mapping[str, Any]):
return requests.post(f'{BASE_URL}photos/{dataset}/recommend', json=input, headers=HEADERS).json()
dataset = 'ctk'
input = {
'id': '1234',
'title': 'Emmanuel Macron in Germany.',
'text': 'Mr. Macron visited Berlin.',
'recommendationCount': 5,
'returnObjects': True, # Return PhotoData objects in addition to the photo IDs.
'returnObjectFields': [
'name',
'description',
'url',
],
};
recommendPhotos(dataset, input)
Here is the simplified output:
{
id: '1234',
referenceKey: '211023-183731-e073c8c0',
photosIds: [ 'P2021102202885', 'P201904290731201' ],
photos: [
{
id: 'P2021102202885',
description: {
en: 'French President Emmanuel Macron arrives ...'
},
name: { cs: 'Emmanuel Macron' },
url: 'http://imultimedia.ctk.cz/storage/foto/P2021102202885/515x515.wm/P2021102202885.jpeg'
},
{
id: 'P201904290731201',
description: {
en: 'German Chancellor Angela Merkel welcomes President of France Emmanuel Macron ...'
},
name: { cs: 'Emmanuel Macron, prezident, politik, Angela Merkel ...' },
url: 'http://imultimedia.ctk.cz/storage/foto/P201904290731201/515x515.wm/P201904290731201.jpeg'
}
],
tags: [
{type: 'Geneea', value: 'G3052772', subType: 'person', description: 'Emmanuel Macron (G3052772)', score: 21.8421387408},
{type: 'Geneea', value: 'G567', subType: 'person', description: 'Angela Merkel (G567)', score: 12.1114189616},
{type: 'Geneea', value: 'G458', subType: 'organization', description: 'European Union (G458)', score: 14.5874189616},
{type: 'Geneea', value: 'G64', subType: 'location', description: 'Berlin (G64)', score: , score: 18.2413894616}
]
}
{
'id': '1234',
'referenceKey': '211023-183731-e073c8c0',
'photosIds': [ 'P2021102202885', 'P201904290731201' ],
'photos': [
{
'id': 'P2021102202885',
'description': {
'en': 'French President Emmanuel Macron arrives ...'
},
'name': { 'cs': 'Emmanuel Macron' },
'url': 'http://imultimedia.ctk.cz/storage/foto/P2021102202885/515x515.wm/P2021102202885.jpeg'
},
{
'id': 'P201904290731201',
'description': {
'en': 'German Chancellor Angela Merkel welcomes President of France Emmanuel Macron ...'
},
'name': { 'cs': 'Emmanuel Macron, prezident, politik, Angela Merkel ...' },
'url': 'http://imultimedia.ctk.cz/storage/foto/P201904290731201/515x515.wm/P201904290731201.jpeg'
}
],
'tags': [
{'type': 'Geneea', 'value': 'G3052772', 'subType': 'person', 'description': 'Emmanuel Macron (G3052772)', 'score': 21.8421387408},
{'type': 'Geneea', 'value': 'G567', 'subType': 'person', 'description': 'Angela Merkel (G567)', 'score': 12.1114189616},
{'type': 'Geneea', 'value': 'G458', 'subType': 'organization', 'description': 'European Union (G458)', 'score': 14.5874189616},
{'type': 'Geneea', 'value': 'G64', 'subType': 'location', 'description': 'Berlin (G64)', 'score': , 'score': 18.2413894616}
]
}
The output is mostly self-explanatory; tags can be used to further filter the results (which is more useful when asking for more than two photos).