Translation API - Google Cloud Python Tutorials p.5
Key Takeaways
Uses Google Cloud Translation API to translate text
Full Transcript
what is up everybody and welcome to part five of the Google cloud apis and such tutorial Series in this video what we're going to be talking about is the translation API which will translate some text to a Target text what's interesting about this one is the sum text um does not need any sort of indication of what that language is it will just detect the language and figure it out the target of course you need to supply that so that's actually pretty interesting uh translation API so to do this same thing as everything we've covered up to this point first we need to enable it so translation API I think we're already on that page um I've got it enabled already but if you don't go ahead and hit enable once you've done that you're ready to rumble so let's go ahead and make a new directory so C out makeer translate example CD translate example and then nanot Translate example.py this one's going to look very similar to the last one hopefully by now if you're been following through all these Google Cloud API examples uh you're starting to see a trend here and hopefully building your own API will be super simple um or building your own projects and stuff off their apis will be super simple um so now let's go from google. cloud we're going to import translate then we're going to Define Translate lat text it's going to take a parameter of text and then it's going to take a Target I'm going to go ahead and auto specify the target that's e n which is for English target has to be ISO 639-1 language code if you need that uh you can go to the docs and look at languages I think it might even have them in the documentation possibly so I'll click documentation I one somewhere here it'll probably say the language code yeah so hopefully uh well yeah we can click this it'll take us to the Wikipedia page uh where it has all the codes listed so 639-1 right here so all of these should in theory be supported I think by um Google Cloud basically you can use any of these as your target uh translation but here I'm going to translate um unknown text to English so coming over here let's continue wonder how many people are mad that I'm coding Python and Nano translate clients equals oo that's a typo translate client equals translate. client similar to all the other ones then we're going to say result equals translate client. translate it's going to take two parameters the text that we want to translate and the target language and that's just going to be equal to whatever the target parameter was that were we're passing there and then this one's really basic so you can for example um is that five one two three four no okay we can print um we can say the text pass and then comma uh result and then this will take uh it's just basically your dictionary so in input um actually I think the result will be a I'm not positive is Json or a dictionary I think it'll be dictionary since we're dealing in this is actual python API anyway uh so that's the text then we're going to say uh the translation and that will be the results translated text in nice non pep8 form print um detected Source L and then again here we can say comma results detected oops we're going to need quotes here detected Source language and then now let's do some example text so in here you can pass whatever you want I'm going to copy and paste a uh one of the comments that was made on one of my tutorials uh that is not in English if I remember to I'll put a link in the description if I forget someone can remind me but also just find some text that's not in your language and feel free to translate it to whatever you want one thing I will say is try to not use translate.google.com to create some non your language text because translate.google.com is not perfect so but it will probably translate back and forth I perfectly so you wouldn't want to do that you'd want to use some real another language so anyways paste that in there oops going the wrong way here um and then finally I can do translate text the text that I want to pass is example text um and this is probably not going to work um but this will be a common error that I think people will deal with in their world of python so let's go ahead and deal with it anyway so boom Okay so we've got this non- asky character blah blah blah blah so there's a few reasons you're going to see this one is it's always because of non- asky characters but it can be for a variety of reasons in our case we need to use pep eight or I mean not utf8 so let's Nano back into here and at the top of here we need to specify our coding so we're going to say uh dash star Dash coding colon utf-8 not 78 and then they'll hold dash star Dash and then um what we want to do is I'm pretty this still won't work shouldn't work let's make let me make sure before I get it wrong oh no it got it okay fine I typo translation though so I'm going to go here uh [Music] translation translation one more time whoops not n know oh dear there we go okay so we get the text that was past translation hello greetings from Columbia excellent tutorials I wish I could at least have Spanish subtitles I'm not sure what that should be let's see if we can let's see uh no like the word is literally I oh okay so it's asking for Spanish probably I think this was meant to say espanol I don't think the e n espanol right there should never be an e after that I think that's a typo I think I don't know I'm pretty sure that's a typo uh but yeah this is converted to utf8 of course because if you looked at the actual text it has like the fancy letters so if we look down here H saludos here we go excellent roals nothing new there but then yeah you get the I forget what you call that the little TIY over the end though um right that's not it's not proper character so anyways that's why it gets converted when we print out here that's that yeah okay so anyway that's the translation API again I feel like I I ran through it so fast that maybe it's it's like almost like not even cool or impressive but it's actually really impressive right that's not a perfect translation but it's pretty close and I I'm pretty sure there's a typo in there and that's that's the problem um anyway um I also think it's pretty cool that you don't need to know the the input language it just it does that all in the background it detects what the input language is no problem and even we can it'll tell us what the input language was or what it thinks it was um and all that I think that's really really impressive um so anyways this is going to conclude uh at least my first batch of Google Cloud's um API stuff even with just this like you can do a lot of really cool things like for example you can make a pretty pretty nice travel app or something like this right you could take pictures of signs you don't understand or don't know what they mean uh that could get you could detect the text translate the text uh put it in your language um uh like it's just like there's so many things that you can do and it's fast and it's pretty darn accurate so um anyway um I'm super impressed with this I mean the amount even if I'm not really positive like some of like at least the natural language API I think is a little overpriced the translation API makes sense on a per character basis I think that's pretty fair pricing uh but then uh and the vision API is definitely fair pricing like that's a steal for doing the image processing tests like that uh so that's pretty cool so I think especially if like you're just trying to up with ideas or make apps or just kind of prototype things this is a no-brainer like Google Cloud apis are just that's the way to go I don't like being dependent on people's apis though but all this stuff is stuff that you could build on your own for sure like doing natural language processing doing semen analysis doing image analysis all these things you could build on your own but it would it will take a while so like if just to do like quick prototyping of ideas and stuff this is really cool anyway um that's it for now I might cover some of some of the other apis I'd like to do the speech at some point uh I'm not positive when I'll do that one but I think that one's pretty cool especially because there's a lot of really neat things that you can do with it but for some reason their documentation contains like no python they have some python examples but I need the documentation that's what I I really need so anyway um or not I guess not documentation but code oops not python uh code examples basically so if you go to Google Cloud speech uh and then you go to their documentation like for the other apis they have like let's do howto guides I'm trying to find it where they've got like all the different languages that they have like examples for I'm just trying to show like a really quick example here libraries maybe oh of course yeah yeah python there there it's there but no uh let's do the rest reference let's do speech maybe overview just trying to show you that in I'm just not getting to it but anyway in the documentation a lot of times they'll have like examples for various languages but for some reason they don't have python in there they've got like uh JavaScript and C or something like that but they don't have python so anyway that's kind of frustrating so you kind of have to like hobble your way through it as far as I've been finding because speech is a little different because you have to record it encode it send it over or even what's neat is they also have like the streaming API uh where you can literally like as you're speaking it's trying to figure out and then it gains confidence kind of like when you speak into your phone or you're do a Google search with the microphone how like as you're speaking it's printing out the text but then a lot of times it changes the text as as you continue to speak and it like realizes oh he meant this or she meant that so um that's really cool and I really want to be able to do that because they've got the synchronous and asynchronous speech recognition and stuff uh but for so like I said right now it doesn't really seem to be the best documented probably because it's also in beta the speech API uh is beta so I don't know hopefully soon I can cover that one too I'd really like to I've kind of poked into it and I just couldn't couldn't figure out like how to do it easily there are some like python modules if you want to do speech recognition there is like python speech recognition that uses I don't think from Google Cloud speech it's like a it's like an older version um so you could look into that if you wanted like if you're really wanting to get in this Google speech uh right now or speech recognition right now you can look into those cuz there are some stuff there and then also the other thing is like go Cloud uh has competitors Azure and IBM has both of them have pretty similar things that you can do and Ian I'm trying to think of who else I don't know if AWS has anything like these like these little apis but anyway that's it for now questions comments concerns suggestions requests whatever leave them them below otherwise I will see you all in another tutorial
Original Description
Welcome to part 5 of the Google Cloud tutorial series, in this tutorial we're going to cover the Translation API.
As usual, you first need to enable this, and of course you need to have your credentials all set up (see part 2 if you haven't done this).
The translation API allows us to take any (well, just about) language and translate it into a target language. The beauty of this is that you don't need to know the language that you're attempting to translate, you just need to know what language you want it to be in.
Sample code: https://pythonprogramming.net/translation-api-google-cloud-tutorial/
https://twitter.com/sentdex
https://www.facebook.com/pythonprogramming.net/
https://plus.google.com/+sentdex
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
🎓
Tutor Explanation
DeepCamp AI