Skip to content

Commit

Permalink
Fetch name from commit and use in lb
Browse files Browse the repository at this point in the history
  • Loading branch information
hetulvp committed Apr 21, 2024
1 parent 0f6aeab commit d439c77
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 31 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/update_leaderboard_after_merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
with:
script: core.setFailed('More than one submissions are not allowed at once.')

# TODO(hetul): Get github profile from email https://api.github.com/search/users?q=EMAIL
- if: ${{ (steps.changes.outputs.src == 'true') && (steps.changes.outputs.src_count == 1) }}
name: Get author's name from last commit
id: author_name
Expand Down Expand Up @@ -62,8 +63,8 @@ jobs:
filename_without_extension="${filename%.*}" # Remove extension
python -m scripts.leaderboard --github_user="${{ steps.author_name.outputs.author_name }}" --prompt="$filename_without_extension"
# - if: ${{ (steps.changes.outputs.src == 'true') && (steps.changes.outputs.src_count == 1) }}
# name: Commit changes
# uses: EndBug/add-and-commit@v9
# with:
# default_author: github_actions
- if: ${{ (steps.changes.outputs.src == 'true') && (steps.changes.outputs.src_count == 1) }}
name: Commit changes
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
13 changes: 4 additions & 9 deletions session_2/challenge/leaderboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ Check [participation guide](how_to_participate.md).
<center>

