1-hr tech talk introducing Machine Learning and the GCP ML APIs and other Google Cloud developer tools to a technical audience:
Easier onramp to getting into AI/ML by using GCP AI/ML APIs (Vision, Video Intelligence, Natural Language, Speech-to-Text, Text-to-Speech, Translation) backed by single-task pre-trained models found in Vertex AI, AutoML for finetuning those pre-trained models, and other "friends of AI/ML" Google dev tools & platforms that can help: BigQuery (data warehouse & analysis), Cloud SQL+AlloyDB & Firestore (SQL & NoSQL databases), serverless platforms (App Engine, Cloud Functions, Cloud Run), and introducing the Gemini API (from both Google AI and GCP Vertex AI)
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Easy path to machine learning (2023-2024)
1. Google developer tools (mainly GCP) & an
Easyier path to machine learning
Mountain View :: Winter 2024
Wesley Chun
Principal, CyberWeb
@wescpy@
Principal Consultant, CyberWeb
● Mission: produce accelerated Python
developers, enable developers to be
successful using Google Cloud and
other Google developer tools & APIs
● Focus: Python, Google Cloud (GCP) &
Google Workspace (GWS) APIs; GAE
migrations; Google X-product sol'ns
● Services: technical consulting,
training, engineering, speaking, code
samples, hands-on tutorials, public
technical content (blogs, social, etc.)
About the speaker
Previous experience / background
● Software Engineer & Developer Advocate
○ Google, Sun, HP, Cisco, EMC, Xilinx &
○ Original Yahoo!Mail engineer/SWE
● Technical trainer, teacher, instructor
○ Teaching Math, Linux, Python since '83
○ Adjunct CS Faculty at local SV colleges
● Python community member
○ Popular Core Python series author
○ Python Software Foundation Fellow
● AB (Math/CS) & CMP (Music/Piano), UC
Berkeley and MSCS, UC Santa Barbara
● Adjunct Computer Science Faculty, Foothill
College (Silicon Valley)
GWS Dev Show
goo.gl/JpBQ40
GAE migration
bit.ly/3xk2Swi
2. AI & ML session: why & agenda
● Big data is everywhere, giving rise to increasingly challenging problems
● AI/ML analyzes data, gives novel insight, and produces new content
● Requiring certain level of math/statistics gives AI/ML learning curve
● APIs backed by ML provides an easier path: if you can call APIs. you can...
● Leverage the power of ML, gain experience, and accelerate learning
What is ML?
1
Introducing
Google Cloud
2
Google APIs
primer
3
Cloud ML APIs
4 5
Other Google
devtools & APIs
7
Wrap-up
6
Inspiration
01
What is machine learning?
Can we make computers "smarter?"
3. AI
Solve problems by
"mimicking" human
intelligence
(logic/rules-based)
ML
Learn from observed
patterns in massive
data sets & formulate
informed decisions
from those insights
DL
More sophisticated ML
models learning with no
human intervention; use
neural networks to
tackle more complex
problems
4. AI & machine learning
Puppy or muffin?
Source: twistedsifter.com/2016/03/
puppy-or-bagel-meme-gallery
Machine learning is learning
from rules plus experience.
6. Three different ways to train ML models
1. Supervised learning
2. Unsupervised learning
3. Reinforcement learning
7. Deep Learning model types
Discriminative/Predictive AI
● Used to classify or predict
● Typically trained on labeled dataset
● Learns relationship between data point features and labels
Generative AI (single-use or multimodal)
● Generates new data similar to data a model was trained on
● Understands distribution of data & how likely a given example is
● Can "predict" the next or similar "item" in dataset
Global view
Problem
● 1B ppl depend on seafood
● 85% at/over-fishing or recovering
● 20% caught illegal, undoc'd, unreg'd
● Analysts monitoring unscalable
One solution
● globalfishingwatch.org/map
● Machine-learning classifiers:
○ Ship type: cargo, tug, sail, fishing
○ Ship size
○ Gear: longline, purse seine, trawl
○ Movement tracking: when and
where vessels are fishing
9. Organize data
Use machines to
flesh out the
model from data
Collect
data
Create model
Deploy fleshed
out model
In reality what ML is
Large Datasets Good Models Lots Of Computation
Keys to Successful Machine Learning
11. Vertex AI task-specific models: ML "building block" APIs
● Gain insights from data using GCP's
pre-trained machine learning models
● Leverage the same technology as Google
Translate, Photos, and Assistant
● Requires ZERO prior knowledge of ML
● If you can call an API, you can use AI/ML!
● cloud.google.com/products/ai/building-blocks
Vision Video
Intelligence
Speech
(S2T & T2S)
Natural
Language
Translation
Full Spectrum of AI & ML Offerings
App developer Data scientist,
developer
Data scientist, Researcher
(w/infrastructure access &
DevOps/SysAdmin skills)
Vertex AI
platform
Build custom models,
use OSS SDK on fully-
managed infrastructure
Single-task
model APIs
App developer,
data scientist
Use or fine-tune
pre-built models
Use pre-built/pre-
trained models
Build custom models, use/
extend OSS SDK, self-manage
training infrastructure
LMM/large
multimodal
model API
Auto ML
13. General steps
1. Go to Cloud Console
2. Login to Google/Gmail account
(Workspace domain may require admin approval)
3. Create project (per application)
4. Enable APIs to use
5. Enable billing (CC, Free Trial, etc.)
6. Download client library(ies)
7. Create & download credentials
8. Write code*
9. Run code (may need to authorize)
Google APIs: how to use
*In your code
1. Import API client library
2. Create API client object
3. Use client to make API Calls
Costs & pricing
● GCP & GMP: pay-per-use (CC req'd)
● GWS: "subscription" (incl. $0USD/mo.)
● GMP: $200/mo. free usage
● GCP Free Trial: $300/1Q
● GCP "Always Free" tier
○ Some products have free tier
○ Daily or monthly quota
○ Must exceed to incur billing
● More on both programs at
cloud.google.com/free
14. Cloud/GCP console
console.cloud.google.com
● Hub of all developer activity
● Applications == projects
○ New project for new apps
○ Projects have a billing acct
● Manage billing accounts
○ Financial instrument required
○ Personal or corporate credit cards,
Free Trial, and education grants
● Access GCP product settings
● Manage users & security
● Manage APIs in devconsole
● View application statistics
● En-/disable Google APIs
● Obtain application credentials
Using Google APIs
goo.gl/RbyTFD
API manager aka Developers Console (devconsole)
console.developers.google.com
15. Client libraries and credentials types
● Two different client library types
○ Platform-level client libraries (lower-level)
■ Multiple product groups as a "lowest-common denominator"
■ Install: developers.google.com/api-client-library
○ Product-level client libraries (higher-level)
■ Custom client libraries made specifically for 1 product or product group
■ Found on product or product group page(s)
● Three different credentials types
○ Simple: API keys (access public data)
■ Simplest form of authorization: an API key; tied to a project
○ Authorized: OAuth client IDs (access data owned by [human] user)
■ Provides additional layer of security via OAuth2 (RFC 6749)
○ Authorized: service accounts (access data owned by an app/robot user)
■ Provides additional layer of security via OAuth2 or JWT (RFC 7519)
Blog series:
dev.to/wescpy
&
Google APIs client
libraries for many
languages; demos in
developers.google.com/api-
client-library
cloud.google.com/apis/docs
/cloud-client-libraries
16. OAuth2 or
API key
HTTP-based REST APIs 1
HTTP
2
Google APIs request-response workflow
● Application makes request
● Request received by service
● Process data, return response
● Results sent to application
(typical client-server model)
04
Cloud ML APIs
Easier path to ML by calling APIs!
17. Machine Learning: Cloud Vision
Google Cloud Vision API lets developers
extract metadata and understand the
content of an image, identify & detect
objects/labels, text/OCR, landmarks,
logos, facial features, products, XC, etc.
cloud.google.com/vision
from google.cloud import vision
image_uri = 'gs://cloud-samples-data/vision/using_curl/shanghai.jpeg'
client = vision.ImageAnnotatorClient()
image = vision.types.Image()
image.source.image_uri = image_uri
response = client.label_detection(image=image)
print('Labels (and confidence score):')
print('=' * 30)
for label in response.label_annotations:
print(label.description, '(%.2f%%)' % (label.score*100.))
Vision: label annotation/object detection
18. $ python3 label-detect.py
Labels (and confidence score):
==============================
People (95.05%)
Street (89.12%)
Mode of transport (89.09%)
Transport (85.13%)
Vehicle (84.69%)
Snapshot (84.11%)
Urban area (80.29%)
Infrastructure (73.14%)
Road (72.74%)
Pedestrian (68.90%)
Vision: label annotation/object detection
g.co/codelabs/vision-python
Machine Learning: Cloud Natural Language
Google Cloud Natural Language API
reveals the structure and meaning
of text, performing sentiment
analysis, content classification,
entity extraction, and syntactical
structure analysis; multi-lingual
cloud.google.com/language
19. Simple sentiment & classification analysis
from google.cloud import language
TEXT = '''Google, headquartered in Mountain View, unveiled the new
Android phone at the Consumer Electronics Show. Sundar Pichai said
in his keynote that users love their new Android phones.'''
NL = language.LanguageServiceClient()
document = language.types.Document(content=TEXT,
type=language.enums.Document.Type.PLAIN_TEXT)
print('TEXT:', TEXT) # sentiment analysis
sent = NL.analyze_sentiment(document).document_sentiment
print('nSENTIMENT: score (%.2f), magnitude (%.2f)' % (sent.score, sent.magnitude))
print('nCATEGORIES:') # content classification
categories = NL.classify_text(document).categories
for cat in categories:
print('* %s (%.2f)' % (cat.name[1:], cat.confidence))
Simple sentiment & classification analysis
$ python nl_sent_simple.py
TEXT: Google, headquartered in Mountain View, unveiled the new Android
phone at the Consumer Electronics Show. Sundar Pichai said in
his keynote that users love their new Android phones.
SENTIMENT: score (0.20), magnitude (0.50)
CATEGORIES:
* Internet & Telecom (0.76)
* Computers & Electronics (0.64)
* News (0.56)
20. Machine Learning: Cloud Video Intelligence
Google Cloud Video Intelligence
API makes videos searchable, and
discoverable, by extracting
metadata. Other features: object
tracking, shot change detection,
and text detection
cloud.google.com/video-intelligence
Machine Learning: Cloud Speech
Google Cloud Speech APIs enable
developers to convert
speech-to-text and vice versa
cloud.google.com/speech
cloud.google.com/text-to-speech
21. Machine Learning: Cloud Translation
Access Google Translate
programmatically through this
API; translate an arbitrary
string into any supported
language using state-of-the-art
Neural Machine Translation
cloud.google.com/translate
Translating text "Hello World" (JS/Node.js)
const {TranslateClient} = require('@google-cloud/translate');
const TRANSLATE = new TranslateClient();
const text = 'Hello World!'; // Text to translate
const target = 'gu'; // Target language
// Translate text to Gujarti
const translation = await TRANSLATE.translate(text,
{from: 'en', to: target}));
// "Translation: હેલો વ ડર્લ્ડ"
console.log('Translation: ', translation[0]);
22. Machine Learning: AutoML
AutoML: suite of cloud APIs for
developers with limited machine
learning expertise; take task-specific
pre-trained model, perform additional
training with your data to finetune
that model
(Translation, Vision, Natural Language,
Video Intelligence, Tables)
cloud.google.com/automl
cloud.google.com/automl-tables
● What is it, and how does it work?
○ These APIs backed by pre-trained models
○ Likely less suitable for your data
○ Finetune (further customize/train) these models with your data
○ Without sophisticated ML background
○ Translate, Vision, Natural Language, Video Intelligence, Tables
○ cloud.google.com/automl
● Steps
a. Prep your training data
b. Create dataset
c. Import items into dataset
d. Train/"finetune" model
e. Evaluate/validate model
f. Make predictions
Cloud AutoML
23. Machine Learning: Vertex AI
Cloud Vertex AI (formerly AI Platform) is a
managed service providing: 1) APIs backed by
pre-trained models, 2) ability to further
train those models, 3) Jupyter Notebook
support, 4) infrastructure to build, train &
deploy ML models (PyTorch, scikit-learn,
TensorFlow) & serve models, all in 1 platform
cloud.google.com/vertex-ai
Machine Learning: Cloud Generative AI
Google Cloud Generative AI is a set of
tools & APIs (like Vertex AI & Duet
AI) that make it easier for developers
to build generative AI-powered
services & applications; includes the
Gemini foundation model as well as
open source & 3rd-party models
cloud.google.com/ai/generative-ai
24. import vertexai
import vertexai.preview.generative_models as genai
PROMPT = 'What is the meaning of life?'
MODEL = 'gemini-pro'
print('** GenAI text: %r model & prompt %rn' % (
MODEL, PROMPT))
vertexai.init()
model = genai.GenerativeModel(MODEL)
response = model.generate_content(PROMPT)
print(response.text)
Cloud Vertex AI: Gemini API
cloud.google.com/vertex-ai/docs/generative-
ai/start/quickstarts/quickstart-multimodal
import google.generativeai as genai
from settings import API_KEY
PROMPT = 'What is the meaning of life?'
MODEL = 'gemini-pro'
print('** GenAI text: %r model & prompt %rn' % (
MODEL, PROMPT))
genai.configure(api_key=API_KEY)
model = genai.GenerativeModel(MODEL)
response = model.generate_content(PROMPT)
print(response.text)
Google AI: Gemini API
ai.google.dev/tutorials
25. 05
Other GCP & Google
APIs & developer tools
These may also be helpful
Other Cloud APIs/services
"Friends of AI/ML" companion services
26. Storing and Analyzing Data: BigQuery
Google BigQuery: fully-managed data
warehouse for large-scale data
analytics with built-in machine
learning (BQML); issue SQL queries
across multi-terabytes of data. BQ
Sandbox lets anyone query up to
1TB/mo for free with no obligation
cloud.google.com/bigquery
BigQuery: querying Shakespeare words
TITLE = "The most common words in all of Shakespeare's works"
QUERY = '''
SELECT LOWER(word) AS word, sum(word_count) AS count
FROM [bigquery-public-data:samples.shakespeare]
GROUP BY word ORDER BY count DESC LIMIT 10
'''
rsp = BQ.jobs().query(body={'query': QUERY}, projectId=PROJ_ID).execute()
print('n*** Results for %r:n' % TITLE)
print('t'.join(col['name'].upper() # HEADERS
for col in rsp['schema']['fields']))
print('n'.join('t'.join(str(col['v']) # DATA
for col in row['f']) for row in rsp['rows']))
27. Top 10 most common Shakespeare words
$ python bq_shake.py
*** Results for "The most common words in all of Shakespeare's works":
WORD COUNT
the 29801
and 27529
i 21029
to 20957
of 18514
a 15370
you 14010
my 12936
in 11722
that 11519
● BigQuery public data sets: cloud.google.com/bigquery/public-data
● BQ sandbox (1TB/mo free): cloud.google.com/bigquery/docs/sandbox (see blog post)
● Other public data sets: cloud.google.com/public-datasets (Google Cloud),
research.google/tools/datasets (Google Research), and Kaggle (kaggle.com)
● COVID-19 BigQuery data sets
○ How to use our data sets (see blog post)
○ JHU Coronavirus COVID-19 Global Cases data set
○ List of all COVID-19 data sets
● Cloud Life Sciences API: cloud.google.com/life-sciences (see blog post)
● Cloud Healthcare API: cloud.google.com/healthcare (see blog post)
BigQuery and public data sets
28. Storing Data: Cloud Storage, Filestore, Persistent Disk
cloud.google.com/storage
cloud.google.com/filestore
cloud.google.com/persistent-disk
Storing Data: Cloud SQL & AlloyDB
Relational DB servers in the cloud;
High-performance, fully-managed
600MB to 416GB RAM; up to 64 vCPUs
Up to 10 TB storage; 40,000 IOPS
Types:
MySQL
Postgres; AlloyDB for high perf
SQLServer
cloud.google.com/databases
cloud.google.com/{sql, alloydb}
29. Storing Data: Cloud Firestore
The best of both worlds: the next
generation of Cloud Datastore
(w/product rebrand) plus features
from the Firebase realtime database
(For choosing between Firebase & Cloud Firestore: see
firebase.google.com/docs/firestore/rtdb-vs-firestore;
for choosing between Firestore Datastore & Firestore Native modes:
see cloud.google.com/datastore/docs/firestore-or-datastore)
cloud.google.com/firestore
Google Workspace: Google Sheets
Sheets API gives you programmatic
access to spreadsheets; perform
(w/code) almost any action you can
do from the web interface as a user
developers.google.com/sheets
30. Try our Node.js customized reporting tool codelab:
g.co/codelabs/sheets
Why use the Sheets API?
data visualization
customized reports
Sheets as a data source
Migrate SQL data to a Sheet
# read SQL data then create new spreadsheet & add rows into it
FIELDS = ('ID', 'Customer Name', 'Product Code',
'Units Ordered', 'Unit Price', 'Status')
cxn = sqlite3.connect('db.sqlite')
cur = cxn.cursor()
rows = cur.execute('SELECT * FROM orders').fetchall()
cxn.close()
rows.insert(0, FIELDS)
DATA = {'properties': {'title': 'Customer orders'}}
SHEET_ID = SHEETS.spreadsheets().create(body=DATA,
fields='spreadsheetId').execute().get('spreadsheetId')
SHEETS.spreadsheets().values().update(spreadsheetId=SHEET_ID, range='A1',
body={'values': rows}, valueInputOption='RAW').execute()
Migrate SQL data
to Sheets
goo.gl/N1RPwC
31. Google and Jupyter Notebooks
Users have many ways to access an indispensable data science tool
● Google Cloud Vertex AI Workbench
○ cloud.google.com/notebooks
● Kaggle
○ kaggle.com
● Google Research CoLaboratory
○ colab.research.google.com
● Google Cloud Dataproc Hub
○ cloud.google.com/dataproc/docs/tutorials/dataproc-hub-overview
● Google Cloud Datalab
○ cloud.google.com/datalab/docs/how-to/working-with-notebooks
Where to run your code (without VMs)
GCP/GWS serverless compute platforms
32. cloud.google.com/hosting-options#hosting-options
Google Cloud compute option spectrum
Compute
Engine
Kubernetes
Engine (GKE)
Cloud Run
on Anthos
Cloud Run
(fully-mgd)
App Engine
(Flexible)
App Engine
(Standard)
Cloud
Functions
> Google Compute Engine configurable
VMs of all shapes & sizes, from
"micro" to 416 vCPUs, 11.776 TB
RAM, 256 TB HDD/SSD plus Google
Cloud Storage for data lake "blobs"
(Debian, CentOS, CoreOS, SUSE, Red Hat Enterprise Linux,
Ubuntu, FreeBSD; Windows Server 2008 R2, 2012 R2, 2016, 1803,
1809, 1903/2019, 1909)
cloud.google.com/compute
cloud.google.com/storage
Yeah, there are VMs & big disk… but why*?
33. Serverless: what & why
● What is serverless?
○ Misnomer (a "PMM") :-)
○ "No worries"
○ Developers focus on writing code & solving business problems*
○ Servers (physical & virtual) completely abstracted away from the user*
● Why serverless?
○ Fastest growing segment of cloud... per analyst research:
■ $1.9B (2016) and $4.25B (2018) ⇒ $7.7B (2021), $14.93B (2023), and $21.1B (2025)^
■ $4.18B (2018) and $6.05B (2020) ⇒ $31.53B (2026) and $53.08B (2028)†
○ What if you go viral? Autoscaling: your new best friend
○ What if you don't? Code not running? You're not paying.
* Forbes (May 2018)
^ (in USD) CB Insights (Sep 2018), MarketsandMarkets™ (Jan 2019)
† (in USD) Reports and Data (Jul 2019 , Jan 2020, and Oct 2021)
Running Code: App Engine
Got a great app idea? Now what?
VMs? Operating systems? Big disk?
Web servers? Load balancing?
Database servers? Autoscaling?
With App Engine, you don't think
about those. Just upload your
code; GCP takes care of the rest.
>
cloud.google.com/appengine
34. Why does App Engine exist?
● Focus on code not DevOps
○ Web app or mobile backend
● Enhance productivity
● Deploy globally
● Fully-managed
● Auto-scaling
● Pay-per-use
● Familiar languages
● Test w/local dev server
● "Bundled" services like DB,
caching, tasks, storage, etc.
Hello World (Python "MVP")
app.yaml
runtime: python39
main.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World!'
requirements.txt
flask
Deploy:
$ gcloud app deploy
Access globally:
PROJECT_ID.appspot.com
cloud.google.com/appengine/docs/standard/python3/quickstart
35. Running Code: Cloud Functions
Don't have an entire app? Just want
to deploy small microservices or
"RPCs" online globally? That's what
Google Cloud Functions are for!
(+Firebase version for mobile apps)
cloud.google.com/functions
firebase.google.com/products/functions
Why does Cloud Functions exist?
● Don't have entire app?
○ No framework "overhead" (LAMP, MEAN...)
○ Deploy short utilities (alerts, ETL...), monoliths →
loosely-coupled microservices, event-driven tasks
● Event-driven
○ Triggered via HTTP or background events
■ Pub/Sub, Cloud Storage, Firebase, etc.
○ Auto-scaling & highly-available; pay per use
● Flexible development environment
○ Cmd-line or developer console (in-browser)
○ Develop/test locally with Functions Framework
● Cloud Functions for Firebase
○ Mobile app use-cases
36. main.py
def hello_world(request):
return 'Hello World!'
Deploy:
$ gcloud functions deploy hello --runtime python39 --trigger-http
Access globally (curl):
$ curl REGION-PROJECT_ID.cloudfunctions.net/hello
Access globally (browser):
https://REGION-PROJECT_ID.cloudfunctions.net/hello
Hello World (Python "MVP")
cloud.google.com/functions/docs/quickstart-python
Running Code: Cloud Run
Got a containerized app? Want its
flexibility along with the convenience
of serverless that's fully-managed
plus auto-scales? Google Cloud Run is
exactly what you're looking for!
Need custom HW? Cloud Run on GKE
cloud.google.com/run
37. The rise of containers... ● Any language
● Any library
● Any binary
● Ecosystem of base images
● Industry standard
FLEXIBILITY
“We can’t be locked in.”
“How can we use
existing binaries?”
“Why do I have to choose between
containers and serverless?”
“Can you support language _______ ?”
Serverless inaccessible for some...
CONVENIENCE
38. Cloud Run: code, build, deploy .js .rb .go
.sh
.py ...
● Any language, library, binary
○ HTTP port, stateless
● Bundle into container
○ Build with Docker OR Cloud Build
○ Image ⇒ Container/Artifact Registry
● Deploy to Cloud Run (managed or GKE)
● GitOps: CD push-to-deploy from Git
○ See documentation & announcement
○ CI/CD with GitHub Actions tutorial
● Cloud Buildpacks: Docker, Dockerfiles,
and knowledge of containers optional
State
HTTP
Hello World (Python "MVP")
main.py
import os
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080)))
cloud.google.com/run/docs/quickstarts/build-and-deploy
requirements.txt
flask
39. Hello World (Python "MVP")
Dockerfile
FROM python:3-slim
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["python", "main.py"]
.dockerignore
Dockerfile
README.md
*.pyc
*.pyo
.git/
__pycache__
Build (think docker build and docker push) then deploy (think docker run):
$ gcloud builds submit --tag gcr.io/PROJ_ID/IMG_NAME
$ gcloud run deploy SVC_NAME --image gcr.io/PROJ_ID/IMG_NAME
OR… Build and Deploy (1-line combination of above commands):
$ gcloud run deploy SVC_NAME --source .
Access globally:
SVC_NAME-HASH-REG_ABBR.a.run.app
Docker &
Dockerfile
OPTIONAL!!
Flexibility in options
Cloud
Functions
App
Engine
Cloud
Run
local
server
● "Nebulous" sample web app
○ Flask/Python 2 or 3
○ Express/Node.js 10+
○ Uses Cloud Translation API
● Deployable to on-prem server
● Also GCP serverless compute
○ App Engine
○ Cloud Functions
○ Cloud Run
● With only config changes
● No changes to app code
Cloud
Translation
My "Google Translate" MVP
goo.gle/2Y0ph5q
youtu.be/eTotLOVR7MQ
40. 06
Inspiration
Use multiple Google APIs
to create unique solutions
Cloud image processing workflow
Archive and analyze GWS data (images) with GCP
44. Cloud image processing workflow
def drive_get_file(fname):
rsp = DRIVE.files().list(q="name='%s'" % fname).execute().get['files'][0]
fileId, fname, mtype = rsp['id'], rsp['name'], rsp['mimeType']
blob = DRIVE.files().get_media(fileId).execute()
return fname, mtype, rsp['modifiedTime'], blob
def gcs_blob_upload(fname, bucket, blob, mimetype):
body = {'name': fname, 'uploadType': 'multipart',
'contentType': mimetype}
return GCS.objects().insert(bucket, body, blob).execute()
def vision_label_img(img, top):
body = {'requests': [{'image': {'content': img}, 'features':
[{'type': 'LABEL_DETECTION', 'maxResults': top}]}]}
rsp = VISION.images().annotate(
body=body).execute().get('responses', [{}])[0]
return ', '.join('%s (%.2f%%)' % (label['description'],
label['score']*100.) for label in rsp['labelAnnotations'])
def sheet_append_row(sheet, row):
rsp = SHEETS.spreadsheets().values().append(
spreadsheetId=sheet, range='Sheet1',
body={'values': rows}).execute()
return rsp.get('updates').get('updatedCells')
def main(fname, bucket, sheet_id, top):
fname, mtype, ftime, data = drive_get_img(fname)
gcs_blob_upload(fname, bucket, data, mtype)
rsp = vision_label_img(data, top)
sheet_append_row(sheet_id, [fname, mtype,
ftime, len(data), rsp])
API method calls in Bold
Driver calls in Bold Italics
● Project goal: Imagining an actual enterprise use case and solve it!
● Specific goals: free-up highly-utilized resource, archive data to
colder/cheaper storage, analyze images, generate report for mgmt
● Download image binary from Google Drive
● Upload object to Cloud Storage bucket
● Send payload for analysis by Cloud Vision
● Write back-up location & analysis results into Google Sheets
● Blog post: goo.gle/3nPxmlc (original post); Cloud X-post
● Codelab: free, online, self-paced, hands-on tutorial
● g.co/codelabs/drive-gcs-vision-sheets
● Application source code
● github.com/wescpy/analyze_gsimg
App summary
45. Hangouts Chat Productivity Tracker
Chat bot that's GCP & Google Workspace (formerly G Suite) aware
Productivity tracker Hangouts Chat bot
Google Workspace
(formerly G Suite)
GCP
Sheets Natural Language
START
or LOG
END
Hangouts
Chat
App
Engine
Cloud
SQL
46. App summary
● Motivation
● Do coding contract jobs during school year
● Needed to track time spent on work (and non-work)
● Who doesn't want to be more productive?
● Hangouts Chat bot framework & API... build bots to:
● Automate workflows
● Query for information
● Other heavy-lifting
● Google Workspace (formerly G Suite) app that leverages app-hosting, NL processing, and storage
tools from GCP
● Application source code
● github.com/gsuitedevs/hangouts-chat-samples/tree/master/python/productivity_tracker
● Presented at GDG Silicon Valley (Aug 2018)
● meetup.com/gdg-silicon-valley/events/252858660
47. 07
Wrap-up
Summary & resources
Summary: AI & ML session
● What is machine learning again?
○ Solving harder problems by making computers smarter
○ "Using data to answer questions.” ~Yufeng Guo, Google Cloud
● How do you do machine learning again?
○ Collect lots of data
○ Build and train your model then validate it
○ Use your model to make predictions on new data
● Do you need lots of machine learning experience to get started?
○ No: use pre-trained models available via APIs
○ No: need to do training? Consider using AutoML APIs
○ Build your experience then use standard OSS library when ready
48. ● Documentation (most APIs have "Quickstarts")
○ GCP: cloud.google.com/{docs,appengine,functions,run,vision,automl,translate,language,
speech,texttospeech,video-intelligence,firestore,bigquery,compute,storage,gpu,tpu}
○ GWS: developers.google.com/{gsuite,drive,calendar,gmail,docs,sheets,slides,apps-script}
● Introductory "codelabs" ([free] self-paced, hands-on tutorials)
○ GWS APIs: g.co/codelabs/gsuite-apis-intro (featuring Drive API)
○ Apps Script: g.co/codelabs/apps-script-intro
○ App Engine: codelabs.developers.google.com/codelabs/cloud-app-engine-python
○ Cloud Functions: codelabs.developers.google.com/codelabs/cloud-starting-cloudfunctions
○ Cloud Run: codelabs.developers.google.com/codelabs/cloud-run-hello-python3
○ Others: g.co/codelabs (all Google codelabs) and g.co/codelabs/cloud (GCP-only)
● Videos: youtube.com/GoogleCloudPlatform (GCP) and goo.gl/JpBQ40 (GWS)
● Code samples: github.com/GoogleCloudPlatform (GCP) and github.com/googleworkspace (GWS)
● Cloud Free Trial (new users) and Always Free (daily/monthly tier) programs: cloud.google.com/free
● Know AWS/Azure? Compare with GCP products at cloud.google.com/docs/compare/aws
● Language support: cloud.google.com/{python,java,nodejs,go,php,ruby,dotnet}
Resources (industry)
quickdraw.withgoogle.com
Cloud Vision demo: Quick Draw game
experiments.withgoogle.com/quick-draw
49. FYI and FYA (if you/your students love comics)
cloud.google.com/products/ai/ml-comic-[12]
... ...
Other Google APIs & platforms
● Google Workspace (G Suite) (code Gmail, Drive, Docs, Sheets, Slides!)
○ developers.google.com/gsuite
● Firebase (mobile development platform and RT DB plus ML-Kit)
○ firebase.google.com and firebase.google.com/docs/ml-kit
● Google Data Studio (data visualization, dashboards, etc.)
○ datastudio.google.com/overview
○ goo.gle/datastudio-course
● Actions on Google/Assistant/DialogFlow (voice apps)
○ developers.google.com/actions
● YouTube (Data, Analytics, and Livestreaming APIs)
○ developers.google.com/youtube
● Google Maps (Maps, Routes, and Places APIs)
○ developers.google.com/maps
● Flutter (native apps [Android, iOS, web] w/1 code base[!])
○ flutter.dev
50. Bring me to your organization
... it is my job to help you!
● "Transfer of Info" tech talks
● Half- or full-day seminars
● Hands-on "codelab" workshops
● Multi-day training courses
● Engineering consulting
● Migration strategy & planning
● cyberwebconsulting.com
● appenginemigration.com
Slides
you're looking
at them now
Work
cyberwebconsulting.com
Books
corepython.com
Blog
dev.to/wescpy
Img proc wkflw
goo.gle/3nPxmlc
AI/ML codelabs
codelabs.developers.google.com/?
category=aiandmachinelearning
Nebulous serverless
goo.gle/2Y0ph5q
youtu.be/eTotLOVR7MQ
Progress bars
goo.gl/69EJVw
Thank you! Questions?
Wesley Chun
Principal Consultant, CyberWeb
Python, GCP & GWS specialist
@wescpy (Tw/X, SO, GH, IG, LI)