Spaces:
Running
Running
Commit
·
7d341ca
1
Parent(s):
5d94a88
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import numpy as np
|
|
| 6 |
from time import time, ctime
|
| 7 |
from PIL import Image, ImageColor
|
| 8 |
from diffusers import DDPMPipeline
|
| 9 |
-
from diffusers import DDIMScheduler
|
| 10 |
from tqdm import tqdm
|
| 11 |
|
| 12 |
device = (
|
|
@@ -19,7 +19,7 @@ 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
|
|
@@ -29,7 +29,7 @@ model = [
|
|
| 29 |
Model("PNDMScheduler")]
|
| 30 |
|
| 31 |
current_model = model[0]
|
| 32 |
-
|
| 33 |
def show_images_save(x):
|
| 34 |
"""Given a batch of images x, make a grid and convert to PIL"""
|
| 35 |
#x = x * 0.5 + 0.5 # Map from (-1, 1) back to (0, 1)
|
|
@@ -38,11 +38,14 @@ def show_images_save(x):
|
|
| 38 |
grid_im = Image.fromarray(np.array(grid_im).astype(np.uint8))
|
| 39 |
return grid_im
|
| 40 |
|
| 41 |
-
def generate(
|
|
|
|
| 42 |
if schedul == "DDIMScheduler":
|
| 43 |
scheduler = DDIMScheduler.from_pretrained(pipeline_name)
|
| 44 |
else:
|
| 45 |
scheduler = PNDMScheduler.from_pretrained(pipeline_name)
|
|
|
|
|
|
|
| 46 |
scheduler.set_timesteps(num_inference_steps=20)
|
| 47 |
x = torch.randn(1, 4, 64, 64).to(device)
|
| 48 |
# Minimal sampling loop
|
|
@@ -54,10 +57,10 @@ def generate(schedul):
|
|
| 54 |
# View the results
|
| 55 |
return show_images_save(x)
|
| 56 |
|
| 57 |
-
def ex(
|
| 58 |
t = time()
|
| 59 |
print(ctime(t))
|
| 60 |
-
return generate(
|
| 61 |
|
| 62 |
demo = gr.Blocks(css="#img_size {max-height: 128px} .container {max-width: 730px; margin: auto;} .min-h-\[15rem\]{min-height: 5rem !important;}")
|
| 63 |
|
|
@@ -75,14 +78,16 @@ with demo:
|
|
| 75 |
"""
|
| 76 |
)
|
| 77 |
with gr.Column():
|
|
|
|
| 78 |
with gr.Row().style(equal_height=True):
|
| 79 |
model_name = gr.Dropdown(label="Base Scheduler", choices=[m.name for m in model], value=current_model.name)
|
| 80 |
#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)
|
|
|
|
| 81 |
with gr.Row().style(equal_height=True):
|
| 82 |
out = gr.Image(shape=(64,64), image_mode='RGBA', type='pil', elem_id='img_size')
|
| 83 |
out2 = gr.Image(shape=(64,64), image_mode='RGBA', type='pil', elem_id='img_size')
|
| 84 |
greet_btn = gr.Button("Generate")
|
| 85 |
-
greet_btn.click(fn=ex, inputs=[model_name], outputs=[out, out2])
|
| 86 |
gr.HTML(
|
| 87 |
"""
|
| 88 |
<div class="footer">
|
|
|
|
| 6 |
from time import time, ctime
|
| 7 |
from PIL import Image, ImageColor
|
| 8 |
from diffusers import DDPMPipeline
|
| 9 |
+
from diffusers import DDIMScheduler
|
| 10 |
from tqdm import tqdm
|
| 11 |
|
| 12 |
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
|
|
|
|
| 29 |
Model("PNDMScheduler")]
|
| 30 |
|
| 31 |
current_model = model[0]
|
| 32 |
+
'''
|
| 33 |
def show_images_save(x):
|
| 34 |
"""Given a batch of images x, make a grid and convert to PIL"""
|
| 35 |
#x = x * 0.5 + 0.5 # Map from (-1, 1) back to (0, 1)
|
|
|
|
| 38 |
grid_im = Image.fromarray(np.array(grid_im).astype(np.uint8))
|
| 39 |
return grid_im
|
| 40 |
|
| 41 |
+
def generate():
|
| 42 |
+
'''
|
| 43 |
if schedul == "DDIMScheduler":
|
| 44 |
scheduler = DDIMScheduler.from_pretrained(pipeline_name)
|
| 45 |
else:
|
| 46 |
scheduler = PNDMScheduler.from_pretrained(pipeline_name)
|
| 47 |
+
'''
|
| 48 |
+
scheduler = DDIMScheduler.from_pretrained(pipeline_name)
|
| 49 |
scheduler.set_timesteps(num_inference_steps=20)
|
| 50 |
x = torch.randn(1, 4, 64, 64).to(device)
|
| 51 |
# Minimal sampling loop
|
|
|
|
| 57 |
# View the results
|
| 58 |
return show_images_save(x)
|
| 59 |
|
| 60 |
+
def ex():
|
| 61 |
t = time()
|
| 62 |
print(ctime(t))
|
| 63 |
+
return generate(), generate()
|
| 64 |
|
| 65 |
demo = gr.Blocks(css="#img_size {max-height: 128px} .container {max-width: 730px; margin: auto;} .min-h-\[15rem\]{min-height: 5rem !important;}")
|
| 66 |
|
|
|
|
| 78 |
"""
|
| 79 |
)
|
| 80 |
with gr.Column():
|
| 81 |
+
'''
|
| 82 |
with gr.Row().style(equal_height=True):
|
| 83 |
model_name = gr.Dropdown(label="Base Scheduler", choices=[m.name for m in model], value=current_model.name)
|
| 84 |
#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)
|
| 85 |
+
'''
|
| 86 |
with gr.Row().style(equal_height=True):
|
| 87 |
out = gr.Image(shape=(64,64), image_mode='RGBA', type='pil', elem_id='img_size')
|
| 88 |
out2 = gr.Image(shape=(64,64), image_mode='RGBA', type='pil', elem_id='img_size')
|
| 89 |
greet_btn = gr.Button("Generate")
|
| 90 |
+
greet_btn.click(fn=ex, '''inputs=[model_name]''', outputs=[out, out2])
|
| 91 |
gr.HTML(
|
| 92 |
"""
|
| 93 |
<div class="footer">
|