This site uses cookies.
Some of these cookies are essential to the operation of the site,
while others help to improve your experience by providing insights into how the site is being used.
For more information, please see the ProZ.com privacy policy.
How to convert REST API of custom model from AutoML Translation into Autohotkey script
Thread poster: Michael79
Michael79 China Local time: 17:23 English to Chinese + ...
Jul 30, 2018
I have an AHK script that helps me to use Google Cloud Translation API more easily. To be more specific, I have converted this AHK script into exe file so that whenever I want to leverage Google Translate API all I need to do is opening the exe file,select source texts and then press ctrl+j and the source text will be translated into target language automatically without bothering to copy everything into the webpage of Google Translate.
Given Google has launched its AutoML Translat... See more
I have an AHK script that helps me to use Google Cloud Translation API more easily. To be more specific, I have converted this AHK script into exe file so that whenever I want to leverage Google Translate API all I need to do is opening the exe file,select source texts and then press ctrl+j and the source text will be translated into target language automatically without bothering to copy everything into the webpage of Google Translate.
Given Google has launched its AutoML Translation and I managed to train my own machine translation model recently but the problem is:
Google has posted REST API of my MT model as follows:
Execute the request curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://automl.googleapis.com/v1beta1/projects/"my project name"/locations/us-central1/models/"a string of project digits":predict \ -d @request.json
My question is that how can I convert this REST API into another AHK script so that I can use my own machine translation engine in any text editor?
The contents of this post will automatically be included in the ticket generated. Please add any additional comments or explanation (optional)
Samuel Murray Netherlands Local time: 11:23 Member (2006) English to Afrikaans + ...
@Michael
Jul 30, 2018
Michael79 wrote: I have an AHK script that helps me to use Google Cloud Translation API more easily.
1. Do you also use curl in that script (e.g. curl.exe)? 2. Does Google provide a non-curl method of querying the trained model?
Execute the request curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ https://automl.googleapis.com/v1beta1/projects/"my project name"/locations/us-central1/models/"a string of project digits":predict \ -d @request.json
It seems that you'd have to save the source text to a file named "request.json" and then send it using curl.exe. Do you know what the required format of the JSON file is?
Obviously the exact syntax of that curl command will also depend on which version of curl.exe you are using (and possibly also whether you are using it on Windows or Linux), but hopefully your preferred version of curl.exe has a user guide.
I wonder if it would be possible to send the request by replacing @request.json with the actual source text (either formatted in JSON format, or just raw), obviously enclosed in quotes.
The request syntax that you mention mentions a bearer and a token. Do you have to use curl.exe before this query to get/generate a token and then use that token in this request, or can you simply use your API key as the "token"?
Subject:
Comment:
The contents of this post will automatically be included in the ticket generated. Please add any additional comments or explanation (optional)
Michael79 China Local time: 17:23 English to Chinese + ...
TOPIC STARTER
thanks my mentor
Jul 30, 2018
Hi Samuel, glad to see your reply. I remember it is you who sent me an AHK script to facilitate process of using Google Translate API while the one I am using now is some kind of advanced version.
I can send the codes to you if you like.
To respond your questions+
1. Do you also use curl in that script (e.g. curl.exe)? No for this case. I mean the script itself is an ahk file and I converted into some exe file in Win7.
Hi Samuel, glad to see your reply. I remember it is you who sent me an AHK script to facilitate process of using Google Translate API while the one I am using now is some kind of advanced version.
I can send the codes to you if you like.
To respond your questions+
1. Do you also use curl in that script (e.g. curl.exe)? No for this case. I mean the script itself is an ahk file and I converted into some exe file in Win7.
2. Does Google provide a non-curl method of querying the trained model?
Python.
The detailed information as follow
predict.py
import sys
from google.cloud import automl_v1beta1 from google.cloud.automl_v1beta1.proto import service_pb2
The contents of this post will automatically be included in the ticket generated. Please add any additional comments or explanation (optional)
Samuel Murray Netherlands Local time: 11:23 Member (2006) English to Afrikaans + ...
@Michael
Jul 31, 2018
Michael79 wrote: I remember it is you who sent me an AHK script to facilitate process of using Google Translate API while the one I am using now is some kind of advanced version.
My Google Translate scripts are written in AutoIt, not AutoHotKey.
I was very lucky to be able to figure out how it works, though. I also tried to write a script for Bing's translator, but Google's system was infinitely simpler to figure out. The fact that AutoML requires a token and a bearer is disconcerting -- it may be the thing that stops you from getting it to work.
2. Does Google provide a non-curl method of querying the trained model? Python.
I know nothing of Python, unfortunately.
I suggest you (a) find a version of curl that works on your computer and learn how it works (e.g. should you use single or double quotes, i.e. Windows vs Linux dialects) and (b) figure out what the format of the JSON file should be. Then you could add the command in your previous mail to a BAT file and run it to see what it does. You may have to add "> file.txt" or something like that so that it writes the returned data to a file for you.
[Edited at 2018-07-31 07:34 GMT]
Subject:
Comment:
The contents of this post will automatically be included in the ticket generated. Please add any additional comments or explanation (optional)
Michael79 China Local time: 17:23 English to Chinese + ...
TOPIC STARTER
thanks again
Jul 31, 2018
Your advice is much appreciated.
I will give it a try.
Have a nice day and sorry for my mistake. Your script is written in AutoIt not AHK.
Subject:
Comment:
The contents of this post will automatically be included in the ticket generated. Please add any additional comments or explanation (optional)
Manage your TMs and Terms ... and boost your translation business
Are you ready for something fresh in the industry? TM-Town is a unique new site for you -- the freelance translator -- to store, manage and share translation memories (TMs) and glossaries...and potentially meet new clients on the basis of your prior work.
Translation Office 3000 is an advanced accounting tool for freelance translators and small agencies. TO3000 easily and seamlessly integrates with the business life of professional freelance translators.