Skip to content

Commit

Permalink
Merge pull request #130 from GoogleCloudPlatform/dev (2.1 release)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwsherman authored Oct 4, 2024
2 parents b29d6da + 8b35216 commit 66aa6c2
Show file tree
Hide file tree
Showing 89 changed files with 1,097 additions and 2,827 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,8 @@ override.tf.json
# Ignore CLI configuration files
.terraformrc
terraform.rc
tf/aux_data/*
infra/output_config/*

# Post deployment files
frontend/.firebase
frontend/.angular
388 changes: 90 additions & 298 deletions README.md

Large diffs are not rendered by default.

Binary file modified app/images/talk_to_data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion backend_apis/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ FROM python:3.11-slim

# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True
ENV GOOGLE_CLOUD_PROJECT <your_project_id>

WORKDIR /
COPY ./requirements.txt /requirements.txt
Expand Down
47 changes: 23 additions & 24 deletions backend_apis/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# GenAI for Marketing - Backend APIs

We developed a comprehensive set of APIs, utilizing Python and FastAI, which encapsulate all features available in the GenAI for Marketing repository. This implementation paves the way for streamlined data interactions and enhanced functionality, enabling you to deploy the solution in your environment.
This information is developers working directly with the backend APIs. See the root [README](../README.md) for information on deploying the solution (including the backend).

We developed a comprehensive set of APIs, utilizing Python and FastAPI, which encapsulate all features available in the GenAI for Marketing repository. This implementation paves the way for streamlined data interactions and enhanced functionality, enabling you to deploy the solution in your environment.

You are empowered to extend these APIs, intertwining them with your specific policies pertaining to security, access, and authentication to bolster a secure, seamless, and individualized interaction with the data and services available. Our offering merges practicality with customization, ensuring that your specific requirements are catered to with precision and reliability.

## List of APIs developed in this repository
## List of APIs Developed in This Repository

**Campaign Creation and Generating the brief assets (POST)** (path="/campaigns")
- Create Campaing and Generate text with PaLM API (text-bison) latest or 001.
**Campaign Creation and Generating the Brief Assets (POST)** (path="/campaigns")
- Create Campaign and Generate text with Gemini.

**List all Campaigns created by user (GET)** (path="/campaigns")
**List All Campaigns Created by User (GET)** (path="/campaigns")
- List of Campaigns and there details.

**Update Campaign (PUT)** (path="/campaigns/{campaign_id}")
Expand All @@ -18,40 +20,37 @@ You are empowered to extend these APIs, intertwining them with your specific pol
**Delete Campaign (DELETE)** (path="/campaigns/{campaign_id}")
- List of Campaigns and there details.

**Text generation with Vertex AI PaLM API (text-bison)** (path="/generate-text")
- Generate text with PaLM API (text-bison) latest or 001.

**Image generation with Vertex Imagen API** (path="/generate-image")
**Image Generation with Vertex Imagen API** (path="/generate-image")
- Generate images with the Vertex Imagen API.

**Image editing with Vertex Imagen API** (path="/edit-image")
**Image Editing with Vertex Imagen API** (path="/edit-image")
- Edit images with a prompt and a mask.

**Get top search terms from Google Trends** (path="/get-top-search-terms")
- Retrieve top search terms from Google trends
**Get Top Search Terms from Google Trends** (path="/get-top-search-terms")
- Retrieve top search terms from Google trends.

**Summarize news articles related to keywords** (path="/post-summarize-news")
**Summarize News Articles Related to Keywords** (path="/post-summarize-news")
- Retrieve N news articles with keyword(s) using the GDELT API and summarize them.

**From natural language to SQL** (path="/post-audiences")
**From Natural Language to SQL** (path="/post-audiences")
- Transform a question using natural language to SQL and query BigQuery.

**Query sample data** (path="/get-dataset-sample")
**Query Sample Data** (path="/get-dataset-sample")
- Query BigQuery and return 3 lines of a given table

**Query Vertex AI Search** (path="/post-consumer-insights")
- Query Vertex AI Search with using input and return to 10 results.

**Upload file to Google Drive** (path="/post-upload-file-drive")
**Upload File to Google Drive** (path="/post-upload-file-drive")
- Given an uploaded file using a form, upload it to Google Drive.

**Create Brief document and upload to Drive** (path="/creative-brief-create-upload")
**Create Brief Document and Upload to Drive** (path="/creative-brief-create-upload")
- Create a folder in Drive with correct permissions, copy the Creative Brief to Drive and update its contents with the generated text.

**Create Slides and populate with Charts** (path="/creative-slides-upload")
**Create Slides and Populate with Charts** (path="/creative-slides-upload")
- Create a Google Slides from a template and populate with information from Google Sheets.

**Translate Text using Google Translation API** (path="/translate")
**Translate Text Using Google Translation API** (path="/translate")
- Translate Text using Google Translation API.

**Content-Generation API for Email/Webpost/SocialMedia/AssetGroup**(path="/generate-content")
Expand All @@ -65,11 +64,11 @@ Connect your app to your Firebase project, do so from the [Firebase console](htt
- Add a Web App to project by going to Project Setting, it will generate the credentials.
- Store credentialds in [Secret Manager](https://cloud.google.com/secret-manager/docs/create-secret-quickstart) and add secret_name in config.toml

## Workspace integration
## Workspace Integration

Follow the steps below to setup the Workspace integration with this demonstration.

#### Create a service account
### Create a Service Account
- Create a Service Account (SA) in the same project you are deploying the demo and download the JSON API Key. This SA doesn't need any roles / permissions.
- Follow this [documentation](https://cloud.google.com/iam/docs/service-accounts-create) to create the service account. Take note of the service account address; it will look like this: `[email protected]`.
- Follow this [documentation](https://cloud.google.com/iam/docs/keys-create-delete#creating) to download the key JSON file with the service account credentials.
Expand All @@ -78,7 +77,7 @@ Follow the steps below to setup the Workspace integration with this demonstratio
- When you deploy the app to AppEngine, the JSON file will be copied inside the docker image.
- **IMPORTANT**: For security reasons, DON'T push this credentials to a public Github repository.

#### Google Drive
### Google Drive
- Navigate to [Google Drive](https://drive.google.com/) and create a folder.
- This folder will be used to host the templates and assets created in the demo.
- Share this folder with the service account address you created in the previous step. Give "Editor" rights to the service account. The share will look like this:
Expand All @@ -88,7 +87,7 @@ Follow the steps below to setup the Workspace integration with this demonstratio
- Open the configuration file [app_config.toml - line 558](/app/app_config.toml) and change to your folder ID.
- **IMPORTANT**: Also share this folder with people who will be using the code.

## How to deploy this APIs to Google Cloud Run
## How to Deploy the APIs to Google Cloud Run

Using the same Vertex AI managed notebook you created in this [README](../README.md) file, follow the steps below:
- Open the JupyterLab environment
Expand Down Expand Up @@ -120,4 +119,4 @@ You will find detailed intructions in this [README](../README.md) file, speciall
> gcloud run deploy genai-marketing-apis --image gcr.io/**"YOUR PROJECT ID"**/genai-marketing-apis --allow-unauthenticated --region us-central1
Replace **"YOUR PROJECT ID"** with the id of your project.
This is just one example on how to deploy this container to Cloud Run on an endpoint that accepts unauthenticated requests. Change to your requirements.
This is just one example on how to deploy this container to Cloud Run on an endpoint that accepts unauthenticated requests. Change to your requirements.
26 changes: 13 additions & 13 deletions backend_apis/app/bulk_email_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from PIL import Image

