 OK. Welcome to this session. Please welcome Jackson Isaac, who's going to guide us through his introduction to Google Cloud and Python. Come right up, which is Jackson. Thanks. Hi, everyone. Hello. Yeah, it works, right? Hello, everyone. Good evening. I'm Jackson Isaac. Today, I'm going to present how to use Google Cloud with Python. Mostly, I'll be focusing on how to use ML APIs. And we'll see a demo on how to do OCR and do a number plate detection from the images using Google Cloud. And I'm a GSOC org admin with the MacPorts project. And I also professionally work as a big data developer at TCS India. So I'll start now. So what is Google Cloud? It's a cloud computing platform provided by Google. So there are more platforms like this, like AWS and Azure. And Google has also come up with their own services in this field. And some of the popular products are Cloud Vision API that we are going to talk about today. And then there's Compute Engine, where you can launch your own virtual machines and do some processing on it. You can have Linux machines on that. And then there's App Engine. So what App Engine does is you can launch your web apps or mobile apps using that engine. And then there's Cloud TPU. So if you're from machine learning or deep learning background, you will know about TensorFlow. So you create some TensorFlow. And then you design your machine learning model. And then you run it. So this TPU specifically, it's designed for TensorFlow. And it performs much better than even your GPUs. And you can use the TPU on cloud itself. Google provides it as a service. And then there's BigQuery, which is used for big data querying. And there's Kubernetes. And then there's CLI. CLI means command line interface that I'll be using from my terminal. So that's gcloud, which is an interface to GCP. Then next is, first we have to set up Python. And here, we can see how to set up Python if you don't have actually. How many of you are Windows users? And Linux or Mac OS? So here, mostly people are Linux users. So you can simply do yum install or apt-get install Python. And here I have mentioned Python 2.7. That is what Google documentation asks for specifically. But even you can use Python 3. And Windows users, they can just download a package from Python website. And they can set up Python. Mac users, probably they get Python 2.6 by default. You can even install 2.7 or 3.6 using Mac ports. Or as well, the .package file if you want a GUI installer. And then for running Python, you can just enter Python hyphen v, which will show you which version of Python you are using. And yeah, that's about Python. Next, we'll see how to set up gcloud SDK. So this is a software development kit by gcloud. We have to download this and install it to use the gcloud CLI and use it through our Python code, which can be downloaded from cloud.google.com slash SDK. Here it will auto-detect your operating system and give you the installer. And then after you have the installation file, you have to change into the folder and then run .slash install.sh. So what basically it is, it is a shell script to set up the gcloud CLI on your machine. It will install all the components. And I'll show you quickly on how the components will look like. So when I do install or here components list, because I have it already installed. So here you can see my SDK version is 193, which is the latest version. And then here you can see all the components, like App Engine, Go extensions, or Emulator reverse proxy, or Cloud Pub sub-Emulator. So these things are not installed by default, but you can use the ID and install it. So what comes by default is the command line cloud storage, gsutil, and the core, and the BigQuery command line tools. And then next, we have to run gcloud init. Before that, I hope you can see the screen, the terminal. It's readable. OK. So when you run this gcloud init command, what it will do is actually initialize the authentication. So it will first redirect you to Gmail or Google account. And then you have to log in. OK. And you have to log in and set up your account so that the environment can read your authentication credentials when you call the API. So you don't have to again and again log in to it. And there is also a quick start guide here on this link. I don't know how the presentation will be shared, or you can get it from Dropbox. So you can just refer to this presentation and click the links. But here you can get the quick start guide on how to set up all the code and all. And for Python, there is a specific API manual here on the Python link. And then there's also some example files on GitHub platform. And then next, also, after doing gcloud init, what we have to do is, OK, so I did here. So it says me, OK, what is the account that I'm using, the configurations, and if I'm reporting all the usage and the project, which project I'm using. So I'm using for Asia 24 March. So on gcloud platform, you have to create a project and where you define which APIs you want and what kind of roles you want to create for users. And here I just created a sample project. And when you have multiple projects, you can select each project by entering gcloud project, set project, and project ID. Here you can see that I can reinitialize with the default settings or I can set a new configuration. So here I don't want to do this. Next is doing installation of Google Cloud for the Python package. You can just run simple pip command. Pip install Google Cloud. This will install all the Python packages required for running gcloud command. So this is about setting up the gcloud SDK. Now, OK. Let's create a VM instance on GCP and see how it works. It's just a simple drag and drop. So here you can have any number of CPUs or GPUs. I think very soon they are also going to launch a TPU. So what you see here is the Google Cloud platform, the UI, where you can select all the services provided here. So these are all the services provided. So we are more focusing on Compute Engine and Cloud Vision API. So this is how it looks. So when you click on Create, it will take you to another window on tab. It's pretty slow. So feel free to ask questions in between if you have any doubts. Here, there are some even templates which you can select if you don't want to create your own instance. So here, you give your name, the zone. So I'll select East 1c. I'll have, say, I want four CPUs. And OK, I want to customize. I want to even have GPU because I'm going to do machine learning. So let's say here GPUs, yeah. So amount, when you configure this, it will give you an hourly estimate on how much the cost will incur. But actually, it's based on per second billing. So you only pay for how much you use. It's not like, OK, if you select for one hour, you'll be charged for the whole. But it's like how much time it is running. And they have a good collection of GPUs here. There is a Tesla K80 and P100. So P100 only in this few selected regions they have. That's why I have selected East 1c. So if I select P100, it is one for deep learning. So OK, this is per month cost. Effective hourly rate is just 134 cents. So that's pretty cheap. I can just run it for, say, 24 hours. My total cost incurred will be just $2.50. And I can train a model, a deep learning model in this time. And even you can configure how many cores you want up to 96. But that's, you have to play around here. It's like a trial and error on how you can configure it. OK, so any doubts here? OK, so I'll move forward. And then here, what I mentioned was GPUs. So if you go to this link, there it's mentioned which GPU is available in which region. Because it's not available in all the regions. Say probably in Singapore, only P100 or K80 might be there. And TPU, you can set up TPU as a beta thing. They haven't launched it officially. So when you run ML Engine or some code on their ML Engine, you can make use of TPU. It costs around $6 per hour. But it's pretty much cheap as compared to running GPUs for hours. And probably we can even give a try on how I can enable TPU for my project. Hi, come on. OK, so here, so basically it's just simple click or drag and drop kind of interface. So it's pretty simple. It's not like you have to configure something or write scripts to configure anything. Here you can even select which tensor flow you want to run. So here you can see $6 and 1 half hourly rate. And then you can create it easily, a node, a node running on TPU. Let me know if I'm going fast. The next is computer vision, which I'll be focusing more on. And we'll be talking much more about Cloud Vision API. So it helps us to detect faces from images. Do OCR? OCR is optical character recognition. So here you see this banner, right? So if you take a photo of this and send it to Google Vision API, it will print out all the details what is written here. Like FOSS is on the first line, ASHA is on the second line. And then there's logo, there's Google Cloud return, or even the dates and all. And then there's label detection. Say you post an image of a tortoise. So it will say, OK, it's an image of an animal. Or even it will recognize, OK, it's a tortoise or a bird, if you upload a bird. Here if you upload this image, you can see some logos. So it will even detect logos from the image. And next is web detection. So web detection means if you have used Google image search, you will see some similar images will be recommended. So say you upload a water bottle. This is a company. And it will give you similar images for bottles. And OK, so before we actually start calling the API from our code, we have to enable the API on our console. So by default, everything will be disabled so that you don't incur cost or there is no fraudulent usage if someone knows your account. So when you are in a GCP platform, you go to API and services. You click on dashboard. So here basically you'll get all list of all the APIs which are there. And then whatever is your requirement based on that, you can enable the APIs. Say I require Cloud Vision API. OK, so this is my Cloud Vision API. I can click here and just disable it from, say, I have launched my app on multiple platforms and everyone has my code. And I don't want them to access it anymore. And so I can just click on disable, delete my project. The app won't be any longer usable unless they get a new credentials from me. So this is Cloud Vision API. But if you go back, you can see a list of other APIs. And then it will also give you all the statistics on how much requests are there or how much errors were there. And what kind of API calls were there. So here you can see compute engine API. There were 21 requests. For TPUs, there were four requests. And for how much time and what latency was there. Anyone doubts? No? OK, I'll move forward. So next is demo. I'll try. If I can do it here, there is some issue with the network. OK, yeah. I actually had it run before. I started the presentation. So here I have a piece of code which takes image as an input. It sends it to Google Cloud. It detects a text. And from there, I only take the first key text annotation from the whole bunch. So it's actually a JSON response. You'll get all the text that is available in the image. And then from there, I just take a number plate. So this demo is basically a number plate detection from an image. And I'll show you how the image looks actually. So here you see there's a car. So it's from India. There's a number plate from India. And if you see here, I have sent the image to Google Vision API. It detected the text from the input image. And then here you can see the number plate. It's written Ka, space 51, space P, space 69. It looks like 3, 1. And that's what is there in the image also. And I'll also take another image. Probably it works fast enough to not go over the time limit. Meanwhile, I'll show you how I have it in the code. I hope everyone can read this. I don't want to open it or else it might take some time to process. You can't read it? OK. Or else? OK, I'll probably not open anything. It will take some time. So OK. So from here, from Google.cloud, I have imported the Vision API. This is the packages that we installed using PIP. PIP installed Google Cloud. So this packages will be available from the Python code. So that's really important you install Google Cloud package. Then there's from Google.cloud.vision import types. So there was some recent changes to the APIs. That's why I had to also import types. And the main code for Vision API is over here. This function that you see, detect text. It takes a path, the file path. It creates an initialized object of Vision API, image annotator of client. And then I read the image file as bytes. I save it in a variable. And I send it to types.image. And then I call vision underscore client.text detection. So here, what it actually does is it sends the image, the content of the image to Vision API as a request. And then from there, I get a JSON response, which is also stored in text variable. And then I print it using text.text annotation of 0, the first key value pair. And then from there, I take the description. Probably if you want to know more details about how this works, I can show it after the talk, or else it will just consume more time. So here, it has run. So here, I have sent rickshaw. It's a public transport in India, this. So you can see the number plate is very small here. And there is also some mobile number written here of the driver. And then when it detected the text, here you can see that it extracted the number plate properly. But along with that, it also extracted the mobile number. So how do you tackle this thing? So when you get this response, you can write a regular expression. Say, I know that Indian number plate is two characters, two numbers, one character or digit, and then four digits. So some kind of regular expression, some patterns you can write to extract only this particular number plate instead of the whole thing. So this is some post-processing that also you have to do because you can't completely rely on the vision API. So this shows you that even minor details, minute details, very small details from an image, it is able to analyze completely. So here I'll give some insights why we went with this. Why didn't we go for in-house model? Because the accuracy was not that great. It was around 70% to 80%. But with Google Cloud, we got around more than 95% accuracy. So that is why we went and OK. Then it's a bonus video. I think I have some time. It's just one and a half minute. I can show this. So here what I have done is, since I'm a big data developer, I thought, OK, let's use some big data tools also. So here I use Kafka. Kafka is a message queue. So you send messages to the broker and you consume via client. And then it OK. I can't play the video here. I'll play it here. So here what it does is you keep on sending the images via Kafka producer. And OK. So there are four tabs. Here are the input images that we are sending. This is the producer. This is the consumer. And here we will cut out this particular plate using OpenCV and just send that itself to Google Cloud so that we don't get a text from anywhere else. That is what happened in the previous image that I showed. So here I'm sending an image through Kafka. Here it's processing. It will take some time. I'll fast forward the video a little bit. Not so much. So it's getting the number plate. And then it has cut out. OpenCV has cut out the plate and send it. I'm not sure if you are able to see this, but it's MH12BG7237. And then next I send another image. And then this code is still running because it's reading from Kafka. There is no loss of any data. Even if here I send one more image. So you can see KA03MG2784. And this is how you can just keep on analyzing multiple number plates. You keep on sending through Kafka and consuming from the client side. So when you launch this app, say you have the client of Kafka, the consumer, on your mobile app. You send it from somewhere. And then you get the number plate detected for you. So yeah, that's about it. And I think, yeah, I'm done. So that was about it. Thank you. If you have any questions, you can contact me on hijaxsonatbackports.org, or even you can tweet me on hijaxsonisac. So mostly I'll reply on both Twitter as well as mail. So you can expect within some hours a reply from me, unless I'm sleeping. So yeah, thanks. Thanks for attending. OK, I see three questions. No questions? Yeah, that's great. If you want to know more about how the code works or the internals, you can ask me. No problem, yeah? Thank you, guys.