Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix github repo url and add direct colab url #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

snimshchikov
Copy link

Great work with maintaining this repo! Added some stuff to make navigation easier
You can find a python file that I used in comments

@snimshchikov
Copy link
Author

import os
import json

# Fix github repo url and add direct colab url

directory = "./"
github_username = "nolanaatama"
branch = "main"

if branch == "main":
    repo_url = f"https://github.com/{github_username}/sd-1click-colab"
else:
    repo_url = f"https://github.com/{github_username}/sd-1click-colab/tree/{branch}"
base_colab_url = f"https://colab.research.google.com/github/{github_username}/sd-1click-colab/blob/{branch}/"

for file in os.scandir(directory):
    if not file.is_file() or not file.name.endswith(".ipynb"):
        continue

    with open(file, "r") as f:
        print(file.name)
        data = json.loads(f.read())

        for cell in data["cells"]:
            if (cell["cell_type"] == "markdown" and 
                cell["source"][0].find("GitHub for more:") != -1
            ):
                cell["source"] = [
                    f"# 📚 GitHub for more: [_@{github_username}_](https://github.com/{github_username})\n",
                    f"# 📦 Repo: [Github]({repo_url})\n",
                    f"# 🔗 Open: [Google Colab]({base_colab_url}{file.name})"
                ]
                break

        with open(file, "w") as fw:
            fw.write(json.dumps(data, indent=2))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant