Skip to content

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