Pada Kesempatan ini kita bahas solusi nya untuk lab Use Machine Learning APIs on Google Cloud: Challenge Lab.
- Bisa sambil buka totorial -> https://www.youtube.com/watch?v=I8DzLVQz_qk
- Untuk soal no 1 dan 2 bisa ikutin tutorial tersebut
- Untuk soal no 3 – 5
Edit file analyze-images-v2.py tambahkan script berikut :
misal case nya pada language / locale japan “ja” bisa sesuaikan misal dengan negara lain sesuai soal
# TBD: Create a Vision API image object called image_object
# Ref: https://googleapis.dev/python/vision/latest/gapic/v1/types.html#google.cloud.vision_v1.types.Image
from google.cloud import vision_v1
import io
client=vision.ImageAnnotatorClient()
# TBD: Detect text in the image and save the response data into an object called response
# Ref: https://googleapis.dev/python/vision/latest/gapic/v1/api.html#google.cloud.vision_v1.ImageAnnotatorClient.document_text_detection
image = vision_v1.types.Image(content=file_content)
response = client.text_detection(image=image)
# TBD: Save the description as the translated text into target_language eg. 'en', 'fe', and 'ja' according to the lab manual .
if locale == 'ja':
translated_text = desc
else:
# TBD: According to the target language pass the description data to the translation API
# ref: https://googleapis.dev/python/translation/latest/client.html#google.cloud.translate_v2.client.Client.translate
# Set the target_language locale to according to the lab activity)
from google.cloud import translate_v2 as translate
translation = translate_client.translate(text_data, target_language='ja')
translated_text = translation['translatedText']
print(translated_text)
Setelah itu bisa running script berikut dari cloudshell sesuaikan dengan project dan bucket
python analyze-images-v2.py qwiklabs-gcp-03-175d8e47fa2c qwiklabs-gcp-03-175d8e47fa2