<!-- leader-board-begins -->
| Rank | Profile Image | GitHub Username | Solution | Accuracy % |
|-------:|:------------------------------------------------------------------------------------------------|:-------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------|-------------:|
| 1 | <img src="https://github.com/.png" width="50px" height="50px" class="profile-image"> | [](https://github.com/) | [baseline](https://github.com/infocusp/llm_seminar_series/blob/main/session_2/challenge/submissions/baseline.py) | 100 |
| 2 | <img src="https://github.com/hetulvp.png" width="50px" height="50px" class="profile-image"> | [hetulvp](https://github.com/hetulvp) | [baseline_copy](https://github.com/infocusp/llm_seminar_series/blob/main/session_2/challenge/submissions/baseline_copy.py) | 100 |
| 3 | <img src="https://github.com/hetul-patel.png" width="50px" height="50px" class="profile-image"> | [New User](https://github.com/new_user) | [New Solution](https://github.com/new_solution) | 99.5 |
| 4 | <img src="https://github.com/hetul-patel.png" width="50px" height="50px" class="profile-image"> | [Username 2](https://github.com/username2) | [Baseline](https://github.com/infocusp/llm_seminar_series/blob/hetul/prompting-leader-board/session_2/challenge/submissions/baseline.py) | 95 |
| 5 | <img src="https://github.com/hetul-patel.png" width="50px" height="50px" class="profile-image"> | [Username 4](https://github.com/username4) | [Baseline](https://github.com/infocusp/llm_seminar_series/blob/hetul/prompting-leader-board/session_2/challenge/submissions/baseline.py) | 95 |
| 6 | <img src="https://github.com/hetul-patel.png" width="50px" height="50px" class="profile-image"> | [Username 3](https://github.com/username3) | [Baseline](https://github.com/infocusp/llm_seminar_series/blob/hetul/prompting-leader-board/session_2/challenge/submissions/baseline.py) | 10 |
| 7 | <img src="https://github.com/hetul-patel.png" width="50px" height="50px" class="profile-image"> | [Username 1](https://github.com/username1) | [Baseline](https://github.com/infocusp/llm_seminar_series/blob/hetul/prompting-leader-board/session_2/challenge/submissions/baseline.py) | 0 |
| Rank | Name | Solution | Accuracy % |
|-------:|:-------|:-----------------------------------------------------------------------------------------------------------------|-------------:|
| 1 | XYZ | [baseline](https://github.com/infocusp/llm_seminar_series/blob/main/session_2/challenge/submissions/baseline.py) | 100 |
| 2 | Hetul | [baseline](https://github.com/infocusp/llm_seminar_series/blob/main/session_2/challenge/submissions/baseline.py) | 50 |
<!-- leader-board-ends -->

</center>
29 changes: 13 additions & 16 deletions session_2/challenge/scripts/leaderboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Sample command:
python -m scripts.leaderboard \
--github_user=your_github_user \
--github_name=your_github_user \
--prompt=baseline
"""

Expand All @@ -18,15 +18,15 @@
"prompt", None, "Name of the submitted prompt to evaluate."
)

_GITHUB_USER = flags.DEFINE_string(
"github_user", None, "Github username to add an entry in leaderboard."
_GITHUB_NAME = flags.DEFINE_string(
"github_name", None, "Github name to add an entry in leaderboard."
)


_LEADERBORAD = "leaderboard.md" # current leaderboard


def generate_leaderboard(prompt_name: str, accuracy: float, github_user: str):
def generate_leaderboard(prompt_name: str, accuracy: float, github_name: str):
"""Generates leaderboard."""
# Read the markdown table into a DataFrame
with open(_LEADERBORAD, "r") as file:
Expand All @@ -39,16 +39,15 @@ def generate_leaderboard(prompt_name: str, accuracy: float, github_user: str):

# Extract rows using regex
rows = re.findall(
r"\|([^|]+)\|([^|]+)\|([^|]+)\|([^|]+)\|([^|]+)\|", table_content
r"\|([^|]+)\|([^|]+)\|([^|]+)\|([^|]+)\|", table_content
)[2:]

# Create a DataFrame from the extracted rows
df = pd.DataFrame(
rows,
columns=[
"Rank",
"Profile Image",
"GitHub Username",
"Name",
"Solution",
"Accuracy %",
],
Expand All @@ -65,17 +64,15 @@ def generate_leaderboard(prompt_name: str, accuracy: float, github_user: str):
repo_url = "https://github.com/infocusp/llm_seminar_series/blob/main/session_2/challenge/submissions"
new_entry = {
"Rank": len(df) + 1,
"Profile Image": f'<img src="https://github.com/{github_user}.png" '
+ 'width="50px" height="50px" class="profile-image">',
"GitHub Username": f"[{github_user}](https://github.com/{github_user})",
"Name": github_name,
"Solution": f"[{prompt_name}]({repo_url}/{prompt_name}.py)",
"Accuracy %": accuracy,
}

df = pd.concat([df, pd.DataFrame([new_entry])], ignore_index=True)

# Keep only the highest submission for each user
highest_indices = df.groupby("GitHub Username")["Accuracy %"].idxmax()
highest_indices = df.groupby("Name")["Accuracy %"].idxmax()
df_highest = df.loc[highest_indices]

# Sort the DataFrame by "Accuracy %" column in descending order
Expand All @@ -102,19 +99,19 @@ def generate_leaderboard(prompt_name: str, accuracy: float, github_user: str):

logging.info(
"Submission by %s with prompt %s updated in the leaderboard.",
github_user,
github_name,
prompt_name,
)


def update_leaderboard(prompt_name: str, github_user: str):
def update_leaderboard(prompt_name: str, github_name: str):
"""Generates a public leaderboard by evaluating given submission."""
sample_dataset = dataset.load_dataset_from_dir(samples_dir="dataset")
acc = evaluate_lib.evaluate(
dataset=sample_dataset, prompt_name=prompt_name
)
generate_leaderboard(
prompt_name=prompt_name, accuracy=acc, github_user=github_user
prompt_name=prompt_name, accuracy=acc, github_name=github_name
)


Expand All @@ -124,11 +121,11 @@ def main(argv: Sequence[str]) -> None:
raise app.UsageError("Too many command-line arguments.")
logging.getLogger().setLevel(logging.INFO)
update_leaderboard(
prompt_name=_PROMPT.value, github_user=_GITHUB_USER.value
prompt_name=_PROMPT.value, github_name=_GITHUB_NAME.value
)


if __name__ == "__main__":
flags.mark_flag_as_required("prompt")
flags.mark_flag_as_required("github_user")
flags.mark_flag_as_required("github_name")
app.run(main)
2 changes: 1 addition & 1 deletion session_2/challenge/submissions/baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def build_prompt(self, job_description: str) -> str:
Say "YES" if the given job description is suitable for
a freshers other wise say "NO".
{job_description}.
{job_description}
"""
return prompt.strip()
Expand Down

0 comments on commit d439c77

Please sign in to comment.