diff --git a/.github/workflows/jupyter.yml b/.github/workflows/jupyter.yml new file mode 100644 index 00000000..8b538456 --- /dev/null +++ b/.github/workflows/jupyter.yml @@ -0,0 +1,50 @@ +name: jupyter + +on: + push: + branches: [ master, shuklak13-patch-1 ] + pull_request: + branches: [ master, shuklak13-patch-1 ] + schedule: + - cron: '0 11 * * *' + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.7] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + - name: Install pip + run: | + python -m pip install --upgrade pip + + - name: Install TensorFlow ecosystem + run: | + pip install tensorflow + pip install tensorflow_data_validation + pip install tensorflow_hub + pip install tensorflow-model-analysis + + - name: Install test dependencies + run: | + pip install nbformat + pip install nbconvert + + - name: Set up Jupyter + run: | + pip install jupyter + jupyter nbextension enable --py widgetsnbextension --sys-prefix + jupyter nbextension install --py --symlink tensorflow_model_analysis --sys-prefix + jupyter nbextension enable --py tensorflow_model_analysis --sys-prefix + + - name: Test Jupyter Notebooks + run: python test_runner.py diff --git a/README.md b/README.md index e3987704..398b62bd 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Fairness Indicators BETA +![](https://github.com/tensorflow/fairness-indicators/workflows/jupyter/badge.svg) + ![Fairness_Indicators](https://raw.githubusercontent.com/tensorflow/fairness-indicators/master/fairness_indicators/images/fairnessIndicators.png) Fairness Indicators is designed to support teams in evaluating, improving, and comparing models for fairness concerns in partnership with the broader Tensorflow toolkit. diff --git a/notebook_runner.py b/notebook_runner.py new file mode 100644 index 00000000..730aeeae --- /dev/null +++ b/notebook_runner.py @@ -0,0 +1,34 @@ +import nbformat +import os + +from nbconvert.preprocessors import ExecutePreprocessor + + +def run_notebook(notebook_path): + nb_name, _ = os.path.splitext(os.path.basename(notebook_path)) + dirname = os.path.dirname(notebook_path) + + with open(notebook_path) as f: + nb = nbformat.read(f, as_version=4) + + proc = ExecutePreprocessor(timeout=None, kernel_name='python3') + proc.allow_errors = True + + proc.preprocess(nb, {'metadata': {'path': '/'}}) + output_path = os.path.join(dirname, '{}_all_output.ipynb'.format(nb_name)) + + with open(output_path, mode='wt') as f: + nbformat.write(nb, f) + + errors = [] + for cell in nb.cells: + if 'outputs' in cell: + for output in cell['outputs']: + if output.output_type == 'error': + errors.append(output) + + print('ERRORS') + print(type(errors)) + print(errors) + + return errors diff --git a/test_runner.py b/test_runner.py new file mode 100644 index 00000000..dad5c691 --- /dev/null +++ b/test_runner.py @@ -0,0 +1,45 @@ +import unittest + +import notebook_runner + + +class TestNotebook(unittest.TestCase): + + def test_example(self): + errors = notebook_runner.run_notebook( + 'fairness_indicators/examples/Fairness_Indicators_Example_Colab.ipynb') + self.assertEmpty(errors) + + def test_facessd(self): + errors = notebook_runner.run_notebook( + 'fairness_indicators/examples/Facessd_Fairness_Indicators_Example_Colab.ipynb') + self.assertEmpty(errors) + + def test_lineage(self): + errors = notebook_runner.run_notebook( + 'fairness_indicators/examples/Fairness_Indicators_Lineage_Case_Study.ipynb') + self.assertEmpty(errors) + + def test_tb(self): + errors = notebook_runner.run_notebook( + 'fairness_indicators/examples/Fairness_Indicators_TensorBoard_Plugin_Example_Colab.ipynb') + self.assertEmpty(errors) + + def test_tfco_celeba(self): + errors = notebook_runner.run_notebook( + 'fairness_indicators/examples/Fairness_Indicators_TFCO_CelebA_Case_Study.ipynb') + self.assertEmpty(errors) + + def test_tfco_wiki(self): + errors = notebook_runner.run_notebook( + 'fairness_indicators/examples/Fairness_Indicators_TFCO_Wiki_Case_Study.ipynb') + self.assertEmpty(errors) + + def test_tfhub(self): + errors = notebook_runner.run_notebook( + 'fairness_indicators/examples/Fairness_Indicators_on_TF_Hub_Text_Embeddings.ipynb') + self.assertEmpty(errors) + + +if __name__ == '__main__': + unittest.main()