Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
camenduru
GitHub Repository: camenduru/stable-diffusion-webui-colab
Path: blob/main/dev/run.ipynb
1607 views
Kernel: Python 3
import os import json directory_path = 'C://Users//PC//Desktop//stable-diffusion-webui-colab//nightly' file_list = os.listdir(directory_path) for filename in file_list: if filename.endswith('.ipynb'): new_filename = filename.replace('.ipynb', '_run.ipynb') notebook_content = { "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {"id": "view-in-github"}, "source": [ f"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/stable-diffusion-webui-colab/blob/main/nightly/{new_filename})" ], }, { "cell_type": "code", "execution_count": None, "metadata": {}, "outputs": [], "source": [ "%cd /content\n", "import urllib, requests\n", "from notebook import notebookapp\n", "name = requests.get(f\"{list(notebookapp.list_running_servers())[0]['url']}api/sessions\").json()[0][\"name\"].replace(\"_run\", \"\")\n", "url = '/'.join(urllib.parse.unquote(requests.get(f\"{list(notebookapp.list_running_servers())[0]['url']}api/sessions\").json()[0][\"path\"].split(\"=\", 1)[1]).split(\"/\")).replace(\"/blob/\", \"/\").replace(\"github.com\", \"raw.githubusercontent.com\").replace(\"_run\", \"\")\n", "!wget {url} -O {name}\n", "%run {name}" ], }, ], "metadata": { "accelerator": "GPU", "colab": { "collapsed_sections": [], "private_outputs": True, "provenance": [], }, "gpuClass": "standard", "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3", }, "language_info": { "name": "python", "version": "3.10.8", }, }, "nbformat": 4, "nbformat_minor": 0, } with open(os.path.join(directory_path, new_filename), 'w') as notebook_file: json.dump(notebook_content, notebook_file, indent=2)