Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -16,19 +16,25 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
|
16 |
seed = random.randint(0, MAX_SEED)
|
17 |
return seed
|
18 |
|
19 |
-
def
|
20 |
-
image
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
)
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
def
|
32 |
prompt: str,
|
33 |
negative_prompt: str = "",
|
34 |
prompt_2: str = "",
|
@@ -47,7 +53,7 @@ def generate(
|
|
47 |
pixel_size: int = 16
|
48 |
):
|
49 |
client = Client("hysts/SDXL")
|
50 |
-
|
51 |
prompt="((Seamless texture)), versatile pattern, high resolution, detailed design, subtle patterns, non-repetitive, smooth edges, square, "+prompt,
|
52 |
negative_prompt=negative_prompt,
|
53 |
prompt_2=prompt_2,
|
@@ -65,30 +71,8 @@ def generate(
|
|
65 |
apply_refiner=apply_refiner,
|
66 |
api_name="/run",
|
67 |
)
|
68 |
-
image = pixelate(result, pixel_size)
|
69 |
-
return image
|
70 |
-
|
71 |
-
def generate_normal_map(image):
|
72 |
-
# Convert image to grayscale
|
73 |
-
grayscale = image.convert("L")
|
74 |
-
grayscale_np = np.array(grayscale)
|
75 |
-
|
76 |
-
# Compute gradients
|
77 |
-
grad_x, grad_y = np.gradient(grayscale_np.astype(float))
|
78 |
-
|
79 |
-
# Normalize gradients
|
80 |
-
grad_x = (grad_x - grad_x.min()) / (grad_x.max() - grad_x.min())
|
81 |
-
grad_y = (grad_y - grad_y.min()) / (grad_y.max() - grad_y.min())
|
82 |
-
|
83 |
-
# Create normal map
|
84 |
-
normal_map = np.dstack((grad_x, grad_y, np.ones_like(grad_x)))
|
85 |
-
normal_map = (normal_map * 255).astype(np.uint8)
|
86 |
-
|
87 |
-
return Image.fromarray(normal_map)
|
88 |
-
|
89 |
-
def compose(image):
|
90 |
normal_map = generate_normal_map(image)
|
91 |
-
return normal_map
|
92 |
|
93 |
examples = [
|
94 |
"A texture of wooden planks, grey wood, high contrast",
|
@@ -198,8 +182,8 @@ with gr.Blocks(css="style.css") as demo:
|
|
198 |
gr.Examples(
|
199 |
examples=examples,
|
200 |
inputs=prompt,
|
201 |
-
outputs=result_image,
|
202 |
-
fn=
|
203 |
)
|
204 |
|
205 |
use_negative_prompt.change(
|
@@ -245,7 +229,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
245 |
queue=False,
|
246 |
api_name=False,
|
247 |
).then(
|
248 |
-
fn=
|
249 |
inputs=[
|
250 |
prompt,
|
251 |
negative_prompt,
|
@@ -264,13 +248,8 @@ with gr.Blocks(css="style.css") as demo:
|
|
264 |
apply_refiner,
|
265 |
pixel_size
|
266 |
],
|
267 |
-
outputs=result_image,
|
268 |
-
api_name="
|
269 |
-
).then(
|
270 |
-
fn=compose,
|
271 |
-
inputs=[result_image],
|
272 |
-
outputs=[result_normal],
|
273 |
-
api_name="compose",
|
274 |
)
|
275 |
|
276 |
if __name__ == "__main__":
|
|
|
16 |
seed = random.randint(0, MAX_SEED)
|
17 |
return seed
|
18 |
|
19 |
+
def generate_normal_map(image):
|
20 |
+
# Convert image to grayscale
|
21 |
+
grayscale = image.convert("L")
|
22 |
+
grayscale_np = np.array(grayscale)
|
23 |
+
|
24 |
+
# Compute gradients
|
25 |
+
grad_x, grad_y = np.gradient(grayscale_np.astype(float))
|
26 |
+
|
27 |
+
# Normalize gradients
|
28 |
+
grad_x = (grad_x - grad_x.min()) / (grad_x.max() - grad_x.min())
|
29 |
+
grad_y = (grad_y - grad_y.min()) / (grad_y.max() - grad_y.min())
|
30 |
+
|
31 |
+
# Create normal map
|
32 |
+
normal_map = np.dstack((grad_x, grad_y, np.ones_like(grad_x)))
|
33 |
+
normal_map = (normal_map * 255).astype(np.uint8)
|
34 |
+
|
35 |
+
return Image.fromarray(normal_map)
|
36 |
|
37 |
+
def generate_image(
|
38 |
prompt: str,
|
39 |
negative_prompt: str = "",
|
40 |
prompt_2: str = "",
|
|
|
53 |
pixel_size: int = 16
|
54 |
):
|
55 |
client = Client("hysts/SDXL")
|
56 |
+
image = client.predict(
|
57 |
prompt="((Seamless texture)), versatile pattern, high resolution, detailed design, subtle patterns, non-repetitive, smooth edges, square, "+prompt,
|
58 |
negative_prompt=negative_prompt,
|
59 |
prompt_2=prompt_2,
|
|
|
71 |
apply_refiner=apply_refiner,
|
72 |
api_name="/run",
|
73 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
normal_map = generate_normal_map(image)
|
75 |
+
return image, normal_map
|
76 |
|
77 |
examples = [
|
78 |
"A texture of wooden planks, grey wood, high contrast",
|
|
|
182 |
gr.Examples(
|
183 |
examples=examples,
|
184 |
inputs=prompt,
|
185 |
+
outputs=[result_image, result_normal],
|
186 |
+
fn=generate_image,
|
187 |
)
|
188 |
|
189 |
use_negative_prompt.change(
|
|
|
229 |
queue=False,
|
230 |
api_name=False,
|
231 |
).then(
|
232 |
+
fn=generate_image,
|
233 |
inputs=[
|
234 |
prompt,
|
235 |
negative_prompt,
|
|
|
248 |
apply_refiner,
|
249 |
pixel_size
|
250 |
],
|
251 |
+
outputs=[result_image, result_normal],
|
252 |
+
api_name="run",
|
|
|
|
|
|
|
|
|
|
|
253 |
)
|
254 |
|
255 |
if __name__ == "__main__":
|