DEVLOPER-IT-CYBER-CENTRE
/
Perform-Foundational-Data-ML-and-AI-Tasks-in-Google-Cloud-Challenge-Lab
Public
forked from MLSA-MUET-SZAB-Club-Khairpur-Mir-s/Perform-Foundational-Data-ML-and-AI-Tasks-in-Google-Cloud-Challenge-Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChallenge Lab Solution
105 lines (60 loc) · 2.9 KB
/
Challenge Lab Solution
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Task - 1 : Run a simple Dataflow job
bq mk lab
gsutil cp gs://cloud-training/gsp323/lab.csv .
cat lab.csv
gsutil cp gs://cloud-training/gsp323/lab.schema .
cat lab.schema
##############################################################################################################################
Task - 2 : Run a simple Dataproc job
This has to be done mannually.
###############################################################################################################################
Task - 3 : Run a simple Dataprep job
This has to be done mannually.
###############################################################################################################################
Task - 4 : AI
gcloud iam service-accounts create my-natlang-sa \
--display-name "my natural language service account"
gcloud iam service-accounts keys create ~/key.json \
--iam-account my-natlang-sa@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com
export GOOGLE_APPLICATION_CREDENTIALS="/home/$USER/key.json"
gcloud auth activate-service-account my-natlang-sa@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com --key-file=$GOOGLE_APPLICATION_CREDENTIALS
gcloud ml language analyze-entities --content="Old Norse texts portray Odin as one-eyed and long-bearded, frequently wielding a spear named Gungnir and wearing a cloak and a broad hat." > result.json
gcloud auth login
(Copy the token from the link provided)
gsutil cp result.json gs://YOUR_PROJECT-marking/task4-cnl.result
Create an API key and export as API_KEY variable.
export API_KEY={Replace with API KEY}
nano request.json
Add this content:
{
"config": {
"encoding":"FLAC",
"languageCode": "en-US"
},
"audio": {
"uri":"gs://cloud-training/gsp323/task4.flac"
}
}
curl -s -X POST -H "Content-Type: application/json" --data-binary @request.json \
"https://speech.googleapis.com/v1/speech:recognize?key=${API_KEY}" > result.json
gsutil cp result.json gs://YOUR_PROJECT-marking/task4-gcs.result
gcloud iam service-accounts create quickstart
gcloud iam service-accounts keys create key.json --iam-account quickstart@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com
gcloud auth activate-service-account --key-file key.json
export ACCESS_TOKEN=$(gcloud auth print-access-token)
nano request.json
Add this content:
{
"inputUri":"gs://spls/gsp154/video/chicago.mp4",
"features": [
"TEXT_DETECTION"
]
}
Now add the following commands on the command line:
curl -s -H 'Content-Type: application/json' \
-H "Authorization: Bearer $ACCESS_TOKEN" \
'https://videointelligence.googleapis.com/v1/videos:annotate' \
-d @request.json
curl -s -H 'Content-Type: application/json' -H "Authorization: Bearer $ACCESS_TOKEN" 'https://videointelligence.googleapis.com/v1/operations/OPERATION_FROM_PREVIOUS_REQUEST' > result1.json
gsutil cp result1.json gs://YOUR_PROJECT-marking/task4-gvi.result
Congratulations, you're all done with the lab 😄