Spaces:
Runtime error
Runtime error
stonkszain
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import torch
|
4 |
+
from diffusers import DiffusionPipeline
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
multi_view_diffusion_pipeline = DiffusionPipeline.from_pretrained(
|
8 |
+
"dylanebert/multi-view-diffusion",
|
9 |
+
custom_pipeline="dylanebert/multi-view-diffusion",
|
10 |
+
torch_dtype=torch.float16,
|
11 |
+
trust_remote_code=True,
|
12 |
+
).to("cuda")
|
13 |
+
|
14 |
+
|
15 |
+
def run(image):
|
16 |
+
image = np.array(image, dtype=np.float32) / 255.0
|
17 |
+
images = multi_view_diffusion_pipeline(
|
18 |
+
"", image, guidance_scale=5, num_inference_steps=30, elevation=0
|
19 |
+
)
|
20 |
+
|
21 |
+
images = [Image.fromarray((img * 255).astype("uint8")) for img in images]
|
22 |
+
|
23 |
+
width, height = images[0].size
|
24 |
+
grid_img = Image.new("RGB", (2 * width, 2 * height))
|
25 |
+
|
26 |
+
grid_img.paste(images[0], (0, 0))
|
27 |
+
grid_img.paste(images[1], (width, 0))
|
28 |
+
grid_img.paste(images[2], (0, height))
|
29 |
+
grid_img.paste(images[3], (width, height))
|
30 |
+
|
31 |
+
return grid_img
|
32 |
+
|
33 |
+
|
34 |
+
demo = gr.Interface(fn=run, inputs="image", outputs="image")
|
35 |
+
demo.launch()
|