File size: 1,670 Bytes
a3a3ae4
 
 
 
1b613d0
 
a3a3ae4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b613d0
 
 
 
 
 
 
 
 
 
a3a3ae4
f8bdccb
 
a3a3ae4
e5cd8c6
 
 
 
a3a3ae4
e5cd8c6
 
a3a3ae4
a57806e
 
 
 
 
 
 
1b613d0
a3a3ae4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import gradio as gr
import spaces
from PIL import Image
from typing import List
import glob
import os

from pipeline import prepare_white_image, MultiViewGenerator
from util import download_file, unzip_file

download_file("https://huggingface.co/aki-0421/character-360/resolve/main/v2.ckpt", "v2.ckpt")
download_file("https://huggingface.co/hbyang/Hi3D/resolve/main/ckpts.zip", "ckpts.zip")

unzip_file("ckpts.zip", ".")

multi_view_generator = MultiViewGenerator(checkpoint_path="v2.ckpt")

@spaces.GPU(duration=120)
def generate_images(input_image: Image.Image) -> List[Image.Image]:
    white_image = prepare_white_image(input_image=input_image)

    return multi_view_generator.infer(white_image=white_image)

def prepare_example() -> List[Image.Image]:
    image_files = sorted(glob.glob(os.path.join("assets/", '*.png')))

    images = []
    for image_file in image_files:
        image = Image.open(image_file)
        images.append(image)

    return images

with gr.Blocks() as demo:
    gr.Markdown("# Character-360")
    gr.Markdown("Do you want to check out your character in 360°?")
    with gr.Row():
        input_image = gr.Image(label="Input Image", type="pil")
        output_gallery = gr.Gallery(
        label="Generated images", show_label=False, elem_id="gallery"
    , columns=[3], object_fit="contain", height="auto")

    btn = gr.Button("Generate")
    btn.click(generate_images, input_image, output_gallery)

    example_images = prepare_example()
    gr.Markdown("### Example Output")
    gr.Gallery(
        value=example_images,
        label="Example Images",
        columns=[5], object_fit="contain", height="auto"
    )

demo.launch()