{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "\n", "import sys, os\n", "import gradio as gr\n", "import numpy as np\n", "sys.path.append('stylegan3')\n", "import utils\n", "\n", "def to_uint8(im, ndim=2):\n", " im -= np.min(im)\n", " im /= np.max(im)\n", " im *= 255.\n", " im = np.asarray(im, dtype=np.uint8)\n", " if ndim == 3: \n", " if im.ndim == 2:\n", " im = np.expand_dims(im, axis=-1)\n", " elif im.ndim == 3:\n", " if im.shape[0] == 1: \n", " np.transpose(im, (1,2,0))\n", " im = np.tile(im, (1,1,3)) #make fake RGB\n", " return im\n", " elif ndim ==2:\n", " if im.ndim == 2:\n", " return im\n", " if im.ndim == 3:\n", " if im.shape[0] == 1: #[1, H, W]\n", " return im[0,...]\n", " elif im.shape[2] == 1: #[H, W, 1]\n", " return im[...,0]\n", " else:\n", " raise AssertionError(f\"Unexpected image passed to to_uint8 with shape: {np.shape(im)}.\")\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7868\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2022-10-11 17:33:10.390 INFO paramiko.transport: Connected (version 2.0, client OpenSSH_7.6p1)\n", "2022-10-11 17:33:11.271 INFO paramiko.transport: Authentication (publickey) successful!\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running on public URL: https://23528.gradio.app\n", "\n", "This share link expires in 72 hours. For free permanent hosting, check out Spaces: https://huggingface.co/spaces\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "