<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Python code to call ML Object Detection API in Artificial Intelligence Forum</title>
    <link>https://community.sap.com/t5/artificial-intelligence-forum/python-code-to-call-ml-object-detection-api/m-p/12075013#M130</link>
    <description>&lt;P&gt;Could someone please share an python example of how can we call the Object Detection API? It would help me a lot!&lt;/P&gt;</description>
    <pubDate>Sun, 04 Feb 2024 06:52:52 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2024-02-04T06:52:52Z</dc:date>
    <item>
      <title>Python code to call ML Object Detection API</title>
      <link>https://community.sap.com/t5/artificial-intelligence-forum/python-code-to-call-ml-object-detection-api/m-p/12075013#M130</link>
      <description>&lt;P&gt;Could someone please share an python example of how can we call the Object Detection API? It would help me a lot!&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2024 06:52:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/artificial-intelligence-forum/python-code-to-call-ml-object-detection-api/m-p/12075013#M130</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2024-02-04T06:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Python code to call ML Object Detection API</title>
      <link>https://community.sap.com/t5/artificial-intelligence-forum/python-code-to-call-ml-object-detection-api/m-p/12075014#M131</link>
      <description>&lt;P&gt;Hello Renan,
Here is some Python code that uses the face feature extractor of MLF.
It shows how to create and use the Bearer token and how to pass a file and the header to MLF.
So this might give you a start for object detection.&lt;/P&gt;&lt;P&gt;Greetings, Andreas&lt;/P&gt;&lt;P&gt;## Get logon credentials from service key&lt;/P&gt;&lt;P&gt;# Path to
service key&lt;/P&gt;&lt;P&gt;service_key_location
= "./Service Keys/Servicekey_beta.txt"&lt;/P&gt;&lt;P&gt;file_read =
open(service_key_location, "r") &lt;/P&gt;&lt;P&gt;jsonRead =
json.loads(file_read.read())&lt;/P&gt;&lt;P&gt;username =
jsonRead["clientid"]&lt;/P&gt;&lt;P&gt;password =
jsonRead["clientsecret"]&lt;/P&gt;&lt;P&gt;## Get
Bearer token&lt;/P&gt;&lt;P&gt;import json&lt;/P&gt;&lt;P&gt;import
requests&lt;/P&gt;&lt;P&gt;api_url =
'https://[yoururl].authentication.us10.hana.ondemand.com/oauth/token?grant_type=client_credentials'&lt;/P&gt;&lt;P&gt;auth_values
= (username, password)&lt;/P&gt;&lt;P&gt;response =
requests.get(api_url, auth=auth_values)&lt;/P&gt;&lt;P&gt;# Extract token
from response&lt;/P&gt;&lt;P&gt;json_response
= response.json()&lt;/P&gt;&lt;P&gt;api_token =
"Bearer " + json_response["access_token"]&lt;/P&gt;&lt;P&gt;print(api_token)&lt;/P&gt;&lt;P&gt;## Identify
face on image&lt;/P&gt;&lt;P&gt;# Obtain
feature vector of face&lt;/P&gt;&lt;P&gt;nugget_file
= "./image.jpg"&lt;/P&gt;&lt;P&gt;api_url =
'https://mlfproduction-face-feature-extractor.cfapps.us10.hana.ondemand.com/api/v2alpha1/image/face-feature-extraction'&lt;/P&gt;&lt;P&gt;files =
{'files': open(nugget_file, 'rb')}&lt;/P&gt;&lt;P&gt;headers =
{'Authorization': api_token}&lt;/P&gt;&lt;P&gt;response_nugget
= requests.post(api_url, files=files, headers=headers)&lt;/P&gt;&lt;P&gt;jsonRead =
json.loads(response_nugget.content.decode('utf-8'))&lt;/P&gt;&lt;P&gt;# Extract
the detected face and display&lt;/P&gt;&lt;P&gt;bottom =
jsonRead['predictions'][0]['faces'][0]['face_location']['bottom']&lt;/P&gt;&lt;P&gt;left =
jsonRead['predictions'][0]['faces'][0]['face_location']['left']&lt;/P&gt;&lt;P&gt;right =
jsonRead['predictions'][0]['faces'][0]['face_location']['right']&lt;/P&gt;&lt;P&gt;top =
jsonRead['predictions'][0]['faces'][0]['face_location']['top']&lt;/P&gt;&lt;P&gt;from PIL
import Image&lt;/P&gt;&lt;P&gt;img =
Image.open(nugget_file)&lt;/P&gt;&lt;P&gt;area =
(left, top, right, bottom)&lt;/P&gt;&lt;P&gt;cropped_img
= img.crop(area)&lt;/P&gt;&lt;P&gt;cropped_img.show()&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 11:15:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/artificial-intelligence-forum/python-code-to-call-ml-object-detection-api/m-p/12075014#M131</guid>
      <dc:creator>AndreasForster</dc:creator>
      <dc:date>2019-10-18T11:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Python code to call ML Object Detection API</title>
      <link>https://community.sap.com/t5/artificial-intelligence-forum/python-code-to-call-ml-object-detection-api/m-p/12075015#M132</link>
      <description>&lt;P&gt;Thank you for the quick answer, Andreas. You've been very helpful!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2019 18:49:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/artificial-intelligence-forum/python-code-to-call-ml-object-detection-api/m-p/12075015#M132</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-10-18T18:49:37Z</dc:date>
    </item>
  </channel>
</rss>

