{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": 2.8891853944186117e+38, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 616 }, "id": 2.8891853944186117e+38, "outputId": "b60a6d5e-045d-4b40-bfd8-6caa407a34df", "scrolled": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7860\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import numpy as np\n", "import gradio as gr\n", "import os\n", "from PIL import Image\n", "from functools import partial\n", "\n", "def retrieve_input_image_wild(dataset, inputs):\n", " img_id = inputs\n", " img_path = os.path.join('online_demo', dataset, 'step-100_scale-6.0')\n", " try:\n", " image = Image.open(os.path.join(img_path, '%s.jpg' % img_id))\n", " except:\n", " image = Image.open(os.path.join(img_path, '%s.png' % img_id))\n", " \n", " image.thumbnail([256, 256], Image.Resampling.LANCZOS) \n", " return image\n", "\n", "def retrieve_input_image(dataset, inputs):\n", " img_id = inputs\n", " img_path = os.path.join('online_demo', dataset, 'step-100_scale-6.0', img_id, 'input.png')\n", " image = Image.open(img_path)\n", " return image\n", "\n", "def retrieve_novel_view(dataset, img_id, polar, azimuth, zoom, seed):\n", " polar = polar // 30 + 1\n", " azimuth = azimuth // 30\n", " zoom = int(zoom * 2 + 1)\n", " img_path = os.path.join('online_demo', dataset, 'step-100_scale-6.0', img_id,\\\n", " 'polar-%d_azimuth-%d_distance-%d_seed-%d.png' % (polar, azimuth, zoom, seed))\n", " image = Image.open(img_path)\n", " return image\n", " \n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"Flip text or image files using this demo.\")\n", " with gr.Tab(\"In-the-wild Images\"):\n", " with gr.Row():\n", " with gr.Column(scale=1):\n", " default_input_image = Image.open( os.path.join('online_demo', 'nerf_wild', 'step-100_scale-6.0', 'car1.png'))\n", " default_input_image.thumbnail([256, 256], Image.Resampling.LANCZOS) \n", " input_image = gr.Image(default_input_image, shape=[256, 256])\n", " options = sorted(next(os.walk('online_demo/nerf_wild/step-100_scale-6.0'))[1])\n", " img_id = gr.Dropdown(options, value='car1', label='options')\n", " text_button = gr.Button(\"Load Input Image\")\n", " retrieve_input_image_dataset = partial(retrieve_input_image_wild, 'nerf_wild')\n", " text_button.click(retrieve_input_image_dataset, inputs=img_id, outputs=input_image)\n", "\n", " with gr.Column(scale=1):\n", " novel_view = gr.Image(shape=[256, 256])\n", " inputs = [img_id,\n", " gr.Slider(-30, 30, value=0, step=30, label='Polar angle (vertical rotation in degrees)'),\n", " gr.Slider(0, 330, value=0, step=30, label='Azimuth angle (horizontal rotation in degrees)'),\n", " gr.Slider(-0.5, 0.5, value=0, step=0.5, label='Zoom'),\n", " gr.Slider(0, 3, value=1, step=1, label='Random seed')]\n", " \n", " submit_button = gr.Button(\"Generate Novel View\")\n", " retrieve_novel_view_dataset = partial(retrieve_novel_view, 'nerf_wild')\n", " submit_button.click(retrieve_novel_view_dataset, inputs=inputs, outputs=novel_view)\n", " \n", " with gr.Tab(\"Google Scanned Objects\"):\n", " with gr.Row():\n", " with gr.Column(scale=1):\n", " default_input_image = Image.open( os.path.join('online_demo', 'GSO', 'step-100_scale-6.0', 'SAMBA_HEMP', 'input.png'))\n", " default_input_image.thumbnail([256, 256], Image.Resampling.LANCZOS) \n", " input_image = gr.Image(default_input_image, shape=[256, 256])\n", " options = sorted(os.listdir('online_demo/GSO/step-100_scale-6.0'))\n", " img_id = gr.Dropdown(options, value='SAMBA_HEMP', label='options')\n", " text_button = gr.Button(\"Choose Input Image\")\n", " retrieve_input_image_dataset = partial(retrieve_input_image, 'GSO')\n", " text_button.click(retrieve_input_image_dataset, inputs=img_id, outputs=input_image)\n", "\n", " with gr.Column(scale=1):\n", " novel_view = gr.Image(shape=[256, 256])\n", " inputs = [img_id,\n", " gr.Slider(-30, 30, value=0, step=30, label='Polar angle (vertical rotation in degrees)'),\n", " gr.Slider(0, 330, value=0, step=30, label='Azimuth angle (horizontal rotation in degrees)'),\n", " gr.Slider(-0.5, 0.5, value=0, step=0.5, label='Zoom'),\n", " gr.Slider(0, 3, value=1, step=1, label='Random seed')]\n", " \n", " submit_button = gr.Button(\"Generate Novel View\")\n", " retrieve_novel_view_dataset = partial(retrieve_novel_view, 'GSO')\n", " submit_button.click(retrieve_novel_view_dataset, inputs=inputs, outputs=novel_view)\n", " \n", " with gr.Tab(\"RTMV\"):\n", " with gr.Row():\n", " with gr.Column(scale=1):\n", " default_input_image = Image.open( os.path.join('online_demo', 'RTMV', 'step-100_scale-6.0', '00000', 'input.png'))\n", " default_input_image.thumbnail([256, 256], Image.Resampling.LANCZOS) \n", " input_image = gr.Image(default_input_image, shape=[256, 256])\n", " options = sorted(os.listdir('online_demo/RTMV/step-100_scale-6.0'))\n", " img_id = gr.Dropdown(options, value='00000', label='options')\n", " text_button = gr.Button(\"Choose Input Image\")\n", " retrieve_input_image_dataset = partial(retrieve_input_image, 'RTMV')\n", " text_button.click(retrieve_input_image_dataset, inputs=img_id, outputs=input_image)\n", "\n", " with gr.Column(scale=1):\n", " novel_view = gr.Image(shape=[256, 256])\n", " inputs = [img_id,\n", " gr.Slider(-30, 30, value=0, step=30, label='Polar angle (vertical rotation in degrees)'),\n", " gr.Slider(0, 330, value=0, step=30, label='Azimuth angle (horizontal rotation in degrees)'),\n", " gr.Slider(-0.5, 0.5, value=0, step=0.5, label='Zoom'),\n", " gr.Slider(0, 3, value=1, step=1, label='Random seed')]\n", " \n", " submit_button = gr.Button(\"Generate Novel View\")\n", " retrieve_novel_view_dataset = partial(retrieve_novel_view, 'RTMV')\n", " submit_button.click(retrieve_novel_view_dataset, inputs=inputs, outputs=novel_view)\n", " \n", " \n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n" ] }, { "cell_type": "code", "execution_count": null, "id": "2febec07", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "colab": { "provenance": [] }, "gpuClass": "standard", "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" } }, "nbformat": 4, "nbformat_minor": 5 }