Cloud Natural Language API: Qwik Start
Solution for Cloud Natural Language API: Qwik Start. 1 lab: GSP097. Fast copy-paste commands for Google Cloud.
GSP097 — Cloud Natural Language API: Qwik Start
Estimated time: 10 minutes
# 🧠 Cloud Natural Language API: Qwik Start > ⚠️ **Disclaimer:** This is an independent, community-made walkthrough created to help you understand why each step works. Attempt the lab yourself first. This guide is intended for educational purposes and hands-on learning with Google Cloud services. It is not intended to replace the official lab instructions or your own understanding of the concepts. This walkthrough is not affiliated with or endorsed by Google Cloud or Google Cloud Skills Boost.
# ==============================================================================
# Color Variables & Branding
# ==============================================================================
GREEN='\e[1;32m'
CYAN='\e[1;36m'
YELLOW='\e[1;33m'
MAGENTA='\e[1;35m'
RED='\e[1;31m'
RESET='\e[0m'
BOLD='\e[1m'
clear
echo -e "${CYAN}${BOLD}"
cat << "EOF"
____ _ _ _ __ ___
/ __ \ | | (_) | / _| / _ \
| | | |_ __| |__ _| |_ ___ | |_ | | | |_ __ ___
| | | | '__| '_ \| | __| / _ \ | _| | | | | '_ \/ __|
| |__| | | | |_) | | |_ | (_) || | | |_| | |_) \__ \
\____/|_| |_.__/|_|\__| \___/ |_| \___/| .__/|___/
| |
|_|
EOF
echo -e "${RESET}"
echo -e "${MAGENTA}${BOLD}>>> ORBIT OF OPS: GSP097 PART 1 INITIALIZED <<<${RESET}\n"
echo -e "${YELLOW}${BOLD}[Orbit of Ops] Auto-fetching Project...${RESET}"
export GOOGLE_CLOUD_PROJECT=$(gcloud config get-value core/project 2>/dev/null)
if [[ -z "$GOOGLE_CLOUD_PROJECT" ]]; then
export GOOGLE_CLOUD_PROJECT=$DEVSHELL_PROJECT_ID
fi
echo -e "✅ Project ID: ${GREEN}$GOOGLE_CLOUD_PROJECT${RESET}\n"
echo -e "${CYAN}${BOLD}[Orbit of Ops] Task 1: Creating Service Account & JSON Key...${RESET}"
gcloud iam service-accounts create my-natlang-sa \
--display-name "my natural language service account" || true
echo -e "${YELLOW}${BOLD}[Orbit of Ops] Generating Credentials...${RESET}"
gcloud iam service-accounts keys create ~/key.json \
--iam-account my-natlang-sa@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com || true
export GOOGLE_APPLICATION_CREDENTIALS="$HOME/key.json"
echo -e "✅ Credentials exported to: ${GREEN}$GOOGLE_APPLICATION_CREDENTIALS${RESET}\n"
echo -e "${GREEN}${BOLD}✅ Part 1 Complete. Check Task 1 progress in the lab window!${RESET}"# ==============================================================================
# Color Variables & Branding
# ==============================================================================
GREEN='\e[1;32m'
CYAN='\e[1;36m'
YELLOW='\e[1;33m'
MAGENTA='\e[1;35m'
RESET='\e[0m'
BOLD='\e[1m'
echo -e "\n${MAGENTA}${BOLD}>>> ORBIT OF OPS: GSP097 PART 2 (UPDATED FOR VM SYNC) <<<${RESET}\n"
# Ensure the credentials variable is still set in this session
export GOOGLE_APPLICATION_CREDENTIALS="$HOME/key.json"
echo -e "${CYAN}${BOLD}[Orbit of Ops] Generating result.json locally...${RESET}"
gcloud ml language analyze-entities \
--content="Michelangelo Caravaggio, Italian painter, is known for 'The Calling of Saint Matthew'." > result.json || true
echo -e "${YELLOW}${BOLD}[Orbit of Ops] Auto-detecting provisioned Compute Engine VM...${RESET}"
export INSTANCE_NAME=$(gcloud compute instances list --format="value(name)" | head -n 1)
export INSTANCE_ZONE=$(gcloud compute instances list --format="value(zone)" | head -n 1)
echo -e "✅ Found VM: ${GREEN}$INSTANCE_NAME${RESET} in Zone: ${GREEN}$INSTANCE_ZONE${RESET}"
echo -e "${CYAN}${BOLD}[Orbit of Ops] Securely copying result.json to the VM to trigger grading...${RESET}"
# Using --quiet to prevent SSH key confirmation prompts
gcloud compute scp result.json $INSTANCE_NAME:~/ --zone=$INSTANCE_ZONE --quiet || true
echo -e "\n${GREEN}${BOLD}🎉 Part 2 Complete! The file is now on the VM. Please click 'Check my progress' on Task 2 in the lab window!${RESET}"