Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from PIL import Image
|
|
5 |
from gradio_client import Client
|
6 |
import numpy as np
|
7 |
|
8 |
-
DESCRIPTION = "# SDXL
|
9 |
|
10 |
MAX_SEED = np.iinfo(np.int32).max
|
11 |
MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "1024"))
|
@@ -48,7 +48,7 @@ def generate(
|
|
48 |
):
|
49 |
client = Client("hysts/SDXL")
|
50 |
result = client.predict(
|
51 |
-
prompt="((
|
52 |
negative_prompt=negative_prompt,
|
53 |
prompt_2=prompt_2,
|
54 |
negative_prompt_2=negative_prompt_2,
|
@@ -68,20 +68,34 @@ def generate(
|
|
68 |
image = pixelate(result, pixel_size)
|
69 |
return image
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
examples = [
|
73 |
-
"
|
74 |
-
"An astronaut riding a green horse",
|
75 |
-
"City of Tokyo at night",
|
76 |
]
|
77 |
|
78 |
with gr.Blocks(css="style.css") as demo:
|
79 |
gr.Markdown(DESCRIPTION)
|
80 |
-
gr.DuplicateButton(
|
81 |
-
value="Duplicate Space for private use",
|
82 |
-
elem_id="duplicate-button",
|
83 |
-
visible=os.getenv("SHOW_DUPLICATE_BUTTON") == "1",
|
84 |
-
)
|
85 |
with gr.Group():
|
86 |
with gr.Row():
|
87 |
prompt = gr.Text(
|
@@ -92,7 +106,8 @@ with gr.Blocks(css="style.css") as demo:
|
|
92 |
container=False,
|
93 |
)
|
94 |
run_button = gr.Button("Run", scale=0)
|
95 |
-
|
|
|
96 |
with gr.Accordion("Advanced options", open=False):
|
97 |
with gr.Row():
|
98 |
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
|
@@ -103,7 +118,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
103 |
max_lines=1,
|
104 |
placeholder="Enter a negative prompt",
|
105 |
visible=True,
|
106 |
-
value="
|
107 |
)
|
108 |
prompt_2 = gr.Text(
|
109 |
label="Prompt 2",
|
@@ -183,7 +198,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
183 |
gr.Examples(
|
184 |
examples=examples,
|
185 |
inputs=prompt,
|
186 |
-
outputs=
|
187 |
fn=generate,
|
188 |
)
|
189 |
|
@@ -249,8 +264,13 @@ with gr.Blocks(css="style.css") as demo:
|
|
249 |
apply_refiner,
|
250 |
pixel_size
|
251 |
],
|
252 |
-
outputs=
|
253 |
-
api_name="
|
|
|
|
|
|
|
|
|
|
|
254 |
)
|
255 |
|
256 |
if __name__ == "__main__":
|
|
|
5 |
from gradio_client import Client
|
6 |
import numpy as np
|
7 |
|
8 |
+
DESCRIPTION = "# SDXL Texture"
|
9 |
|
10 |
MAX_SEED = np.iinfo(np.int32).max
|
11 |
MAX_IMAGE_SIZE = int(os.getenv("MAX_IMAGE_SIZE", "1024"))
|
|
|
48 |
):
|
49 |
client = Client("hysts/SDXL")
|
50 |
result = client.predict(
|
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,
|
54 |
negative_prompt_2=negative_prompt_2,
|
|
|
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",
|
|
|
|
|
95 |
]
|
96 |
|
97 |
with gr.Blocks(css="style.css") as demo:
|
98 |
gr.Markdown(DESCRIPTION)
|
|
|
|
|
|
|
|
|
|
|
99 |
with gr.Group():
|
100 |
with gr.Row():
|
101 |
prompt = gr.Text(
|
|
|
106 |
container=False,
|
107 |
)
|
108 |
run_button = gr.Button("Run", scale=0)
|
109 |
+
result_image = gr.Image(label="Texture", show_label=True)
|
110 |
+
result_normal = gr.Image(label="Normal", show_label=True)
|
111 |
with gr.Accordion("Advanced options", open=False):
|
112 |
with gr.Row():
|
113 |
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
|
|
|
118 |
max_lines=1,
|
119 |
placeholder="Enter a negative prompt",
|
120 |
visible=True,
|
121 |
+
value="anatomy, text, logos, faces, animals, recognizable objects, cube, sphere, human, hands",
|
122 |
)
|
123 |
prompt_2 = gr.Text(
|
124 |
label="Prompt 2",
|
|
|
198 |
gr.Examples(
|
199 |
examples=examples,
|
200 |
inputs=prompt,
|
201 |
+
outputs=result_image,
|
202 |
fn=generate,
|
203 |
)
|
204 |
|
|
|
264 |
apply_refiner,
|
265 |
pixel_size
|
266 |
],
|
267 |
+
outputs=result_image,
|
268 |
+
api_name="generate",
|
269 |
+
).then(
|
270 |
+
fn=compose,
|
271 |
+
inputs=[result_image],
|
272 |
+
outputs=[result_normal],
|
273 |
+
api_name="compose",
|
274 |
)
|
275 |
|
276 |
if __name__ == "__main__":
|