This is an OSS demo of how to get GenAI to work with Google Cloud.
Google Cloud tech stack:
- Cloud Run (to run the container - currently here)
- Cloud Build (to automate a new build at every commit! We're serious and lazy here!)
- Vertex AI GenAI used for:
- Generating long text (story ideation)
- Summarization (auto-title! So sweet)
- Image generation (a different pic per paragraph)
- Google Translate API to generate a story in A number of languages: ๐ฎ๐น๐ง๐ท๐ช๐ธ๐ซ๐ท๐จ๐ณ๐ท๐บ .. This is the only consumer API used, with an API key
- Text to Speech API to generate an Audio (italian sample)
- Google Cloud Storage for ActiveStorage (images and sounds are stored in a GCS bucket)
- Secrets Manager to hold my app most precious untold secrets:
RAILS_MASTER_KEY
,TRANSLATE_API_KEY
, andservice_account_key.json
. Actually if You find them in the code, please tell me, as I'm not infallible. I promise you Italian gratitude.
Boring details:
- Ruby version:
3.2.0
- Rails version:
7.0.6
- Frontend:
Bootstrap 5
. - System dependencies: see
make install
- Database:
PostgreS
ActiveStorage
: backend on Google Cloud StorageDelayedJob
for job queue (usingPGSQL
DB , not Redis like most humans - I've just been lazy).direnv
to manage ๐ฑ.envrc
and friends. You can create a.envrc.$USER
file and it will be auto-slurped by my awesome scripts.
This is a simplified architecture of the Google Cloud components used:
This is how it works (thanks Mermaid and stackedit ):
flowchart TD;
A2["Shakespeare Story ๐งฉ Prompt"] -- GenAI: Text gen --> B["๐ Story::Body"];
B -- GenAI: Text summary --> C[Story::Title];
C -- split --> P1["๐ Paragraph1"];
C -- split --> P2["๐ Paragraph2"];
C -- split --> Pdot[..];
C -- split --> P3["๐ ParagraphN"];
P1 -- "concat with Kid\n๐ถ๐พ visual Description" --> PD1["Par1 + Desc"];
P2 -- concat.. --> PD2[Par2 + Desc];
P3 -- concat.. --> PD3[PaN + Desc];
PD1 -- GenAI Vision --> IMG1["๐๏ธ Par1 Image"];
PD2 -- GenAI Vision --> IMG2["๐๏ธ Par2 Image"];
PD3 -- GenAI Vision --> IMG3["๐๏ธ Par3 Image"];
IMG1 --> END["Story with \n N ๐๐paragraphs \n and N ๐๏ธ๐๏ธimages"]
IMG2 --> END
IMG3 --> END
P1 --> END;
- make sure you create yur own
.envrc.yourname
and assign the ENV vars you want. - Create A svcAcct for GCS and download it under
private/sa.json
. Do NOT check it in :) - Create your own
RAILS_MASTER_KEY
and keep it aside. - Environments:
make dev
: runs indevelopment
, with sqlite3 db and local storagemake dev-on-gcp
: run in pseudo-dev, but with pgsql DB (and GCS storage)make prod
: run in prod, with pgsql DB (and GCS storage)
make reauth-local
ensures the GCP has been enabled.make test-gcp
if you want to make sure that AI / GCP are working.make dev
# or whatever ENV you want to run. Check Makefile for some options- Also make sure that the secret key points to a non-expired SvcAcct key ;)
- Cloud Build (on ricc project
ror-goldie
). - manually created build with:
_RAILS_MASTER_KEY
set tocat config/master.key
_DANGEROUS_SA_JSON_VALUE
set tocat private/sa.json
Ruby (and Rails):
This app