-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added automatic fetching of stars
- Loading branch information
Showing
5 changed files
with
117 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,16 @@ jobs: | |
- name: Install dependencies | ||
run: pip install -r requirements.txt | ||
|
||
- name: Update stars | ||
run: python update_stars.py | ||
|
||
- name: Generate README | ||
run: python generate_readme.py | ||
|
||
- name: Commit and push changes | ||
run: | | ||
git config --global user.name 'GitHub Actions' | ||
git config --global user.email '[email protected]' | ||
git add README.md | ||
git add . | ||
git commit -m "chore: automatically generated README.md" | ||
git push origin master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Autogenerated by update_stars.py | ||
https://huggingface.co/Phind/Phind-CodeLlama-34B-v2: | ||
stars: 332 | ||
updated: '2023-10-03T12:29:52.263572' | ||
https://huggingface.co/WizardLM/WizardCoder-15B-V1.0: | ||
stars: 614 | ||
updated: '2023-10-03T12:29:52.263572' | ||
https://huggingface.co/WizardLM/WizardCoder-Python-34B-V1.0: | ||
stars: 597 | ||
updated: '2023-10-03T12:29:52.263572' | ||
https://huggingface.co/bigcode/santacoder: | ||
stars: 298 | ||
updated: '2023-10-03T12:29:52.263572' | ||
https://huggingface.co/replit/replit-code-v1-3b: | ||
stars: 674 | ||
updated: '2023-10-03T12:29:52.263572' | ||
https://huggingface.co/sahil2801/replit-code-instruct-glaive: | ||
stars: 83 | ||
updated: '2023-10-03T12:29:52.263572' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import yaml | ||
import requests | ||
|
||
|
||
from datetime import datetime | ||
|
||
|
||
from pathlib import Path | ||
|
||
|
||
def _get_stars(url): | ||
if url.startswith("https://huggingface.co/"): | ||
# examples: | ||
# - datasets/bigcode/the-stack | ||
# - models/Phind/Phind-CodeLlama-34B-v2 | ||
# - WizardLM/WizardCoder-Python-34B-V1.0 (assumed to be a model) | ||
repo_id = url[23:] | ||
if not any([repo_id.startswith("datasets/"), repo_id.startswith("models/")]): | ||
repo_id = f"models/{repo_id}" | ||
response = requests.get(f"https://huggingface.co/api/{repo_id}") | ||
response.raise_for_status() | ||
json_data = response.json() | ||
stars_count = json_data["likes"] | ||
elif url.startswith("https://github.com/"): | ||
github_api_url = "https://api.github.com/repos" | ||
repo_id = url[19:] | ||
response = requests.get(f"{github_api_url}/{repo_id}") | ||
response.raise_for_status() | ||
json_data = response.json() | ||
stars_count = json_data["stargazers_count"] | ||
else: | ||
raise ValueError(f"Unknown repo url: {url}") | ||
|
||
return stars_count | ||
|
||
|
||
def save_stars(file_path: str, dest: str) -> None: | ||
with open(file_path, "r") as f: | ||
data = yaml.load(f, Loader=yaml.SafeLoader) | ||
|
||
starmap = {} | ||
if Path(dest).exists(): | ||
with open(dest, "r") as f: | ||
starmap = yaml.load(f, Loader=yaml.SafeLoader) | ||
|
||
now = datetime.now() | ||
|
||
def _update_stars(link): | ||
try: | ||
print(f"Attempting to get stars for {link}") | ||
stars_count = _get_stars(link) | ||
starmap[link] = { | ||
"stars": stars_count, | ||
"updated": now.isoformat(), | ||
} | ||
print(f" Succeeded: {stars_count}") | ||
except Exception as e: | ||
print(f" Error: {e}") | ||
|
||
# Update the existing entries, if it's been more than 3 days: | ||
for link in starmap: | ||
if (datetime.now() - datetime.fromisoformat(starmap[link]["updated"])).days > 3: | ||
_update_stars(link) | ||
|
||
# If any new | ||
for category in data: | ||
for item in data[category]: | ||
if item["link"] not in starmap: | ||
print("New entry: ", item["link"]) | ||
_update_stars(item["link"]) | ||
|
||
with open(dest, "w") as f: | ||
# add comment to the top of the file, so that it's clear it's autogenerated | ||
f.write("# Autogenerated by update_stars.py\n") | ||
yaml.dump(starmap, f, default_flow_style=False) | ||
|
||
|
||
if __name__ == "__main__": | ||
save_stars("data.yaml", "stars.yaml") |