Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import numpy as np
|
|
3 |
import random
|
4 |
from diffusers import DiffusionPipeline
|
5 |
import torch
|
|
|
6 |
|
7 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
8 |
|
@@ -55,169 +56,70 @@ examples = [
|
|
55 |
["red", "sweat shirt", "geometric design", "plain"],
|
56 |
]
|
57 |
|
58 |
-
css = """
|
59 |
-
#col-container {
|
60 |
-
margin: 0 auto;
|
61 |
-
max-width: 520px;
|
62 |
-
}
|
63 |
-
"""
|
64 |
-
|
65 |
if torch.cuda.is_available():
|
66 |
power_device = "GPU"
|
67 |
else:
|
68 |
power_device = "CPU"
|
69 |
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
-
with gr.Column(
|
73 |
gr.Markdown(f"""
|
74 |
-
#
|
75 |
Currently running on {power_device}.
|
76 |
""")
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
interactive=False,
|
85 |
-
container=False,
|
86 |
-
elem_id="prompt_part1",
|
87 |
-
visible=False,
|
88 |
-
)
|
89 |
-
|
90 |
-
prompt_part2 = gr.Textbox(
|
91 |
-
label="color",
|
92 |
-
show_label=False,
|
93 |
-
max_lines=1,
|
94 |
-
placeholder="color (e.g., color category)",
|
95 |
-
container=False,
|
96 |
-
)
|
97 |
-
|
98 |
-
prompt_part3 = gr.Textbox(
|
99 |
-
label="dress_type",
|
100 |
-
show_label=False,
|
101 |
-
max_lines=1,
|
102 |
-
placeholder="dress_type (e.g., t-shirt, sweatshirt, shirt, hoodie)",
|
103 |
-
container=False,
|
104 |
-
)
|
105 |
-
|
106 |
-
prompt_part4_front = gr.Textbox(
|
107 |
-
label="front design",
|
108 |
-
show_label=False,
|
109 |
-
max_lines=1,
|
110 |
-
placeholder="front design",
|
111 |
-
container=False,
|
112 |
-
)
|
113 |
-
|
114 |
-
prompt_part4_back = gr.Textbox(
|
115 |
-
label="back design",
|
116 |
-
show_label=False,
|
117 |
-
max_lines=1,
|
118 |
-
placeholder="back design",
|
119 |
-
container=False,
|
120 |
-
)
|
121 |
-
|
122 |
-
prompt_part5 = gr.Textbox(
|
123 |
-
value="hanging on the plain wall",
|
124 |
-
label="Prompt Part 5",
|
125 |
-
show_label=False,
|
126 |
-
interactive=False,
|
127 |
-
container=False,
|
128 |
-
elem_id="prompt_part5",
|
129 |
-
visible=False,
|
130 |
-
)
|
131 |
-
|
132 |
-
run_button = gr.Button("Run", scale=0)
|
133 |
|
134 |
-
|
135 |
-
back_result = gr.Image(label="Back View Result", show_label=False)
|
136 |
-
|
137 |
-
with gr.Row():
|
138 |
-
edit_button = gr.Button("Edit Front Design")
|
139 |
-
edit_front_design = gr.Image(interactive=True, tool="editor")
|
140 |
|
141 |
-
|
142 |
-
|
143 |
-
edit_back_design = gr.Image(interactive=True, tool="editor")
|
144 |
|
145 |
-
|
146 |
-
|
147 |
-
negative_prompt = gr.Textbox(
|
148 |
-
label="Negative prompt",
|
149 |
-
max_lines=1,
|
150 |
-
placeholder="Enter a negative prompt",
|
151 |
-
visible=False,
|
152 |
-
)
|
153 |
-
|
154 |
-
seed = gr.Slider(
|
155 |
-
label="Seed",
|
156 |
-
minimum=0,
|
157 |
-
maximum=MAX_SEED,
|
158 |
-
step=1,
|
159 |
-
value=0,
|
160 |
-
)
|
161 |
-
|
162 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
163 |
-
|
164 |
-
with gr.Row():
|
165 |
-
|
166 |
-
width = gr.Slider(
|
167 |
-
label="Width",
|
168 |
-
minimum=256,
|
169 |
-
maximum=MAX_IMAGE_SIZE,
|
170 |
-
step=32,
|
171 |
-
value=512,
|
172 |
-
)
|
173 |
-
|
174 |
-
height = gr.Slider(
|
175 |
-
label="Height",
|
176 |
-
minimum=256,
|
177 |
-
maximum=MAX_IMAGE_SIZE,
|
178 |
-
step=32,
|
179 |
-
value=512,
|
180 |
-
)
|
181 |
-
|
182 |
-
with gr.Row():
|
183 |
-
|
184 |
-
guidance_scale = gr.Slider(
|
185 |
-
label="Guidance scale",
|
186 |
-
minimum=0.0,
|
187 |
-
maximum=10.0,
|
188 |
-
step=0.1,
|
189 |
-
value=0.0,
|
190 |
-
)
|
191 |
-
|
192 |
-
num_inference_steps = gr.Slider(
|
193 |
-
label="Number of inference steps",
|
194 |
-
minimum=1,
|
195 |
-
maximum=12,
|
196 |
-
step=1,
|
197 |
-
value=2,
|
198 |
-
)
|
199 |
-
|
200 |
-
gr.Examples(
|
201 |
-
examples=examples,
|
202 |
-
inputs=[prompt_part2, prompt_part3, prompt_part4_front, prompt_part4_back]
|
203 |
-
)
|
204 |
|
205 |
run_button.click(
|
206 |
fn=infer,
|
207 |
-
inputs=[prompt_part1, prompt_part2, prompt_part3, prompt_part4_front, prompt_part4_back, prompt_part5
|
208 |
outputs=[front_result, back_result]
|
209 |
)
|
210 |
|
211 |
-
|
212 |
-
fn=lambda x: x,
|
213 |
-
inputs=[front_result],
|
214 |
-
outputs=[edit_front_design],
|
215 |
-
)
|
216 |
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
|
|
|
|
|
|
|
|
|
|
221 |
)
|
222 |
|
223 |
demo.queue().launch()
|
|
|
3 |
import random
|
4 |
from diffusers import DiffusionPipeline
|
5 |
import torch
|
6 |
+
from PIL import Image, ImageOps
|
7 |
|
8 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
9 |
|
|
|
56 |
["red", "sweat shirt", "geometric design", "plain"],
|
57 |
]
|
58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
if torch.cuda.is_available():
|
60 |
power_device = "GPU"
|
61 |
else:
|
62 |
power_device = "CPU"
|
63 |
|
64 |
+
def edit_image(img_data, operation, *args):
|
65 |
+
image = Image.open(img_data)
|
66 |
+
|
67 |
+
if operation == "rotate":
|
68 |
+
angle = args[0]
|
69 |
+
image = image.rotate(angle, expand=True)
|
70 |
+
elif operation == "crop":
|
71 |
+
left, top, right, bottom = args
|
72 |
+
image = image.crop((left, top, right, bottom))
|
73 |
+
elif operation == "resize":
|
74 |
+
width, height = args
|
75 |
+
image = image.resize((width, height))
|
76 |
+
elif operation == "flip":
|
77 |
+
if args[0] == "horizontal":
|
78 |
+
image = ImageOps.mirror(image)
|
79 |
+
else:
|
80 |
+
image = ImageOps.flip(image)
|
81 |
+
|
82 |
+
return image
|
83 |
+
|
84 |
+
with gr.Blocks() as demo:
|
85 |
|
86 |
+
with gr.Column():
|
87 |
gr.Markdown(f"""
|
88 |
+
# GenZ Couture
|
89 |
Currently running on {power_device}.
|
90 |
""")
|
91 |
|
92 |
+
prompt_part1 = gr.Textbox(value="a single", label="Prompt Part 1")
|
93 |
+
prompt_part2 = gr.Textbox(label="color", placeholder="color (e.g., red, blue)")
|
94 |
+
prompt_part3 = gr.Textbox(label="dress_type", placeholder="dress_type (e.g., t-shirt, hoodie)")
|
95 |
+
prompt_part4_front = gr.Textbox(label="front design", placeholder="front design")
|
96 |
+
prompt_part4_back = gr.Textbox(label="back design", placeholder="back design")
|
97 |
+
prompt_part5 = gr.Textbox(value="hanging on the plain wall", label="Prompt Part 5")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
run_button = gr.Button("Run", label="Generate Designs")
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
+
front_result = gr.Image(label="Front View Result", type="file", interactive=True)
|
102 |
+
back_result = gr.Image(label="Back View Result", type="file", interactive=True)
|
|
|
103 |
|
104 |
+
gr.Examples(examples=examples, inputs=[prompt_part2, prompt_part3, prompt_part4_front, prompt_part4_back])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
run_button.click(
|
107 |
fn=infer,
|
108 |
+
inputs=[prompt_part1, prompt_part2, prompt_part3, prompt_part4_front, prompt_part4_back, prompt_part5],
|
109 |
outputs=[front_result, back_result]
|
110 |
)
|
111 |
|
112 |
+
gr.Markdown("## Creative Touch")
|
|
|
|
|
|
|
|
|
113 |
|
114 |
+
edit_operation = gr.Dropdown(choices=["rotate", "crop", "resize", "flip"], label="Edit Operation")
|
115 |
+
edit_args = gr.Textbox(label="Edit Arguments (comma-separated)", placeholder="For rotate: angle, For crop: left,top,right,bottom, For resize: width,height, For flip: horizontal/vertical")
|
116 |
+
|
117 |
+
edit_button = gr.Button("Edit Front Design")
|
118 |
+
|
119 |
+
edit_button.click(
|
120 |
+
fn=lambda img_data, operation, args: edit_image(img_data, operation, *map(int, args.split(','))),
|
121 |
+
inputs=[front_result, edit_operation, edit_args],
|
122 |
+
outputs=[front_result]
|
123 |
)
|
124 |
|
125 |
demo.queue().launch()
|