O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Powerful Google Cloud tools for your hack (2020)

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Powerful Google Cloud
tools for your hack
Wesley Chun
Developer Advocate, Google
Adjunct CS Faculty, Foothill College
G Su...
Why and Agenda
● How Google Cloud can help with your hack
● Can't hurt to learn a bit more about cloud computing
● Cloud s...
What is Google Cloud Platform?
Getting things done using someone else’s computers, especially
where someone else worries a...
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Carregando em…3
×

Confira estes a seguir

1 de 49 Anúncio

Powerful Google Cloud tools for your hack (2020)

Baixar para ler offline

You may know Google for search, YouTube, Android, Chrome, and Gmail, but did you know Google has many other cloud services? This session takes hackathon participants on a deeper dive from the opening ceremony lightning intro. In this comprehensive yet still high-level overview of Google Cloud tools & APIs with the purpose of inspiring students for their hacks. We'll look closely at our serverless platforms & machine learning APIs, tools that have an immediate impact on projects, alleviating the need to think about computing infrastructure as well as dispensing with the need to have machine learning expertise. We'll wrap up w/online resources like videos & hands-on tutorials to get you started so you'll know what to do with those Cloud credits you got from MLH!

You may know Google for search, YouTube, Android, Chrome, and Gmail, but did you know Google has many other cloud services? This session takes hackathon participants on a deeper dive from the opening ceremony lightning intro. In this comprehensive yet still high-level overview of Google Cloud tools & APIs with the purpose of inspiring students for their hacks. We'll look closely at our serverless platforms & machine learning APIs, tools that have an immediate impact on projects, alleviating the need to think about computing infrastructure as well as dispensing with the need to have machine learning expertise. We'll wrap up w/online resources like videos & hands-on tutorials to get you started so you'll know what to do with those Cloud credits you got from MLH!

Anúncio
Anúncio

Mais Conteúdo rRelacionado

Diapositivos para si (20)

Semelhante a Powerful Google Cloud tools for your hack (2020) (20)

Anúncio

Mais recentes (20)

Anúncio

Powerful Google Cloud tools for your hack (2020)

  1. 1. Powerful Google Cloud tools for your hack Wesley Chun Developer Advocate, Google Adjunct CS Faculty, Foothill College G Suite Dev Show goo.gl/JpBQ40 About the speaker Developer Advocate, Google Cloud ● Mission: enable current and future developers everywhere to be successful using Google Cloud and other Google developer tools & APIs ● Videos: host of the G Suite Dev Show on YouTube ● Blogs: developers.googleblog.com & gsuite-developers.googleblog.com ● Twitters: @wescpy, @GoogleDevs, @GSuiteDevs Previous experience / background ● Software engineer & architect for 20+ years ● One of the original Yahoo!Mail engineers ● Author of bestselling "Core Python" books (corepython.com) ● Technical trainer, teacher, instructor since 1983 (Computer Science, C, Linux, Python) ● Fellow of the Python Software Foundation ● AB (Math/CS) & CMP (Music/Piano), UC Berkeley and MSCS, UC Santa Barbara ● Adjunct Computer Science Faculty, Foothill College (Silicon Valley)
  2. 2. Why and Agenda ● How Google Cloud can help with your hack ● Can't hurt to learn a bit more about cloud computing ● Cloud skills are in-demand in today's workforce ● Show how to get started with Google Cloud Cloud computing & Google Cloud 1 Hosting your code 2 Google APIs primer 3 Machine Learning 4 5 Other APIs to consider 6 Wrap-up 01 Cloud computing & Google Cloud Intro and overview
  3. 3. What is Google Cloud Platform? Getting things done using someone else’s computers, especially where someone else worries about maintenance, provisioning, system administration, security, networking, failure recovery, etc. Google Compute Engine, Google Cloud Storage AWS EC2 & S3; Rackspace; Joyent Cloud service levels/"pillars" SaaS Software as a Service PaaS Platform as a Service IaaS Infrastructure as a Service Google BigQuery, Cloud SQL, Cloud Datastore, NL, Vision, Pub/Sub AWS Kinesis, RDS; Windows Azure SQL, Docker Google Apps Script, App Maker Salesforce1/force.com G Suite (Google Apps) Yahoo!Mail, Hotmail, Salesforce, Netsuite Google App Engine, Cloud Functions Heroku, Cloud Foundry, Engine Yard, AWS Lambda
  4. 4. Google Compute Engine, Google Cloud Storage AWS EC2 & S3; Rackspace; Joyent Outsourcing of apps (SaaS) SaaS Software as a Service PaaS Platform as a Service IaaS Infrastructure as a Service Google BigQuery, Cloud SQL, Cloud Datastore, NL, Vision, Pub/Sub AWS Kinesis, RDS; Windows Azure SQL, Docker Google Apps Script, App Maker Salesforce1/force.com Google App Engine, Cloud Functions Heroku, Cloud Foundry, Engine Yard, AWS Lambda G Suite (Google Apps) Yahoo!Mail, Hotmail, Salesforce, Netsuite Google Compute Engine, Google Cloud Storage AWS EC2 & S3; Rackspace; Joyent Outsourcing of hardware (IaaS) SaaS Software as a Service PaaS Platform as a Service IaaS Infrastructure as a Service Google BigQuery, Cloud SQL, Cloud Datastore, NL, Vision, Pub/Sub AWS Kinesis, RDS; Windows Azure SQL, Docker Google Apps Script, App Maker Salesforce1/force.com G Suite (Google Apps) Yahoo!Mail, Hotmail, Salesforce, Netsuite Google App Engine, Cloud Functions Heroku, Cloud Foundry, Engine Yard, AWS Lambda
  5. 5. Google Compute Engine, Google Cloud Storage AWS EC2 & S3; Rackspace; Joyent Outsourcing of logic-hosting (PaaS) SaaS Software as a Service PaaS Platform as a Service IaaS Infrastructure as a Service Google BigQuery, Cloud SQL, Cloud Datastore, NL, Vision, Pub/Sub AWS Kinesis, RDS; Windows Azure SQL, Docker Google Apps Script, App Maker Salesforce1/force.com G Suite (Google Apps) Yahoo!Mail, Hotmail, Salesforce, Netsuite Google App Engine, Cloud Functions Heroku, Cloud Foundry, Engine Yard, AWS Lambda Google Compute Engine, Google Cloud Storage AWS EC2 & S3; Rackspace; Joyent IaaS/PaaS gray area (DataB/S/P-aaS?) SaaS Software as a Service PaaS Platform as a Service IaaS Infrastructure as a Service Google Apps Script, App Maker Salesforce1/force.com G Suite (Google Apps) Yahoo!Mail, Hotmail, Salesforce, Netsuite Google App Engine, Cloud Functions Heroku, Cloud Foundry, Engine Yard, AWS Lambda Google BigQuery, Cloud SQL, Cloud Datastore, NL, Vision, Pub/Sub AWS Kinesis, RDS; Windows Azure SQL, Docker
  6. 6. Google Compute Engine, Google Cloud Storage AWS EC2 & S3; Rackspace; Joyent SaaS/PaaS gray area SaaS Software as a Service PaaS Platform as a Service IaaS Infrastructure as a Service Google BigQuery, Cloud SQL, Cloud Datastore, NL, Vision, Pub/Sub AWS Kinesis, RDS; Windows Azure SQL, Docker G Suite (Google Apps) Yahoo!Mail, Hotmail, Salesforce, Netsuite Google App Engine, Cloud Functions Heroku, Cloud Foundry, Engine Yard, AWS Lambda Google Apps Script, App Maker Salesforce1/force.com Summary of responsibility SaaS Software as a Service Applications Data Runtime Middleware OS Virtualization Servers Storage Networking Applications Data Runtime Middleware OS Virtualization Servers Storage Networking IaaS Infrastructure as a Service Applications Data Runtime Middleware OS Virtualization Servers Storage Networking PaaS Platform as a Service Managed by YOU Managed by cloud vendor Applications Data Runtime Middleware OS Virtualization Servers Storage Networking on-prem all you, no cloud
  7. 7. Theme - Spec/Reqs Logistics - Design app Space - Provision HW Food - Build & serve app Manage - Manage app on-prem (DIY) IaaS (Compute Engine) PaaS (App Engine/GCF) SaaS (G Suite) Pick theme Plan party Find space Cook On-call Pick theme Plan party Rent hall Cook On-call Pick theme Plan party Rent hall Hire Caterer Hire manager Pick theme Hire planner Rent hall Hire caterer Hire manager Imagine you’re hosting a party... YOUR NEXT APP? google.com/datacenter
  8. 8. What is Google Cloud Platform? GCP lets you host & run code (web apps, mobile backends, web services, containers), store & analyze data, and much more, all on Google’s highly-scalable & reliable computing infrastructure
  9. 9. What is Google Cloud Platform?some Google Cloud Platform products Compute Big Data BigQuery Cloud Dataflow Cloud Dataproc Cloud Datalab Cloud Pub/Sub Genomics Storage & Databases Cloud Storage Cloud Bigtable Cloud Datastore Cloud SQL Cloud Spanner Persistent Disk Machine Learning Cloud ML Engine Cloud Vision API Cloud Speech APIs Cloud Natural Language API Cloud Translation API Cloud Jobs API Data Studio Cloud Dataprep Cloud Video Intelligence API AutoML suite Compute Engine App Engine Kubernete s Engine GPU Cloud Functions Container- Optimized OS Identity & Security Cloud IAM Cloud Resource Manager Cloud Security Scanner Key Management Service BeyondCorp Data Loss Prevention API Identity-Aware Proxy Security Key Enforcement Internet of Things Cloud IoT Core Transfer Appliance Cloud Firestore 02 Hosting your code on GCP serverless/PaaS
  10. 10. What is Google Cloud Platform?some Google Cloud Platform products (tl;dr) Compute Big Data BigQuery Cloud Dataflow Cloud Dataproc Cloud Datalab Cloud Pub/Sub Genomics Storage & Databases Cloud Storage Cloud Bigtable Cloud Datastore Cloud SQL Cloud Spanner Persistent Disk Machine Learning Cloud ML Engine Cloud Vision API Cloud Speech APIs Cloud Natural Language API Cloud Translation API Cloud Jobs API Data Studio Cloud Dataprep Cloud Video Intelligence API AutoML auite Compute Engine App Engine Kubernete s Engine GPU Cloud Functions Container- Optimized OS Identity & Security Cloud IAM Cloud Resource Manager Cloud Security Scanner Key Management Service BeyondCorp Data Loss Prevention API Identity-Aware Proxy Security Key Enforcement Transfer Appliance Cloud Firestore Internet of Things Cloud IoT Core > Google Compute Engine configurable VMs of all shapes & sizes, from "micro" to 416 vCPUs, 11.75 TB RAM, 64 TB HDD/SSD plus Google Cloud Storage for blobs/cloud data lake (Debian, CentOS, CoreOS, SUSE, Red Hat Enterprise Linux, Ubuntu, FreeBSD; Windows Server 2008 R2, 2012 R2, 2016) cloud.google.com/compute cloud.google.com/storage Yeah, we got VMs & big disk… but why?
  11. 11. Serverless: what & why ● What is serverless? ○ Misnomer ○ "No worries" ○ Developers focus on writing code & solving business problems* ● Why serverless? ○ Fastest growing segment of cloud... per analyst research*: ■ $1.9B (2016) and $4.25B (2018) ⇒ $7.7B (2021) and $14.93B (2023) ○ What if you go viral? Autoscaling: your new best friend ○ What if you don't? Code not running? You're not paying. * in USD; source:Forbes (May 2018), MarketsandMarkets™ & CB Insights (Aug 2018) Google Compute Engine, Google Cloud Storage AWS EC2 & S3; Rackspace; Joyent SaaS Software as a Service PaaS Platform as a Service IaaS Infrastructure as a Service G Suite (Google Apps) Yahoo!Mail, Hotmail, Salesforce, Netsuite Google App Engine, Cloud Functions Heroku, Cloud Foundry, Engine Yard, AWS Lambda Google BigQuery, Cloud SQL, Cloud Datastore, NL, Vision, Pub/Sub AWS Kinesis, RDS; Windows Azure SQL, Docker Serverless: PaaS-y compute/processing Google Apps Script, App Maker Salesforce1/force.com
  12. 12. Running Code: App Engine Got a great app idea? Now what? VMs? Operating systems? Big disk? Web servers? Load balancing? Database servers? Autoscaling? With Google App Engine, you don't think about those. Just upload your code; we do everything else. > cloud.google.com/appengine Why does App Engine exist?
  13. 13. App Engine to the rescue!! ● Focus on app not DevOps ● Enhance productivity ● Deploy globally ● Fully-managed ● Auto-scaling ● Pay-per-use ● Familiar standard runtimes ● 2nd gen std platforms ○ Python 3.7 ○ Java 8, 11 ○ PHP 7.2 ○ Go 1.11 ○ JS/Node.js 8, 10 ○ Ruby 2.5 Hello World (Python "MVP") app.yaml runtime: python37 main.py from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return 'Hello World!' requirements.txt Flask==1.0.2 Deploy: $ gcloud app deploy Access globally: PROJECT_ID.appspot.com Quickstart tutorial and open source repo at cloud.google.com/appengine/docs/standard/python3/quickstart
  14. 14. App Engine demo Python Flask QuickStart tutorial (also Java, Node.js, PHP, Go, Ruby) 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
  15. 15. Why does Cloud Functions exist? ● Don't have entire app? ○ No framework "overhead" (LAMP, MEAN...) ○ Deploy microservices ● 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) ● Cloud Functions for Firebase ○ Mobile app use-cases ● Available runtimes ○ JS/Node.js 6, 8, 10 ○ Python 3.7 ○ Go 1.11, 1.12 ○ Java 8 main.py def hello_world(request): return 'Hello World!' Deploy: $ gcloud functions deploy hello --runtime python37 --trigger-http Access globally (curl): curl -X POST https://GCP_REGION-PROJECT_ID.cloudfunctions.net/hello -H "Content-Type:application/json" Access globally (browser): GCP_REGION-PROJECT_ID.cloudfunctions.net/hello Hello World (Python "MVP") Quickstart tutorial and open source repo at cloud.google.com/functions/docs/quickstart-python
  16. 16. No cmd-line access? Use in-browser dev environment! ● setup ● code ● deploy ● test Cloud Functions demo Python GCF QuickStart tutorial (also in Node.js & Go)
  17. 17. 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! cloud.google.com/run Code, build, deploy .js .rb .go .sh.py ... ● Any language, library, binary ○ HTTP port, stateless ● Bundle into container ○ Build w/Docker OR ○ Google Cloud Build ○ Image ⇒ Container Registry ● Deploy to Cloud Run (managed or GKE) StateHTTP https://yourservice.run.app
  18. 18. Hello World (Python "MVP") Dockerfile FROM python:3.7 ENV APP_HOME /app ENV TARGET MyWorld WORKDIR $APP_HOME COPY . . RUN pip install Flask gunicorn CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 app:app cloud.google.com/run/docs/quickstarts/build-and-deploy or github.com/knative/docs/tree/master/docs/serving/samples/h ello-world/helloworld-python .dockerignore Dockerfile README.md *.pyc *.pyo *.pyd __pycache__ Hello World (Python "MVP") app.py import os from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): target = os.environ.get('TARGET', 'World') return 'Hello {}!'.format(target) if __name__ == '__main__': app.run(debug=True, host='0.0.0.0', port=int(os.environ.get('PORT', 8080)))
  19. 19. Hello World (Python "MVP") Build (think docker build): $ gcloud builds submit --tag gcr.io/PROJ_ID/CONT_NAME Deploy (think docker push): $ gcloud run deploy --image gcr.io/PROJ_ID/CONT_NAME --platform managed Access globally: https://CONT_NAME-RANDOM_HASH-uREGION.a.run.app 03 Google APIs primer How to access Cloud APIs
  20. 20. 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) 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
  21. 21. Navigating the Cloud console ● 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
  22. 22. 04 Machine Learning Access AI/ML w/API calls quickdraw.withgoogle.com
  23. 23. Puppy or Muffin?
  24. 24. Machine learning is learning from rules plus experience. rules data Traditional Programming answers answers data rulesMachine Learning
  25. 25. Inference Phase Training Phase answers data rules/modelMachine Learning Model predictions(new) data Google Translate
  26. 26. Google Photos Did you ever stop to notice this app has a search bar?!? Full Spectrum of AI & ML Offerings App developer Data scientist, developer Data scientist, Researcher (w/infrastructure access & DevOps/SysAdmin skills) ML EngineAuto ML Build custom models, use OSS SDK on fully- managed infrastructure ML APIs App developer, data scientist Use/customize pre-built models Use pre-built/pre- trained models Build custom models, use/ extend OSS SDK, self-manage training infrastructure
  27. 27. Machine Learning: Cloud Vision Google Cloud Vision API lets developers extract metadata and understand the content of an image, identifying & detecting objects/labels, text/OCR, facial features, landmarks, logos, products, XC, etc. cloud.google.com/vision from google.cloud import vision IMG = 'https://google.com/services/images/section-work-card-img_2x.jpg' client = vision.ImageAnnotatorClient() image = vision.types.Image() image.source.image_uri = IMG response = client.label_detection(image=image) print('** Labels detected (and confidence score):') for label in response.label_annotations: print('%s (%.2f%%)' % (label.description, label.score*100.)) response = client.face_detection(image=image) print('n** Facial features detected (and likelihood):') for label in response.face_annotations: for likelihood in dir(label): if likelihood.endswith('_likelihood'): llh = str(vision.enums.Likelihood(getattr(label, likelihood))).split('.')[1].replace('_', ' ').lower() print('%s: %s' % (likelihood.split('_')[0].title(), llh)) Vision: image analysis & metadata extraction
  28. 28. $ python3 viz_demo.py ** Labels detected (and confidence score): Sitting (89.94%) Interior design (86.09%) Furniture (82.08%) Table (81.52%) Room (80.85%) White-collar worker (79.04%) Office (76.19%) Conversation (68.18%) Photography (62.42%) Window (60.96%) ** Facial features detected (and likelihood): Anger: very unlikely Blurred: very unlikely Headwear: very unlikely Joy: very likely Sorrow: very unlikely Surprise: very unlikely Under: very unlikely Vision: image analysis & metadata extraction from google.cloud import vision image_uri = 'gs://cloud-vision-codelab/otter_crossing.jpg' client = vision.ImageAnnotatorClient() image = vision.types.Image() image.source.image_uri = image_uri response = client.text_detection(image=image) for text in response.text_annotations: print('=' * 30) print(f'"{text.description}"') vertices = [f'({v.x},{v.y})' for v in text.bounding_poly.vertices] print(f'bounds: {",".join(vertices)}') Vision: OCR, text detection/extraction
  29. 29. $ python3 text-detect.py ============================== "CAUTION Otters crossing for next 6 miles " bounds: (61,243),(251,243),(251,340),(61,340) ============================== "CAUTION" bounds: (75,245),(235,243),(235,269),(75,271) ============================== "Otters" bounds: (65,296),(140,297),(140,315),(65,314) ============================== "crossing" bounds: (151,294),(247,295),(247,317),(151,316) : Vision: OCR, text detection/extraction g.co/codelabs/vision-python Cloud Vision exercise g.co/codelabs/vision- python (others at gcplab.me)
  30. 30. 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 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) sentiment = NL.analyze_sentiment(document).document_sentiment print('TEXT:', TEXT) print('nSENTIMENT: score (%.2f), magnitude (%.2f)' % ( sentiment.score, sentiment.magnitude)) categories = NL.classify_text(document).categories print('nCATEGORIES:') for cat in categories: print('* %s (%.2f)' % (cat.name[1:], cat.confidence))
  31. 31. 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.30), magnitude (0.60) CATEGORIES: * Internet & Telecom (0.76) * Computers & Electronics (0.64) * News (0.56) 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
  32. 32. Text-to-Speech: synthesizing audio text # request body (with text body using 16-bit linear PCM audio encoding) body = { 'input': {'text': text}, 'voice': { 'languageCode': 'en-US', 'ssmlGender': 'FEMALE', }, 'audioConfig': {'audioEncoding': 'LINEAR16'}, } # call Text-to-Speech API to synthesize text (write to text.wav file) T2S = discovery.build('texttospeech', 'v1', developerKey=API_KEY) audio = T2S.text().synthesize(body=body).execute().get('audioContent') with open('text.wav', 'wb') as f: f.write(base64.b64decode(audio)) Speech-to-Text: transcribing audio text # request body (16-bit linear PCM audio content, i.e., from text.wav) body = { 'audio': {'content': audio}, 'config': { 'languageCode': 'en-US', 'encoding': 'LINEAR16', }, } # call Speech-to-Text API to recognize text S2T = discovery.build('speech', 'v1', developerKey=API_KEY) rsp = S2T.speech().recognize( body=body).execute().get('results')[0]['alternatives'][0] print('** %.2f%% confident of this transcript:n%r' % ( rsp['confidence']*100., rsp['transcript']))
  33. 33. Speech-to-Text: transcribing audio text $ python s2t_demo.py ** 92.03% confident of this transcript: 'Google headquarters 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' 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
  34. 34. Video intelligence: make videos searchable # request body (single payload, base64 binary video) body = { "inputContent": video, "features": ['LABEL_DETECTION', 'SPEECH_TRANSCRIPTION'], "videoContext": {"speechTranscriptionConfig": {"languageCode": 'en-US'}}, } # perform video shot analysis followed by speech analysis VINTEL = discovery.build('videointelligence', 'v1', developerKey=API_KEY) resource = VINTEL.videos().annotate(body=body).execute().get('name') while True: results = VINTEL.operations().get(name=resource).execute() if results.get('done'): break time.sleep(random.randrange(8)) # expo-backoff probably better Video intelligence: make videos searchable # display shot labels followed by speech transcription for labels in results['response']['annotationResults']: if 'shotLabelAnnotations' in labels: print('n** Video shot analysis labeling') for shot in labels['shotLabelAnnotations']: seg = shot['segments'][0] print(' - %s (%.2f%%)' % ( shot['entity']['description'], seg['confidence']*100.)) if 'speechTranscriptions' in labels: print('** Speech transcription') speech = labels['speechTranscriptions'][0]['alternatives'][0] print(' - %r (%.2f%%)' % ( speech['transcript'], speech['confidence']*100.))
  35. 35. Video intelligence: make videos searchable $ python3 vid_demo.py you-need-a-hug.mp4 ** Video shot analysis labeling - vacation (30.62%) - fun (61.53%) - interaction (38.93%) - summer (57.10%) ** Speech transcription - 'you need a hug come here' (79.27%) 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
  36. 36. ● What is it, and how does it work? ○ Google Cloud ML APIs use pre-trained models ○ Perhaps those models less suitable for your data ○ Further customize/train our models for 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. Create/train model e. Evaluate/validate model f. Make predictions Cloud AutoML 05 Other APIs to consider What else may be useful?
  37. 37. Storing Data: Cloud SQL SQL 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 SQLServer (2019) cloud.google.com/sql Storing Data: Cloud Datastore Cloud Datastore: a fully- managed, highly-scalable NoSQL database for your web and mobile applications cloud.google.com/datastore
  38. 38. Storing Data: Firebase Firebase data is stored as JSON & synchronized in real-time to every connected client; other tools + FB == v2 mobile development platform firebase.google.com 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 cloud.google.com/firestore
  39. 39. ● Ordinary database - explicitiy query database for new updates (but when?) ● Realtime database - automatically receive deltas when database updated (setup client listener object) ● Highly scalable database ● Multi-regional data replication ● Strong consistency (vs. eventual consistency): read your writes! Cloud Firestore key features Cloud Firestore data model collections subcollections
  40. 40. Cloud Firestore straightforward querying github.com/GoogleCloudPlatform/python-docs-samples/blob/master/firestore/cloud-client/snippets.py Firestore: create & query for objects from datetime import datetime from google.cloud import firestore def store_time(timestamp): visits = FRSTOR.collection('visit') visits.add({'timestamp': timestamp}) def fetch_times(limit): visits = FRSTOR.collection('visit') return visits.order_by(u'timestamp', direction=firestore.Query.DESCENDING).limit(limit).stream() FRSTOR = firestore.Client() # create Cloud Firestore client print('** Adding another visit') store_time(datetime.now()) # store a "visit" object print('** Last 10 visits') times = fetch_times(10) # fetch 10 most recent "visits" for obj in times: print('-', obj.to_dict()['timestamp'])
  41. 41. Storing and Analyzing Data: BigQuery Google BigQuery is a fast, highly scalable, fully-managed data warehouse in the cloud for analytics with built-in machine learning (BQML); issue SQL queries across multi-terabytes of data cloud.google.com/bigquery BigQuery: querying Shakespeare words from google.cloud import bigquery 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 = bigquery.Client().query(QUERY).result() print('n*** Results for %r:n' % TITLE) print('t'.join(col.name.upper() for col in rsp.schema)) # HEADERS print('n'.join('t'.join(str(x) for x in row.values()) for row in rsp)) # DATA
  42. 42. 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 G Suite: Google Drive Drive API allows developers to read, write, control permissions/sharing, import/export files, and more! developers.google.com/drive
  43. 43. List (first 100) files/folders in Google Drive from __future__ import print_function from googleapiclient import discovery from httplib2 import Http from oauth2client import file, client, tools SCOPES = 'https://www.googleapis.com/auth/drive.metadata.readonly' store = file.Storage('storage.json') creds = store.get() if not creds or creds.invalid: flow = client.flow_from_clientsecrets('client_secret.json', SCOPES) creds = tools.run_flow(flow, store) DRIVE = discovery.build('drive', 'v3', http=creds.authorize(Http())) files = DRIVE.files().list().execute().get('files', []) for f in files: print(f['name'], f['mimeType']) Listing your files goo.gl/ZIgf8k Download from Drive, upload to GCS # Assume 1) FNAME == Drive filename (and it exists), 2) BUCKET == # GCS bucket name, and 3) DRIVE and GCS are API service endpoints # Find 1st matching file on Google Drive, download binary & info target = DRIVE.files().list(q="name='%s'" % FNAME, fields='files(id,mimeType,modifiedTime)').execute().get('files')[0] data = DRIVE.files().get_media(fileId=target['id']).execute() print('Downloaded %r (%s, %s, size: %d)' % (FNAME, target['mimeType'], target['modifiedTime'], len(data))) # Setup metadata and upload blob/object to Google Cloud Storage body = {'name': FNAME, 'uploadType': 'multipart', 'contentType': target['mimeType']} data = http.MediaIoBaseUpload(io.BytesIO(data), mimetype=target['mimeType']) rsp = GCS.objects().insert(bucket=BUCKET, body=body, media_body=data, fields='bucket,name').execute() print('Uploaded %r to GCS bucket %r' % (rsp['name'], rsp['bucket']))
  44. 44. Automate photo albums OR G Suite: 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
  45. 45. 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
  46. 46. Visualize big data results function createColumnChart(spreadsheet) { var sheet = spreadsheet.getSheets()[0]; var START_CELL = 'A2'; // skip header row var END_CELL = 'B11'; var START_ROW = 5; // place chart in... var START_COL = 5; // row 5, col 5 (E) var OFFSET = 0; var chart = sheet.newChart() .setChartType(Charts.ChartType.COLUMN) .addRange(sheet.getRange(START_CELL + ':' + END_CELL)) .setPosition(START_ROW, START_COL, OFFSET, OFFSET) .build(); sheet.insertChart(chart); return chart; } Other Google APIs & platforms ● G Suite (you can code Gmail, Google Drive, Calendar, Docs, Sheets, Slides!) ○ developers.google.com/gsuite ● Firebase (mobile development platform + RT DB) ○ firebase.google.com ● Google Data Studio (data visualization, dashboards, etc.) ○ datastudio.google.com/overview ● 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
  47. 47. 06 Wrap-up Summary & resources for hackers ● Key GCP product code samples for students: goo.gle/hackathon-toolkit ● Google Cloud codelabs (free, self-paced, hands-on tutorials): gcplab.me ● Other Google codelabs: g.co/codelabs ● GCP documentation - cloud.google.com/{docs,appengine,functions,vision,automl, language,speech,text-to-speech,translate,video-intelligence,firestore,bigquery} ● Like GCP? Wanna use it in class or your research lab? Send your profs to cloud.google.com/edu to apply for teaching or research credits! ● Know AWS? Compare w/GCP at cloud.google.com/docs/compare/aws ● Other references ○ Firebase docs - firebase.google.com ○ G Suite docs - developers.google.com/{gsuite,drive,docs,sheets,slides} ○ Videos - youtube.com/GoogleCloudPlatform (GCP) & goo.gl/JpBQ40 (G Suite) ○ Free trial (ignore) and Always Free (tier) - cloud.google.com/free Resources (students)
  48. 48. Best use of Google Cloud challenge Use any Google Cloud affiliated product to qualify; GCP, G Suite, Firebase, Maps, etc. Eligible products @ cloud.google.com/products Every member of the winning team gets: ● Google Home Mini ● Patagonia Backpack ● Cloud Pillow ● Acrylic Trophy ● Water Bottle Best use of Google Cloud challenge Use any Google Cloud affiliated product to qualify; GCP, G Suite, Firebase, Maps, etc. Eligible products @ cloud.google.com/products Every member of the runner-up team receives: ● Google Home Mini
  49. 49. $50 in GCP credits Check for an email from Major League Hacking (MLH) to activate your coupon for free $50USD worth of GCP credits! (NOTE: must exceed Always Free tier to incur billing, so you may not use much) WARNING: avoid the GCP $300 free trial!! 💳 😓 Thank you! Qs? Hit us up on Slack or Discord Wesley Chun @wescpy Progress bars: goo.gl/69EJVw

×