A proof of concept showcasing the integration of the GCP Vision API into a Svelte single page web application.
Follow the Vision API getting started instructions to set up your GCP environment
Note: For this demo project you will be using your GCP user account for authentication, and we will not be using any of the Vision API client libraries.
To validate you have everything setup correctly, from your Terminal issue the following curl command which sends a request to the Vision API to annotate the following image:
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth print-access-token) \
-H "X-Goog-User-Project: $(gcloud config get project)" \
-H "Content-Type: application/json; charset=utf-8" \
https://vision.googleapis.com/v1/images:annotate \
-d \
'{
"requests": [
{
"image": {
"source": {
"imageUri": "gs://cloud-samples-data/vision/eiffel_tower.jpg"
}
},
"features": [
{
"type": "LABEL_DETECTION",
"maxResults": 3
},
{
"type": "OBJECT_LOCALIZATION",
"maxResults": 1
},
{
"type": "TEXT_DETECTION",
"maxResults": 1,
"model": "builtin/latest"
}
]
}
]
}'
git clone [email protected]:Ben-Chapman/Svelte-GCP-Vision-API.gitbrew install npmsudo apt install npmsudo pacman -S npmsudo dnf install npmecho -e "Node.js Version: $(node -v)\tnpm Version: $(npm -v)"cd Svelte-GCP-Vision-API/visionapp/npm installSvelte-GCP-Vision-API/visionapp
directory and issue the following command:npm run devRunning the dev script starts a program called Vite. Vite's job is to take your application's source files, pass them to other programs (including Svelte, in our case) and convert them into the code that will actually run when you open the application in a browser.
Speaking of which, open a browser and navigate to http://localhost:5173. This is your application running on a local web server (hence 'localhost') on port 5173.
Try changing src/App.svelte and saving it. The application will update with your changes.
That's it! You now have a copy of the Svelte GCP Vision app running. Try dragging and dropping an image onto the web page, and if everything is setup correctly, you'll receive the GCP Vision API results right in your browser.