Spaces:
Running
on
Zero
Running
on
Zero
Update app and add examples
Browse files- app.py +65 -16
- samples/bricks.jpg +0 -0
- samples/metal.jpg +0 -0
app.py
CHANGED
@@ -1,57 +1,106 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import spaces
|
3 |
-
import torch
|
4 |
-
import diffusers
|
5 |
|
6 |
from generation import generate_material
|
7 |
|
8 |
|
9 |
@spaces.GPU
|
10 |
def generate(prompts, seed, resolution, refinement):
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
|
15 |
-
def interface_function(
|
|
|
|
|
16 |
if prompt_type == "Text":
|
17 |
return generate(text_prompt, seed, resolution, refinement)
|
18 |
elif prompt_type == "Image":
|
19 |
return generate(image_prompt, seed, resolution, refinement)
|
20 |
|
|
|
21 |
def update_visibility(prompt_type):
|
22 |
if prompt_type == "Text":
|
23 |
return gr.update(visible=True), gr.update(visible=False)
|
24 |
elif prompt_type == "Image":
|
25 |
return gr.update(visible=False), gr.update(visible=True)
|
26 |
|
|
|
27 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
with gr.Row():
|
29 |
with gr.Column():
|
30 |
-
prompt_type = gr.Radio(
|
31 |
-
|
|
|
|
|
|
|
|
|
32 |
image_prompt = gr.Image(type="pil", label="Image Prompt", visible=False)
|
33 |
-
|
34 |
with gr.Column():
|
35 |
seed = gr.Number(value=-1, label="Seed (-1 for random)")
|
36 |
-
resolution = gr.Dropdown(
|
|
|
|
|
|
|
|
|
|
|
37 |
refinement = gr.Checkbox(label="Refinement", interactive=False)
|
38 |
generate_button = gr.Button("Generate")
|
39 |
|
40 |
-
prompt_type.change(
|
41 |
-
|
|
|
|
|
42 |
with gr.Row():
|
43 |
output_basecolor = gr.Image(label="Base Color", format="png", image_mode="RGB")
|
44 |
output_normal = gr.Image(label="Normal Map", format="png", image_mode="RGB")
|
45 |
output_height = gr.Image(label="Height Map", format="png", image_mode="L")
|
46 |
output_metallic = gr.Image(label="Metallic Map", format="png", image_mode="L")
|
47 |
output_roughness = gr.Image(label="Roughness Map", format="png", image_mode="L")
|
48 |
-
|
49 |
generate_button.click(
|
50 |
-
fn=interface_function,
|
51 |
-
inputs=[prompt_type, text_prompt, image_prompt, seed, resolution, refinement],
|
52 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
)
|
54 |
|
|
|
55 |
if __name__ == "__main__":
|
56 |
demo.launch()
|
57 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
|
3 |
import spaces
|
|
|
|
|
4 |
|
5 |
from generation import generate_material
|
6 |
|
7 |
|
8 |
@spaces.GPU
|
9 |
def generate(prompts, seed, resolution, refinement):
|
10 |
+
image = generate_material(
|
11 |
+
prompts, seed=seed, resolution=int(resolution), refinement=refinement
|
12 |
+
)
|
13 |
+
return image.basecolor, image.normal, image.height, image.metallic, image.roughness
|
14 |
+
pass
|
15 |
|
16 |
|
17 |
+
def interface_function(
|
18 |
+
prompt_type, text_prompt, image_prompt, seed, resolution, refinement
|
19 |
+
):
|
20 |
if prompt_type == "Text":
|
21 |
return generate(text_prompt, seed, resolution, refinement)
|
22 |
elif prompt_type == "Image":
|
23 |
return generate(image_prompt, seed, resolution, refinement)
|
24 |
|
25 |
+
|
26 |
def update_visibility(prompt_type):
|
27 |
if prompt_type == "Text":
|
28 |
return gr.update(visible=True), gr.update(visible=False)
|
29 |
elif prompt_type == "Image":
|
30 |
return gr.update(visible=False), gr.update(visible=True)
|
31 |
|
32 |
+
|
33 |
with gr.Blocks() as demo:
|
34 |
+
title = """
|
35 |
+
<center>
|
36 |
+
|
37 |
+
<h1> StableMaterials </h1>
|
38 |
+
<b> Try the <a href="https://huggingface.co/gvecchio/StableMaterials">StableMaterials</a> model. Start generating using a text o image prompt, or simply try one of the examples below. </b>
|
39 |
+
<br>
|
40 |
+
<b> NB: </b> The demo currently uses only the base model and does not include the refinement step. The refiner model will be released in a future update.
|
41 |
+
|
42 |
+
</center>
|
43 |
+
"""
|
44 |
+
gr.HTML(title)
|
45 |
+
|
46 |
with gr.Row():
|
47 |
with gr.Column():
|
48 |
+
prompt_type = gr.Radio(
|
49 |
+
choices=["Text", "Image"], label="Prompt Type", value="Text"
|
50 |
+
)
|
51 |
+
text_prompt = gr.Textbox(
|
52 |
+
label="Text Prompt", visible=True, lines=3, placeholder="A brick wall"
|
53 |
+
)
|
54 |
image_prompt = gr.Image(type="pil", label="Image Prompt", visible=False)
|
55 |
+
|
56 |
with gr.Column():
|
57 |
seed = gr.Number(value=-1, label="Seed (-1 for random)")
|
58 |
+
resolution = gr.Dropdown(
|
59 |
+
["512", "1024", "2048"],
|
60 |
+
value="512",
|
61 |
+
label="Resolution",
|
62 |
+
interactive=False,
|
63 |
+
)
|
64 |
refinement = gr.Checkbox(label="Refinement", interactive=False)
|
65 |
generate_button = gr.Button("Generate")
|
66 |
|
67 |
+
prompt_type.change(
|
68 |
+
fn=update_visibility, inputs=prompt_type, outputs=[text_prompt, image_prompt]
|
69 |
+
)
|
70 |
+
|
71 |
with gr.Row():
|
72 |
output_basecolor = gr.Image(label="Base Color", format="png", image_mode="RGB")
|
73 |
output_normal = gr.Image(label="Normal Map", format="png", image_mode="RGB")
|
74 |
output_height = gr.Image(label="Height Map", format="png", image_mode="L")
|
75 |
output_metallic = gr.Image(label="Metallic Map", format="png", image_mode="L")
|
76 |
output_roughness = gr.Image(label="Roughness Map", format="png", image_mode="L")
|
77 |
+
|
78 |
generate_button.click(
|
79 |
+
fn=interface_function,
|
80 |
+
inputs=[prompt_type, text_prompt, image_prompt, seed, resolution, refinement],
|
81 |
+
outputs=[
|
82 |
+
output_basecolor,
|
83 |
+
output_normal,
|
84 |
+
output_height,
|
85 |
+
output_metallic,
|
86 |
+
output_roughness,
|
87 |
+
],
|
88 |
+
)
|
89 |
+
|
90 |
+
gr.Markdown("### Examples")
|
91 |
+
gr.Examples(
|
92 |
+
examples=[
|
93 |
+
["Text", "A brick wall", None],
|
94 |
+
["Text", "A wooden floor", None],
|
95 |
+
["Image", None, "./samples/bricks.jpg"],
|
96 |
+
["Image", None, "./samples/metal.jpg"],
|
97 |
+
],
|
98 |
+
inputs=[prompt_type, text_prompt, image_prompt],
|
99 |
+
)
|
100 |
+
gr.Markdown(
|
101 |
+
"Try the examples above to see how the Material Generator works. Adjust the parameters and click 'Generate' to create new material maps."
|
102 |
)
|
103 |
|
104 |
+
|
105 |
if __name__ == "__main__":
|
106 |
demo.launch()
|
|
samples/bricks.jpg
ADDED
samples/metal.jpg
ADDED