import numpy as np import gradio as gr import os from PIL import Image from functools import partial def retrieve_input_image(dataset, inputs): img_id = inputs img_path = os.path.join('online_demo', dataset, 'step-100_scale-6.0', img_id, 'input.png') image = Image.open(img_path) return image def retrieve_novel_view(dataset, img_id, polar, azimuth, zoom, seed): polar = polar // 30 + 1 azimuth = azimuth // 30 zoom = int(zoom * 2 + 1) img_path = os.path.join('online_demo', dataset, 'step-100_scale-6.0', img_id,\ 'polar-%d_azimuth-%d_distance-%d_seed-%d.png' % (polar, azimuth, zoom, seed)) image = Image.open(img_path) return image with gr.Blocks() as demo: gr.Markdown("Flip text or image files using this demo.") with gr.Tab("In-the-wild Images"): with gr.Row(): with gr.Column(scale=1): default_input_image = Image.open( os.path.join('online_demo', 'nerf_wild', 'step-100_scale-6.0', 'car1', 'input.png')) input_image = gr.Image(default_input_image, shape=[256, 256]) options = sorted(os.listdir('online_demo/nerf_wild/step-100_scale-6.0')) img_id = gr.Dropdown(options, value='car1') text_button = gr.Button("Choose Input Image") retrieve_input_image_dataset = partial(retrieve_input_image, 'nerf_wild') text_button.click(retrieve_input_image_dataset, inputs=img_id, outputs=input_image) with gr.Column(scale=1): novel_view = gr.Image(shape=[256, 256]) inputs = [img_id, gr.Slider(-30, 30, value=0, step=30, label='Polar angle (vertical rotation in degrees)'), gr.Slider(0, 330, value=0, step=30, label='Azimuth angle (horizontal rotation in degrees)'), gr.Slider(-0.5, 0.5, value=0, step=0.5, label='Zoom'), gr.Slider(1, 4, value=1, step=1, label='Random seed')] submit_button = gr.Button("Get Novel View") retrieve_novel_view_dataset = partial(retrieve_novel_view, 'nerf_wild') submit_button.click(retrieve_novel_view_dataset, inputs=inputs, outputs=novel_view) with gr.Tab("Google Scanned Objects"): with gr.Row(): with gr.Column(scale=1): default_input_image = Image.open( os.path.join('online_demo', 'GSO', 'step-100_scale-6.0', 'SAMBA_HEMP', 'input.png')) input_image = gr.Image(default_input_image, shape=[256, 256]) options = sorted(os.listdir('online_demo/GSO/step-100_scale-6.0')) img_id = gr.Dropdown(options, value='SAMBA_HEMP') text_button = gr.Button("Choose Input Image") retrieve_input_image_dataset = partial(retrieve_input_image, 'GSO') text_button.click(retrieve_input_image_dataset, inputs=img_id, outputs=input_image) with gr.Column(scale=1): novel_view = gr.Image(shape=[256, 256]) inputs = [img_id, gr.Slider(-30, 30, value=0, step=30, label='Polar angle (vertical rotation in degrees)'), gr.Slider(0, 330, value=0, step=30, label='Azimuth angle (horizontal rotation in degrees)'), gr.Slider(-0.5, 0.5, value=0, step=0.5, label='Zoom'), gr.Slider(1, 4, value=1, step=1, label='Random seed')] submit_button = gr.Button("Get Novel View") retrieve_novel_view_dataset = partial(retrieve_novel_view, 'GSO') submit_button.click(retrieve_novel_view_dataset, inputs=inputs, outputs=novel_view) with gr.Tab("RTMV"): with gr.Row(): with gr.Column(scale=1): default_input_image = Image.open( os.path.join('online_demo', 'RTMV', 'step-100_scale-6.0', '00000', 'input.png')) input_image = gr.Image(default_input_image, shape=[256, 256]) options = sorted(os.listdir('online_demo/RTMV/step-100_scale-6.0')) img_id = gr.Dropdown(options, value='00000') text_button = gr.Button("Choose Input Image") retrieve_input_image_dataset = partial(retrieve_input_image, 'RTMV') text_button.click(retrieve_input_image_dataset, inputs=img_id, outputs=input_image) with gr.Column(scale=1): novel_view = gr.Image(shape=[256, 256]) inputs = [img_id, gr.Slider(-30, 30, value=0, step=30, label='Polar angle (vertical rotation in degrees)'), gr.Slider(0, 330, value=0, step=30, label='Azimuth angle (horizontal rotation in degrees)'), gr.Slider(-0.5, 0.5, value=0, step=0.5, label='Zoom'), gr.Slider(1, 4, value=1, step=1, label='Random seed')] submit_button = gr.Button("Get Novel View") retrieve_novel_view_dataset = partial(retrieve_novel_view, 'RTMV') submit_button.click(retrieve_novel_view_dataset, inputs=inputs, outputs=novel_view) if __name__ == "__main__": demo.launch()