Ever wondered on how we can add AI when it comes to location based services? In this code we upload pass an image to a Python Flask Application and get recommendation based on the food picture you have passed.
Sign up for IBM Cloud at https://ibm.biz/HERETechnologies
Get your HERE API Key at https://developer.here.com
- User passes an image in the python code
- As we are using the visual recognition service there is a out of the box food model which we are going to use and it detects the name of the food which we have passed
- The name of the food is then passed to the HERE Maps Discover API which then suggests places around a particular location which we have configured within the python application.
To implement this code to a location of your choice
- Clone this repository
git clone https://github.com/vidhanbhonsle/Visual-Recognition-with-IBM-HERE-and-Python
- Add your IBM Cloud Visual Recogntion API Key and Here Maps API Key in
test.py
authenticator = IAMAuthenticator('IBM_API_KEY')
visual_recognition = VisualRecognitionV3(
version='2018-03-19',
authenticator=authenticator)
visual_recognition.set_service_url('IBM_SERVICE_URL')
- Enter the templates directory and add the HERE maps API key obtained from developer.here.com and add it to the
JS_API_KEY
variable
var platform = new H.service.Platform({
apikey: "JS_API_KEY" //HERE MAPS API KEY
});
- And scroll to the variables where the
latitude
andlongitude
are set and replace it with the latitude and longitude of your desired locaiton.
latitude = 12.959111
longitude = 77.732022
- Open a terminal and
cd
into the application directory and export theFLASK_APP
variable
export FLASK_APP=test.py
-
You can now run the application by running
flask run
in the terminal. -
OPTIONAL If you would like to assess another food item just add it to the project folder and in the
test.py
file replace the filenamepizza.jpg
with the filename of your picture.
with open('./pizza.jpg', 'rb') as images_file:
Save the file and re-run flask run
to see the changes.
To host your application online you can also deploy the same application on IBM Cloud's Coud Foundry.
Install the IBM Cloud CLI
Mac or Linux
curl -sL https://ibm.biz/idt-installer | bash
Windows (Use Powershell as Adminstrator)
[Net.ServicePointManager]::SecurityProtocol = "Tls12, Tls11, Tls, Ssl3"; iex(New-Object Net.WebClient).DownloadString('https://ibm.biz/idt-win-installer')
- Login to the IBM Cloud CLI
ibmcloud login
- Target your IBM Cloud CF Organization & Space
ibmcloud target --cf
- Edit the
manifest.yaml
and change then- name: <your app name>
to the same name you have entered on IBM Cloud when creating the Cloud Foundry IBM Cloud Service
applications:
- name: allocation
random-route: true
memory: 128M
- Once you have changed the .yml file you can start with pushing your application, making sure that you are in the
VisualRec-CloudFoundry
directory enter the command
ibmcloud app push
And your application will start to deploy on Cloud Foundry and you will be able to access it by seeing the output of the application route on your terminal and also can be access through .
NOTICE You can also make changes to the application if you like as stated in the local deployment section within the VisualRec-CloudFoundry
directory and run cf psuh
to see your changes.