<jupyter_start><jupyter_text>Step 0: Authenticate & Fetch Code<jupyter_code>GCP_PROJECT_ID = "" #@param {type:"string"}
INSTANCE_NAME="" #@param {type:"string"}
!gcloud auth login
!gcloud config set project $GCP_PROJECT_ID
!rm -rf modem && git clone https://github.com/google/modem.git
import re
email=!gcloud config get-value account
SSH_DESTINATION = re.findall(r".*@",email[0])[0]+INSTANCE_NAME
SSH_DESTINATION = SSH_DESTINATION.replace('.','_')
print("SSH Destination: ", SSH_DESTINATION)
%%writefile enable_firewall.sh
exists_rule=$(gcloud compute firewall-rules list | grep "default-allow-ssh" | wc -l)
if [ $exists_rule -eq 0 ] 
then 
  gcloud compute firewall-rules create default-allow-ssh --allow tcp:22;
  echo "New firewall rule created."
else
  echo "The correct firewall rules exist." 
fi<jupyter_output><empty_output><jupyter_text>Step 1: Copy the service key file text into the cell below.Replace the existing content expect the %%writefile header (line 1).<jupyter_code>%%writefile modem/bqml/pipeline/svc_key.json
{
  "TODO": "Replace file." 
}<jupyter_output><empty_output><jupyter_text>Step 2: Fill out the parametersGA_ACCOUNT_ID, GA_PROPERTY_ID, GA_DATASET_ID, BQML_PREDICT_QUERY (required) **Note:** Please don't remove the string quotes.<jupyter_code>%%writefile modem/bqml/pipeline/params.py
# -------------------------MANDATORY SECTION------------------------

# GA Details 
GA_ACCOUNT_ID = ""
GA_PROPERTY_ID = ""
GA_DATASET_ID = "" 
GA_IMPORT_METHOD = "di" # "di" - Data Import or "mp" - Measurement Protocol 

# BQML Details -
# Ensure that the BQ result headers resemble the data import schema
# E.g. If data import schema looks like  - ga:clientId, ga:dimension1, etc.
# BQ result headers should like ga_clientId, ga_dimension1, etc.
BQML_PREDICT_QUERY = """
                     """

# Options for logging & error monitoring
# LOGGING: Create BQ Table for logs with schema as follows -
# time TIMESTAMP, status STRING, error ERROR
ENABLE_BQ_LOGGING = False
# ERROR MONITORING: Sign up for the free Sendgrid API.
ENABLE_SENDGRID_EMAIL_REPORTING = False

# --------------------------OPTIONAL SECTION-------------------------

# (OPTIONAL) Workflow Logging - BQ details, if enabled
GCP_PROJECT_ID = ""
BQ_DATASET_NAME = ""
BQ_TABLE_NAME = ""


# (OPTIONAL) Email Reporting - Sendgrid details, if enabled
SENDGRID_API_KEY = ""
TO_EMAIL = ""


# (OPTIONAL) Email Reporting - Additional Parameters
FROM_EMAIL = "<EMAIL>"
SUBJECT = "FAILED: Audience Upload to GA"
HTML_CONTENT = """
               <p>
               Hi WorkflowUser, <br>
               Your BQML Custom Audience Upload has failed- <br>
               Time: {0} UTC <br>
               Reason: {1}
               </p>
               """<jupyter_output><empty_output><jupyter_text>**Change the cron schedule** (line 1) to the desired frequency.<jupyter_code>%%writefile modem/bqml/pipeline/shell_scheduler.sh
cron_schedule="*/2 * * * *" 
echo "$cron_schedule cd ~/modem/bqml/pipeline && python main.py >> logs.csv" | crontab -
echo "Your workflow has been scheduled with the cron schedule of $cron_schedule. Enjoy!"<jupyter_output><empty_output><jupyter_text>Step 3: Deploy the codeRun the cell below.<jupyter_code>!sh enable_firewall.sh
!gcloud compute scp --recurse modem $SSH_DESTINATION:~/
!echo "Code deployed."<jupyter_output><empty_output><jupyter_text>Step 4: Test and schedule the codeWhen you run the cell below, an interactive shell opens up. Use the following commands - 1. Test the code. If successful, you should see a SUCCESS message along with a timestamp. Proceed to Step 2. If there are any errors, you can either work through the colab from Step 1, fixing the parameters, or log into the Compute Engine instance to fix the errors.```cd modem/bqml/pipelinesh shell_deploy.sh```2. Ensure Step 1 was successful. Run the command below.```sh shell_scheduler.sh```<jupyter_code>!gcloud compute ssh $SSH_DESTINATION<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1279452748923233, 'fraction_numerical': 0.005573853559665568, 'mean_word_length': 3.984848484848485, 'pattern_counts': {'":': 1, '<': 31, '<?xml version=': 0, '>': 33, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '636191', 'license': 'Apache-2.0', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1279, 'n_words': 384, 'path': 'bqml/utils/BQML_Deployment_Template_Compute_Engine.ipynb', 'repo_name': 'dgsabate/modem', 'size': '3960'}