from google.cloud import translate_v2 as translate
from vertexai.preview.language_models import TextGenerationModel
from vertexai.preview.generative_models import GenerativeModel, GenerationConfig
from vertexai.preview.vision_models import ImageGenerationModel


Expand All @@ -43,8 +43,7 @@
vertexai.init(
project=project_id,
location=location)
llm = TextGenerationModel.from_pretrained(
config["models"]["text_model_name"])
text_llm = GenerativeModel(config["models"]["text_model_name"])
imagen = ImageGenerationModel.from_pretrained(config["models"]["image_model_name"])
translate_client = translate.Client()

Expand Down Expand Up @@ -75,12 +74,12 @@ def generate_information(data : list) -> pd.DataFrame:
return df

async def email_generate(row: pd.Series, theme: str, image_context: str) -> pd.Series:
prompt_row = row['first_name']
first_name = row['first_name']

email_prompt = EMAIL_TEXT_PROMPT.format(prompt_row,
email_prompt = EMAIL_TEXT_PROMPT.format(first_name,
theme)
loop = asyncio.get_running_loop()
progress_text = f"Generating email text for {prompt_row}"
progress_text = f"Generating email text for {first_name}"
print(progress_text)
generated_text = ""
generated_images = []
Expand All @@ -89,13 +88,14 @@ async def email_generate(row: pd.Series, theme: str, image_context: str) -> pd.S
generated_response = await loop.run_in_executor(
None,
functools.partial(
llm.predict,
prompt=email_prompt,
temperature=0.2,
max_output_tokens=1024,
top_k = 40,
top_p = 0.8
))
text_llm.generate_content,
contents=email_prompt,
generation_config=GenerationConfig(temperature=0.2,
top_p=0.8,
top_k=40,
max_output_tokens=1024),
)
)
except Exception as e:
generated_response = None
print("Error")
Expand Down
Loading

0 comments on commit 66aa6c2

Please sign in to comment.