Welcome to the final chapter! In the previous chapter, translations, we explored the massive directory that holds this course in over 40 different languages.
We learned that maintaining so many languages is hard work. If we change one sentence in the English version of 1-Introduction, do we really expect 40 human volunteers to rush in and update their files immediately?
That would be impossible. Humans sleep. Humans take vacations.
This brings us to the final file in our journey: .github/workflows/co-op-translator.yml.
Imagine you run a newspaper.
This file is a GitHub Action. It is a set of instructions that tells GitHub's servers to wake up and do work for us automatically.
The Use Case: A contributor updates a lesson. Instead of waiting for a human, they type a magic command in a comment, and this workflow runs a Python script to translate the changes instantly using Azure AI.
This file isn't Python code, and it isn't data. It is YAML (Yet Another Markup Language). It is a configuration file that defines a "Pipeline" or an "Assembly Line."
on)Just like a burglar alarm, the robot needs to know when to wake up.
/translate) in a discussion.jobs)Once the robot is awake, what should it do?
The GitHub server doesn't know Spanish. So, inside the job, it connects to Azure Cognitive Services. It sends the English text to the cloud, and the cloud sends back the translated text.
Unlike the Python scripts in 2-Regression, you don't run this file on your computer. It runs in the cloud (on GitHub's computers).
However, you trigger it through human interaction.
Let's say you just fixed a typo in the English README. You want to update the Hindi version.
/translate hi
.github/workflows/co-op-translator.yml file "hears" this comment.hi (Hindi).Output: Your Pull Request now contains two files: the English one you wrote, and the Hindi one the robot wrote!
How does a text comment turn into a new file? Let's visualize the "Event Loop."
issue_comment event.Let's look at the actual YAML code inside the file. We will simplify it to show the most important parts.
This section tells GitHub when to start.
name: Co-op Translator
# Trigger on comments in Pull Requests
on:
issue_comment:
types: [created]
Explanation:
on: issue_comment: This means "Run this file every time someone posts a comment."We don't want to run the robot for every comment (like "Good job!"). We only want to run it for the magic command.
jobs:
translate:
# Only run if the comment starts with '/translate'
if: startsWith(github.event.comment.body, '/translate')
runs-on: ubuntu-latest
Explanation:
if:: This acts like a filter. It checks the text body of the comment. If it sees /translate, it proceeds. If not, it goes back to sleep.runs-on: ubuntu-latest: This tells GitHub to rent a Linux computer for a few minutes to do the work.Now we give the Linux computer a checklist of things to do.
steps:
# 1. Download our project code
- uses: actions/checkout@v2
# 2. Install Python (just like we did in Chapter 3)
- uses: actions/setup-python@v2
with:
python-version: 3.x
# 3. Run the translation script
- name: Run Translator
run: |
pip install -r requirements.txt
python translation_script.py
env:
AZURE_KEY: ${{ secrets.AZURE_KEY }}
Explanation:
checkout: Get the current code from the repo.setup-python: Prepare the environment.run: This is the core. It installs tools and runs a Python script (just like python script.py).env: We pass the secret password (API Key) for Azure so the script can talk to the cloud securely.You might think this is "DevOps," not Machine Learning. But in the real world, ML is useless if it is isolated.
Congratulations! You have reached the end of ML-For-Beginners.
In this final chapter, we learned that we can automate the boring parts of coding using GitHub Actions. We built a "Co-op Translator" that helps us maintain our translations folder by connecting our repository to Azure AI.
Let's recap your journey:
You are no longer just a beginner. You are a practitioner. The world of data is now yours to explore.
End of Curriculum.
Generated by Code IQ