Setting up API and Vision Intro – Google Cloud Python Tutorials p.2

Setting up API and Vision Intro – Google Cloud Python Tutorials p.2


Setting up API and Vision Intro 

welcome everybody to part 2 of our google cloud (API) tutorial miniseries in this video

what we’re doing is covering the first API but also just kind of how to set up any of the

api’s that you’re going to use because the first time you go through this you’ve got to deal

with some sort of API validation key and stuff like that so also you have to install the actual Google cloud

stuff to work on the server so anyway the first one that we’re going to work with is the actual vision API

so this is something you can feed an image to and it can and the API will basically give you information

on this image what’s in the image what is the image about I can even give you some

metadata on that image so if it sees something that it recognizes so if you fed it an image of like the Eiffel Tower

or something like that the metadata might include the Wikipedia page for the Eiffel Tower anyway

let’s go ahead and get started so you should be on a fresh server we did install a CH top so

we could pop on in there and look at H top if we wanted ctrl C to get out of that

and so we should be in our kind of typical home directory so and it’s not just CD facility here and then

that way we’re basically back at just well this puts us in the root directory so now what

I want us to go ahead and do is we’re going to make Durer we’ll call this G cloud stuff and then let’s change

directory CD G cloud stuff and what I’m going to do here is first let’s go ahead and make sure

we’ve got pips so you should have it but just in case sudo apt-get install actually

I’m not sure if these servers will come with pip or not anyway should I have to get install a Python –

pip nope it doesn’t look like we had it already so cool let’s grab it another thing we probably should have done

is an update and upgrade but you can do that on your own time I think we’ll get away with not doing

even piss taking a while once we get tip we’re going to install Google – cloud you can

alternatively do Google – cloud – vision that’s the only one you want since

I’m going to be doing a series on Google cloud I’m going to do sudo pip install Google – clap

but if you just wanted vision you can type – vision but I want the whole thing so

I’m going to install the full everything so just as you can see everything is getting

installed here once we’ve done that there’s one more thing that we really need to do

and that is the API T for dealing with the api’s so while this is running head back over to Google cloud

here and let’s click on the wool hamburger thing go to API manager and then come

on down to credentials and once you’re in the credentials what we’re going to do is create credentials

we’ll do a service account key and let’s choose a new service account and I’m going to call this API

it’s all be like that role project and let’s just give it owner which just gives us full access to

everything so I’m going to give it owner you can give it really specific access so if you had you know if this was your business and then you could give specific

keys to certain of your employees or something like that but for now I’m the owner so

I get full access we do want JSON so we’ll hit create and this will give us a file that’s going to download

a file downloaded go ahead and just kind of save it and put it somewhere so save to my computer

I’m going to move this over here and what we’re going to do now is well I’m just going to leave it there

but we can open it up and this is the file so it just has some information in here I wouldn’t show

this to people normally but this server will be deleted soon enough anyway so by the time you see

it this won’t matter anyway but anyways that’s what’s in it it uses something we can copy and paste so we’ve got

that let’s go back to our server now and what I’m going to do is what’s weird we just installed it

and it watches update okay let’s get we can upgrade it that’s fine – install – – that’s pretty yep

and now we want to do is add this API key so I’m going to go ahead and just a nano API

T dot JSON that’s an empty file so I’m going to now take that file that we just downloaded from Google

copy come over here paste ctrl X – safe yes enter whatever you can feel free to use a different editor if you like

I know someone’s going to like why did you use man oh okay so I like to use silly editors now once

we’ve done that so the next thing that we can do is so for example like if you if you go to

Google basically what they tell you to do is okay export and then Google underscore application

underscore Prudential equals and then you give the path those credentials this is going to run off the screen so let me make sure this is all shown there we go equals

and then the path to what we just made so g-cloud stuff you can hit tab to autocomplete API key JSON so we could do that and hit enter maybe not a valid identifier export

what did I do wrong let’s see X for Google application credentials maybe no space I’m not positive

Y that fails okay I guess it’s a space that’s interesting okay let the problem with this is if you restart

your server or whatever it’s not going to work so what we’re going to go ahead and do is let’s do nano till

the flash period on file and then just go to the very bottom of this profile and then actually what we want

to do is copy that line so let’s go ahead and copy this line here you can right click to copy there it is

I don’t want that there and then now let’s go ahead and nano into the profile

again and then right click to paste now let’s fix this little space here and then control X yes good

and then to update that will be source bash RC and now we’ll be working off that either way it should have worked

as we exported it initially but basically this is like adding something to your path so now

when when we use the Google cloud cut Python API it knows okay here’s where we can find the API key all right so now we’ve done that let’s go ahead I’m going to make the vision the X for example

I’m gonna CD into this gem DX great now I’m going to go ahead and nano vision X up PI and

this will be a new python file and what we’re going to go ahead

and do is first I’m going to import i/o I’m going to go from Google’s cloud import vision and then

we can specify vision clients on this tech vision client Eagles vision Docs clients and now we

