File size: 1,962 Bytes
e355cb1
 
 
c29fe64
 
3b5bc19
 
e355cb1
3b5bc19
c1c9aee
3b5bc19
 
 
 
e355cb1
e2e2896
ba32ce3
3b5bc19
 
d8268cd
3b5bc19
e355cb1
3b5bc19
e355cb1
3b5bc19
 
e355cb1
3b5bc19
 
 
 
e355cb1
3b5bc19
e355cb1
 
ba32ce3
29d9978
9f14218
ba32ce3
 
 
facd25e
ba32ce3
 
 
3b5bc19
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
import gradio as gr
import numpy as np
import torch
import spaces

from diffusers import DiffusionPipeline
from PIL import Image

multi_view_diffusion_pipeline = DiffusionPipeline.from_pretrained(
    "jkorstad/multi-view-diffusion",
    custom_pipeline="dylanebert/multi-view-diffusion",
    torch_dtype=torch.float16,
    trust_remote_code=True,
).to("cuda")

@spaces.GPU
def run(image, elevation):
    image = np.array(image, dtype=np.float32) / 255.0
    images = multi_view_diffusion_pipeline(
        "", image, guidance_scale=5, num_inference_steps=30, elevation=elevation
    )

    images = [Image.fromarray((img * 255).astype("uint8")) for img in images]

    width, height = images[0].size
    grid_img = Image.new("RGB", (2 * width, 2 * height))

    grid_img.paste(images[0], (0, 0))
    grid_img.paste(images[1], (width, 0))
    grid_img.paste(images[2], (0, height))
    grid_img.paste(images[3], (width, height))

    return grid_img


demo = gr.Interface(
    title="Multi-View of any image",
    description="Imagine being able to visualize an object or scene from multiple angles simultaneously. My Multi-View Diffusion Model allows you to do just that. Simply upload an image, select your desired view elevation, and my model will generate a 4-way view of the scene, showing you what it looks like from the front, back, left, and right. Explore New Perspectives. Generate 4-way views of any image, from objects to landscapes. Discover new details and insights from multiple angles. Enhance your understanding of complex scenes and objects. Please note that additional views are generated and will not be exact or always accurate.",
    fn=run,
    inputs=[
        gr.Image(label="Input Image"),
        gr.Slider(0, 42, 10, label="Elevation", info="Choose the elevation value for the generated multi view output. A higher value will show the object from a higher elevation.")
    ],
    outputs=gr.Image(label="Output Image")
)
demo.launch()