Spaces:
Running
Running
Commit
·
e287c20
1
Parent(s):
e0b5d9d
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,28 +19,15 @@ device = (
|
|
| 19 |
|
| 20 |
pipeline_name = 'WiNE-iNEFF/Minecraft-Skin-Diffusion-V2'
|
| 21 |
image_pipe = DDPMPipeline.from_pretrained(pipeline_name).to(device)
|
| 22 |
-
|
| 23 |
-
class Model:
|
| 24 |
-
def __init__(self, name):
|
| 25 |
-
self.name = name
|
| 26 |
-
model = [
|
| 27 |
-
Model("DDIMScheduler"),
|
| 28 |
-
Model("PNDMScheduler")]
|
| 29 |
-
current_model = model[0]
|
| 30 |
-
'''
|
| 31 |
def show_images_save(x):
|
| 32 |
grid = torchvision.utils.make_grid(x, nrow=4)
|
| 33 |
grid_im = grid.detach().cpu().permute(1, 2, 0).clip(0, 1) * 255
|
| 34 |
grid_im = Image.fromarray(np.array(grid_im).astype(np.uint8))
|
| 35 |
return grid_im
|
| 36 |
|
|
|
|
| 37 |
def generate():
|
| 38 |
-
'''
|
| 39 |
-
if schedul == "DDIMScheduler":
|
| 40 |
-
scheduler = DDIMScheduler.from_pretrained(pipeline_name)
|
| 41 |
-
else:
|
| 42 |
-
scheduler = PNDMScheduler.from_pretrained(pipeline_name)
|
| 43 |
-
'''
|
| 44 |
scheduler = DDIMScheduler.from_pretrained(pipeline_name)
|
| 45 |
scheduler.set_timesteps(num_inference_steps=20)
|
| 46 |
x = torch.randn(8, 4, 64, 64).to(device)
|
|
@@ -51,6 +38,7 @@ def generate():
|
|
| 51 |
x = scheduler.step(noise_pred, t, x).prev_sample
|
| 52 |
return show_images_save(x)
|
| 53 |
|
|
|
|
| 54 |
def crrop(file):
|
| 55 |
width, height = file.size
|
| 56 |
sav = []
|
|
@@ -60,47 +48,38 @@ def crrop(file):
|
|
| 60 |
sav.append(file.crop(box))
|
| 61 |
return sav
|
| 62 |
|
|
|
|
| 63 |
def ex():
|
| 64 |
t = time()
|
| 65 |
print(ctime(t))
|
| 66 |
return crrop(generate())
|
| 67 |
|
| 68 |
-
|
|
|
|
| 69 |
|
| 70 |
with demo:
|
| 71 |
gr.HTML(
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
)
|
| 83 |
with gr.Column():
|
| 84 |
-
'''
|
| 85 |
-
with gr.Row().style(equal_height=True):
|
| 86 |
-
model_name = gr.Dropdown(label="Base Scheduler", choices=[m.name for m in model], value=current_model.name)
|
| 87 |
-
#number = gr.Number(value="40", label="number of generation steps (Standard value 40, MAX 1000; The larger the number, the better the quality, but the longer it takes)", show_label=True)
|
| 88 |
-
'''
|
| 89 |
with gr.Row().style(equal_height=True):
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
'''inputs=[model_name]'''
|
| 94 |
gr.HTML(
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
</center>
|
| 101 |
-
</div>
|
| 102 |
-
</div>
|
| 103 |
-
"""
|
| 104 |
-
)
|
| 105 |
|
| 106 |
demo.launch()
|
|
|
|
| 19 |
|
| 20 |
pipeline_name = 'WiNE-iNEFF/Minecraft-Skin-Diffusion-V2'
|
| 21 |
image_pipe = DDPMPipeline.from_pretrained(pipeline_name).to(device)
|
| 22 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
def show_images_save(x):
|
| 24 |
grid = torchvision.utils.make_grid(x, nrow=4)
|
| 25 |
grid_im = grid.detach().cpu().permute(1, 2, 0).clip(0, 1) * 255
|
| 26 |
grid_im = Image.fromarray(np.array(grid_im).astype(np.uint8))
|
| 27 |
return grid_im
|
| 28 |
|
| 29 |
+
|
| 30 |
def generate():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
scheduler = DDIMScheduler.from_pretrained(pipeline_name)
|
| 32 |
scheduler.set_timesteps(num_inference_steps=20)
|
| 33 |
x = torch.randn(8, 4, 64, 64).to(device)
|
|
|
|
| 38 |
x = scheduler.step(noise_pred, t, x).prev_sample
|
| 39 |
return show_images_save(x)
|
| 40 |
|
| 41 |
+
|
| 42 |
def crrop(file):
|
| 43 |
width, height = file.size
|
| 44 |
sav = []
|
|
|
|
| 48 |
sav.append(file.crop(box))
|
| 49 |
return sav
|
| 50 |
|
| 51 |
+
|
| 52 |
def ex():
|
| 53 |
t = time()
|
| 54 |
print(ctime(t))
|
| 55 |
return crrop(generate())
|
| 56 |
|
| 57 |
+
|
| 58 |
+
demo = gr.Blocks(css=".container {max-width: 730px; margin: auto;} .min-h-\[15rem\]{min-height: 5rem !important;}")
|
| 59 |
|
| 60 |
with demo:
|
| 61 |
gr.HTML(
|
| 62 |
+
"""
|
| 63 |
+
<div style="text-align: center; margin: 0 auto;">
|
| 64 |
+
<div style="display: inline-flex;align-items: center;gap: 0.8rem;font-size: 1.75rem;">
|
| 65 |
+
<img src='https://huggingface.co/spaces/WiNE-iNEFF/MinecraftSkin-Diffusion/resolve/main/MSD_7.png'>
|
| 66 |
+
</div>
|
| 67 |
+
<p style="margin-bottom: 10px; font-size: 94%; line-height: 23px;">
|
| 68 |
+
Gradio demo for Minecraft Skin Diffusion. This is simple Unconditional Diffusion Model that will help you generate skins for game Minecraft.
|
| 69 |
+
</p>
|
| 70 |
+
</div>
|
| 71 |
+
"""
|
| 72 |
)
|
| 73 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
with gr.Row().style(equal_height=True):
|
| 75 |
+
gall = gr.Gallery(elem_id='gallery')
|
| 76 |
+
greet_btn = gr.Button("Generate")
|
| 77 |
+
greet_btn.click(fn=ex, outputs=gall)
|
|
|
|
| 78 |
gr.HTML(
|
| 79 |
+
"""
|
| 80 |
+
<div class="footer">
|
| 81 |
+
<div style='text-align: center;'>Minecraft Skin Diffusion by <a href='https://twitter.com/wine_ineff' target='_blank'>Artsem Holub (WiNE-iNEFF)</a></div>
|
| 82 |
+
</div>
|
| 83 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
demo.launch()
|