need an image so what I’m going to go ahead and do is come over here and

I’m just going to search for we go Rossum great let’s go to his Wikipedia page great picture let’s

copy that image address and then we’ll come back over here and in fact we need to kind

of let me just save this here so yes okay so we’re back over here control

X days yes I’m going to do with W get that image awesome so that image name is here LS to list up the directory

I’m going to copy that image and then now back vanna visionary nan-oh and now we’re going to specify the filename

so we’re going take file name D equals right-click boom I’m sure it’s not running over my face

and now we’ve got the file so now we want to load this image into memory so we’re just a wisp IO dot open file

name RB as image file what do we want to do there is a content equals image underscore

file dot read we’re going to say image equals vision underscore client dot image and then content equals

contents and then we can get something simple like the label there’s more things that we can do as vision

we’re going to continue but for now, I just want to do something really simple and basic because of this one

is going to serve both as an intro to division API but also just how to use any of the API is because the process is pretty similar labels equals image dot detect underscore

labels so they’ll just tell us what Google happens to see in this image so we’re just going to print out

in fact let’s get irate through labels so let’s say for labels in labels we can print print label

dot description and let’s just do that and then I’m going to give you some advice on using this API

so yes enter and let’s go ahead and I think we might have to use pseudo for this but let’s just try to run

it without pseudo oh we haven’t enabled the API okay so the okay the whole point of this tutorial

so yeah we so we got this permission denied so we got the API key but we haven’t enabled division API

in our actual platform so the easiest thing to do there is some way to get there probably here maybe

I don’t know I don’t know how to get there for real but you can just search like vision boom google cloud

vision API no problem you get here enable the API okay now we’ll come back over it did say wait a few minutes

after you-you enable the API let’s go ahead and try it post that in just sacrifice a few minutes for everybody

boom done so actually that was very quick okay so what does it see any image it sees

hair face person facial hair nose chin hairstyle beard and senior citizen sorry greena okay

so um so this are like a really quick example there’s more stuff I’m definitely going to show you

but the one thing I do want to show you that I think is kind of part of all

the api’s is I think the document usually Google is really good about documentation

but there’s a lot of the examples that don’t have Python examples yet and then the documentation is met and

the code is kind of a challenge to crawl through so for example when you have like the labels and labels and

actually, even labels like so, for example, I’m trying to think how I want to do this what I probably could do is

I think we’ll do this let me just copy this exit no let’s run Python and I think I can do this let’s see if this code if we get away

with this great so so I’m just running this in regular Python so if we do something like this like dirt

this will tell you all the kind of attributes of something right so for example

we could say dur labels and this just tells us kind of like what does all the attributes and things and

methods that we can do we’ve got a pend count okay so clearly this is something that’s

been iterable just by looking at this but then what we can do is like for label endure

or rather let’s see let me just completely real quick yeah so let’s do der label as we can see each of the labels like because basically, this is storing the last label

that was iterated through kind of a thing with Python so what we have or all the attributes

of a label that we could possibly access so these ones you anything with the underscores you probably

leave alone unless you really know what you’re doing but you’ve got interesting do this score anymore yes I do okay

so bounds description from an API repper I’m not sure what that even does

I don’t know if this one is either locale locations mid I don’t know and score but like we use dot description

to get what is the actual thing right that gave us the hair the face beard person and all that kind of stuff but there’s some other attributes too like locations unfortunately

I don’t think I’ve ever seen locations work so for example for a label in labels print label dot or locations let’s give able dot locations label dot locale

I don’t think that one either has any information yeah so locale I’m not really sure locale

what that would normally give you so clearly it looks like it’s going to give you

a you know text data of some kind but anyway I was really hoping locations would work but

I actually haven’t found an image that locations works on at all so it’d be nice if you could show

the vision API a picture of a bunch of cars and it would see yes it says cars and then here are all the X&Y;

coordinates for those cars or even better like a box that would be awesome to give you like the box

coordinates like the top left in the bottom right corner that’d be really neat but that doesn’t think

may be the case and like I said nursing locations work clearly looks like it’s probably going to be some X&Y;

data or even a box data but it’s just not there so and

I’m sorry guys I’ve never seen it actually doing it but you do get it at least an explanation

of what image you’re looking at which is actually pretty impressive and then like

I said some of the stuff gets even more interesting because it especially if you if you show it things that should have metadata

and it actually finds committed okay so that’s a really quick example of the vision

API and then also just using API is in general don’t forget to enable the API I always forget

but at least now you know what it’s going to look like when you do forget it’s going to be like this permission

denied basically go and enable the API also the key we won’t ever have to do that again so now that it knows

where the key is we don’t have to generate a key every time we want to use a different API

but you do have to enable that API all right so if you have questions comments

concerns whatever feel free to leave them below otherwise I will see you in the next video where we’re

going to be doing a little bit more with the vision API because it’s a cool API and you can do some

things with it but other than that see you next time

No hay comentarios

Dejar una respuesta