Skip to content

Commit

Permalink
Merge pull request #2 from mijanr/main
Browse files Browse the repository at this point in the history
push chnages in main to test
  • Loading branch information
mijanr authored Mar 16, 2024
2 parents bbd8955 + d7d2f3c commit 744c113
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/update_readme.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Update README

on:
push:
branches:
- main

jobs:
update-readme:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install mlflow tabulate
- name: Run script
run: python results/gen_result.py

- name: Commit results if it changed
run: |
git diff --exit-code --quiet results/best_runs.md || (git add results/best_runs.md && git commit -m "Update best runs")
- name: Replace results in README
run: |
results=$(cat results/best_runs.md) # Read the results
# Replace the results in the README
awk -v r="$results" '/<!--START-->/ {print; print r; f=1} /<!--END-->/ {f=0} !f' README.md > temp && mv temp README.md
- name: Commit and push if it changed
run: |
git diff
git config --global user.email "[email protected]"
git config --global user.name "Md Mijanur Rahman"
git commit -am "Update README with test results" || exit 0
git push
27 changes: 27 additions & 0 deletions results/gen_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
We will generate a table here with the results of the experiments from mlruns
"""

import mlflow
import git

basePath = git.Repo('.', search_parent_directories=True).working_tree_dir
mlflow.set_tracking_uri(f"file:{basePath}/mlruns")

def get_best_runs():

all_runs = mlflow.search_runs(search_all_experiments=True)
columns = ['tags.mlflow.runName', 'params.model_name', 'metrics.accuracy']
all_runs = all_runs[columns]
best_runs = all_runs.groupby(['tags.mlflow.runName', 'params.model_name']).agg({'metrics.accuracy': 'max'}).reset_index()
best_runs = best_runs.pivot(index='tags.mlflow.runName', columns='params.model_name', values='metrics.accuracy').reset_index()
best_runs.columns.name = None
best_runs = best_runs.rename(columns={'tags.mlflow.runName': 'Dataset'})
# save as markdown file
with open('best_runs.md', 'w') as f:
f.write(best_runs.to_markdown(index=False))


if __name__ == "__main__":
get_best_runs()

0 comments on commit 744c113

Please sign in to comment.