diff --git a/colab/roop.ipynb b/colab/roop.ipynb new file mode 100644 index 0000000..772464a --- /dev/null +++ b/colab/roop.ipynb @@ -0,0 +1,166 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "gpuType": "T4" + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + }, + "accelerator": "GPU" + }, + "cells": [ + { + "cell_type": "code", + "source": [ + "from google.colab import drive\n", + "drive.mount('/content/gdrive')" + ], + "metadata": { + "id": "pq3f83s2Jb3C" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "#@markdown # Install/Update roop\n", + "from IPython.display import clear_output\n", + "from IPython.utils import capture\n", + "from subprocess import getoutput\n", + "import ipywidgets as widgets\n", + "import sys\n", + "import fileinput\n", + "import os\n", + "import time\n", + "\n", + "if not os.path.exists(\"/content/\"):\n", + " print('\u001b[1;31mGdrive not connected, using colab storage ...')\n", + " time.sleep(4)\n", + " !mkdir -p /content/\n", + "with capture.capture_output() as cap:\n", + " def inf(msg, style, wdth):\n", + " inf = widgets.Button(description=msg, disabled=True, button_style=style, layout=widgets.Layout(min_width=wdth))\n", + " display(inf)\n", + "\n", + " %mkdir -p /content/gdrive/MyDrive\n", + " %cd /content/gdrive/MyDrive\n", + " !git clone https://github.com/s0md3v/roop.git\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/MyDrive/roop/\n", + " !git reset --hard\n", + " time.sleep(1)\n", + "print('\u001b[1;32m')\n", + "!git pull\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')" + ], + "metadata": { + "cellView": "form", + "id": "SEAgT4YZJexL" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "9mpP8csoFKXt", + "cellView": "form" + }, + "outputs": [], + "source": [ + "#@markdown # Requirements\n", + "\n", + "print('\u001b[1;32mInstalling requirements...')\n", + "\n", + "with capture.capture_output() as cap:\n", + " %cd /content/gdrive/MyDrive/roop/\n", + " !wget -O \"inswapper_128.onnx\" https://civitai.com/api/download/models/85159\n", + " !pip install onnxruntime-gpu\n", + " !pip install -r requirements.txt\n", + " !mkdir /content/gdrive/MyDrive/roop_output\n", + "\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')" + ] + }, + { + "cell_type": "code", + "source": [ + "#@markdown # Download example files\n", + "\n", + "print('\u001b[1;32mDownload example files...')\n", + "\n", + "with capture.capture_output() as cap:\n", + " !mkdir /content/gdrive/MyDrive/example\n", + " %cd /content/gdrive/MyDrive/example\n", + " !wget -O \"img.jpg\" https://pinkmirror.com/getImagePerson.ashx?id=16051&&photo_type=photo\n", + " !wget -O \"vid.mp4\" https://github.com/ai-forever/ghost/raw/main/examples/videos/nggyup.mp4\n", + "\n", + "clear_output()\n", + "inf('\\u2714 Done','success', '50px')" + ], + "metadata": { + "cellView": "form", + "id": "nnyfsTHvvosD" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "#@markdown #**Select source image and target video**\n", + "\n", + "#@markdown Choose source image as a photo, preferable a selfie of a person\n", + "\n", + "\n", + "source_path = '/content/gdrive/MyDrive/example/img.jpg' #@param {type:\"string\"}\n", + "target_path = '/content/gdrive/MyDrive/example/vid.mp4' #@param {type:\"string\"}\n", + "path_to_video = '/content/gdrive/MyDrive/roop_output/changed_video.mp4' #@param {type:\"string\"}\n", + "keep_fps = False #@param {type:\"boolean\"}\n", + "keep_frames = False #@param {type:\"boolean\"}\n", + "\n", + "OUT_VIDEO_NAME = path_to_video\n", + "\n", + "!python /content/gdrive/MyDrive/roop/run.py -f $source_path -t $target_path -o $path_to_video --keep-fps --gpu-vendor nvidia\n" + ], + "metadata": { + "cellView": "form", + "id": "xnSqGP3D5h-H" + }, + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "#@markdown #**Visualize Video Swap**\n", + "\n", + "from IPython.display import HTML\n", + "from base64 import b64encode\n", + "\n", + "video_file = open(OUT_VIDEO_NAME, \"r+b\").read()\n", + "video_url = f\"data:video/mp4;base64,{b64encode(video_file).decode()}\"\n", + "\n", + "HTML(f\"\"\"\"\"\")" + ], + "metadata": { + "cellView": "form", + "id": "3LF20NWxFi4j" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file