Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
@@ -1,15 +1,70 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
-
|
4 |
import requests
|
5 |
from PIL import Image
|
6 |
from io import BytesIO
|
7 |
import time
|
8 |
|
9 |
-
# TODO: PNGinfo追加, 使用データの展開(コピーボタン)
|
10 |
MAX_SEED = np.iinfo(np.int32).max
|
11 |
MAX_IMAGE_SIZE = 1344
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
model_url = {
|
14 |
"ImageUltra": "https://api.stability.ai/v2beta/stable-image/generate/ultra",
|
15 |
"ImageCore": "https://api.stability.ai/v2beta/stable-image/generate/core",
|
@@ -29,6 +84,90 @@ service_url = {
|
|
29 |
}
|
30 |
|
31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
def bytes_to_image(image):
|
33 |
image = BytesIO(image)
|
34 |
image = Image.open(image).convert("RGB")
|
@@ -83,12 +222,15 @@ def generate(
|
|
83 |
"seed": seed,
|
84 |
"aspect_ratio": aspect,
|
85 |
}
|
|
|
|
|
|
|
86 |
if input_image is not None:
|
87 |
file["image"] = image_to_bytes(input_image)
|
88 |
if mask is not None:
|
89 |
file["mask"] = image_to_bytes(mask)
|
90 |
|
91 |
-
if mode == "Generate":
|
92 |
file["none"] = ""
|
93 |
if model == "Stable Image Ultra (8B + workflow)":
|
94 |
url = model_url["ImageUltra"]
|
@@ -104,44 +246,46 @@ def generate(
|
|
104 |
elif model == "Stable Diffusion 3 Large Turbo (8B Turbo)":
|
105 |
url = model_url["StableDiffusion3"]
|
106 |
data["model"] = "sd3-large-turbo"
|
107 |
-
|
108 |
else:
|
109 |
raise ValueError("Invalid model type")
|
110 |
|
111 |
-
elif mode == "Upscale":
|
112 |
-
if submode == "Conservative":
|
113 |
url = service_url["Conservative_Upscale"]
|
114 |
-
elif submode == "Creative":
|
115 |
url = service_url["Creative_Upscale"]
|
116 |
|
117 |
-
elif mode == "Edit":
|
118 |
-
if submode == "Erase":
|
119 |
url = service_url["Erase"]
|
120 |
-
elif submode == "Inpaint":
|
121 |
url = service_url["Inpaint"]
|
122 |
-
elif submode == "Outpaint":
|
123 |
url = service_url["Outpaint"]
|
124 |
data["left"] = op_left
|
125 |
data["right"] = op_right
|
126 |
data["up"] = op_up
|
127 |
data["down"] = op_down
|
128 |
-
elif submode == "
|
129 |
url = service_url["SR"]
|
130 |
data["search_prompt"] = search_prompt
|
131 |
-
elif submode == "
|
|
|
132 |
url = service_url["RMBG"]
|
133 |
|
134 |
-
elif mode == "Control":
|
135 |
data["control_strength"] = CNstrength
|
136 |
-
if submode == "Sketch":
|
137 |
url = service_url["Sketch"]
|
138 |
-
elif submode == "Structure":
|
139 |
url = service_url["Structure"]
|
140 |
-
|
141 |
response = send_request(url, api_key, file, data)
|
142 |
-
|
143 |
if response.status_code == 200:
|
144 |
-
if
|
|
|
|
|
|
|
145 |
generation_id = response.json().get("id")
|
146 |
if not generation_id:
|
147 |
raise Exception("No generation ID returned for creative upscale")
|
@@ -200,31 +344,41 @@ def update_mode(mode):
|
|
200 |
img_input_update = gr.update(visible=False)
|
201 |
mask_update = gr.update(visible=False)
|
202 |
|
203 |
-
if mode == "Generate":
|
204 |
submode_update = gr.update(visible=False)
|
205 |
-
elif mode == "Upscale":
|
206 |
submode_update = gr.update(
|
207 |
-
choices=[
|
|
|
|
|
|
|
|
|
|
|
208 |
)
|
209 |
img_input_update = gr.update(visible=True)
|
210 |
image_label_update = gr.update(visible=True)
|
211 |
-
elif mode == "Edit":
|
212 |
submode_update = gr.update(
|
213 |
choices=[
|
214 |
-
"Erase",
|
215 |
-
"Inpaint",
|
216 |
-
"Outpaint",
|
217 |
-
"
|
218 |
-
"
|
219 |
],
|
220 |
-
value="Erase",
|
221 |
visible=True,
|
222 |
)
|
223 |
img_input_update = gr.update(visible=True)
|
224 |
image_label_update = gr.update(visible=True)
|
225 |
-
elif mode == "Control":
|
226 |
submode_update = gr.update(
|
227 |
-
choices=[
|
|
|
|
|
|
|
|
|
|
|
228 |
)
|
229 |
img_input_update = gr.update(visible=True)
|
230 |
image_label_update = gr.update(visible=True)
|
@@ -238,17 +392,17 @@ def update_submode(submode):
|
|
238 |
cn = gr.update(visible=False)
|
239 |
search_prompt = gr.update(visible=False)
|
240 |
|
241 |
-
if submode in ["Erase", "Inpaint"]:
|
242 |
mask = gr.update(visible=True)
|
243 |
|
244 |
else:
|
245 |
-
if submode == "Outpaint":
|
246 |
outpaint = gr.update(visible=True)
|
247 |
|
248 |
-
elif submode
|
249 |
cn = gr.update(visible=True)
|
250 |
|
251 |
-
elif submode == "
|
252 |
search_prompt = gr.update(visible=True)
|
253 |
|
254 |
return mask, outpaint, cn, search_prompt
|
@@ -257,44 +411,50 @@ def update_submode(submode):
|
|
257 |
with gr.Blocks(css=css, theme="NoCrypt/miku") as demo:
|
258 |
with gr.Column(elem_id="col-container"):
|
259 |
gr.Markdown(
|
260 |
-
|
261 |
-
# Stability AI - Developer Platform WebUI
|
262 |
-
**Overview**
|
263 |
-
Stability AI’s Stable Image services offer a growing set of APIs for developers to build the best in class image applications.
|
264 |
-
|
265 |
-
- **Disrupting Content Creation:** Stability’s Image APIs are the foundation for applications disrupting publishing, media, gaming, marketing, advertising, design, and more.
|
266 |
-
- **For Developers:** Application developers can build advanced features for designers, photographers, content creators, and a variety of B2C customers.
|
267 |
-
- **Simple APIs:** Stability AI is focused on delivering simple APIs for easy integration into applications with a high bar for quality, alignment, speed, and safety.
|
268 |
-
|
269 |
-
Get Started Now: https://platform.stability.ai/docs/getting-started/stable-image
|
270 |
-
|
271 |
-
Contact: D̷ELL@Stability AI - Advocate (https://x.com/xqdior) / Author: umise (https://x.com/UiE029)
|
272 |
-
"""
|
273 |
)
|
|
|
|
|
|
|
|
|
274 |
|
275 |
with gr.Row():
|
276 |
api_key = gr.Text(
|
277 |
-
label="
|
278 |
type="password",
|
279 |
-
placeholder="
|
280 |
max_lines=1,
|
281 |
container=False,
|
282 |
)
|
283 |
|
284 |
with gr.Row():
|
285 |
model = gr.Dropdown(
|
286 |
-
label="
|
287 |
-
choices=[
|
288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
)
|
290 |
mode = gr.Dropdown(
|
291 |
-
label="
|
292 |
-
choices=[
|
293 |
-
|
|
|
|
|
|
|
|
|
|
|
294 |
)
|
295 |
|
296 |
submode = gr.Dropdown(
|
297 |
-
label="Submode"
|
|
|
|
|
|
|
298 |
)
|
299 |
|
300 |
with gr.Row():
|
@@ -303,7 +463,7 @@ with gr.Blocks(css=css, theme="NoCrypt/miku") as demo:
|
|
303 |
label="Prompt",
|
304 |
show_label=False,
|
305 |
max_lines=1,
|
306 |
-
placeholder="
|
307 |
container=False,
|
308 |
)
|
309 |
search_prompt = gr.Text(
|
@@ -311,14 +471,18 @@ with gr.Blocks(css=css, theme="NoCrypt/miku") as demo:
|
|
311 |
visible=False,
|
312 |
show_label=False,
|
313 |
max_lines=1,
|
314 |
-
placeholder="
|
315 |
)
|
316 |
-
|
317 |
-
|
318 |
-
|
|
|
|
|
319 |
with gr.Row():
|
320 |
with gr.Column():
|
321 |
-
image_label = gr.Markdown(
|
|
|
|
|
322 |
image = gr.Image(
|
323 |
type="pil",
|
324 |
label="img input",
|
@@ -342,30 +506,34 @@ with gr.Blocks(css=css, theme="NoCrypt/miku") as demo:
|
|
342 |
)
|
343 |
|
344 |
with gr.Row():
|
345 |
-
result = gr.Image(
|
|
|
|
|
346 |
|
347 |
-
with gr.Accordion("
|
348 |
negative_prompt = gr.Text(
|
349 |
-
label="
|
350 |
max_lines=1,
|
351 |
-
placeholder="
|
352 |
)
|
353 |
seed = gr.Slider(
|
354 |
-
label="
|
355 |
minimum=0,
|
356 |
maximum=MAX_SEED,
|
357 |
step=1,
|
358 |
value=0,
|
359 |
)
|
360 |
CN_strength = gr.Slider(
|
361 |
-
label="
|
362 |
minimum=0,
|
363 |
maximum=1,
|
364 |
step=0.01,
|
365 |
value=0.5,
|
366 |
visible=False,
|
367 |
)
|
368 |
-
randomize_seed = gr.Checkbox(
|
|
|
|
|
369 |
aspect = gr.Radio(
|
370 |
choices=[
|
371 |
"1:1",
|
@@ -378,7 +546,7 @@ with gr.Blocks(css=css, theme="NoCrypt/miku") as demo:
|
|
378 |
"9:16",
|
379 |
"9:21",
|
380 |
],
|
381 |
-
label="
|
382 |
value="1:1",
|
383 |
)
|
384 |
with gr.Row(visible=False) as style:
|
@@ -402,9 +570,9 @@ with gr.Blocks(css=css, theme="NoCrypt/miku") as demo:
|
|
402 |
"pixel-art",
|
403 |
"tile-texture",
|
404 |
],
|
405 |
-
label="
|
406 |
value="anime",
|
407 |
-
info="
|
408 |
)
|
409 |
with gr.Row(visible=False) as outpaint_scale:
|
410 |
paint = gr.Markdown(value="Outpain Scale")
|
@@ -421,18 +589,16 @@ with gr.Blocks(css=css, theme="NoCrypt/miku") as demo:
|
|
421 |
label="down", minimum=0, maximum=2000, step=4, value=200
|
422 |
)
|
423 |
|
424 |
-
gr.Examples(examples=examples, inputs=[prompt])
|
425 |
-
|
426 |
copy_filed = gr.TextArea(
|
427 |
value="",
|
428 |
label="Copy Field",
|
429 |
max_lines=1,
|
430 |
-
placeholder="
|
431 |
show_copy_button=True,
|
432 |
container=False,
|
433 |
)
|
434 |
gr.Markdown(
|
435 |
-
|
436 |
## License
|
437 |
This work is licensed under a
|
438 |
[Creative Commons Attribution-NonCommercial 4.0 International License][cc-by-nc].
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
|
|
3 |
import requests
|
4 |
from PIL import Image
|
5 |
from io import BytesIO
|
6 |
import time
|
7 |
|
|
|
8 |
MAX_SEED = np.iinfo(np.int32).max
|
9 |
MAX_IMAGE_SIZE = 1344
|
10 |
|
11 |
+
title = """
|
12 |
+
# Stability AI - Developer Platform WebUI
|
13 |
+
### UI for using the stable image api
|
14 |
+
|
15 |
+
API Key is required to use this service.
|
16 |
+
https://platform.stability.ai/account/keys
|
17 |
+
|
18 |
+
Contact: D̷ELL@Stability AI - Advocate (https://x.com/xqdior) / Author: umise (https://x.com/UiE029)
|
19 |
+
"""
|
20 |
+
|
21 |
+
title_jp = """
|
22 |
+
# Stability AI - Developer Platform WebUI
|
23 |
+
### このSpaceは、Stable Image APIを使用するためのWEB-UIです。
|
24 |
+
|
25 |
+
このサービスを利用するにはAPIキーが必要です。以下のリンクから取得してください。
|
26 |
+
https://platform.stability.ai/account/keys
|
27 |
+
|
28 |
+
お問い合わせ先: D̷ELL@Stability AI - Advocate (https://x.com/xqdior) / Author: umise (https://x.com/UiE029)
|
29 |
+
"""
|
30 |
+
|
31 |
+
overview = """
|
32 |
+
|
33 |
+
**Overview**
|
34 |
+
Stability AI’s Stable Image services offer a growing set of APIs for developers to build the best in class image applications.
|
35 |
+
|
36 |
+
- **Disrupting Content Creation:** Stability’s Image APIs are the foundation for applications disrupting publishing, media, gaming, marketing, advertising, design, and more.
|
37 |
+
- **For Developers:** Application developers can build advanced features for designers, photographers, content creators, and a variety of B2C customers.
|
38 |
+
- **Simple APIs:** Stability AI is focused on delivering simple APIs for easy integration into applications with a high bar for quality, alignment, speed, and safety.
|
39 |
+
|
40 |
+
Get Started Now: https://platform.stability.ai/docs/getting-started/stable-image
|
41 |
+
"""
|
42 |
+
|
43 |
+
overview_jp = """
|
44 |
+
各種モードについて
|
45 |
+
- テキストから生成:
|
46 |
+
プロンプトを基に画像を生成します。
|
47 |
+
- アップスケール:
|
48 |
+
- 通常のアップスケール:
|
49 |
+
できるだけ絵を変更せずにアップスケールします
|
50 |
+
- クリエィティブなアップスケール:
|
51 |
+
絵全体をいい感じになるようにアップスケールします
|
52 |
+
- 画像の編集:
|
53 |
+
- 消去:
|
54 |
+
マスクした要素を削除します
|
55 |
+
- インペイント:
|
56 |
+
マスクされた部分とプロンプトを基に再生成します
|
57 |
+
- アウトペイント:
|
58 |
+
指定した範囲分、画像を拡張します
|
59 |
+
- 検索と置き換え:
|
60 |
+
検索プロンプトに入力されたオブジェクトを探し、プロンプトをもとにオブジェクトを再生成します
|
61 |
+
- コントロール:
|
62 |
+
- 構図:
|
63 |
+
入力画像の構図を基に新しい画像を生成します
|
64 |
+
- スケッチ:
|
65 |
+
ラフなスケッチとプロンプトを基に生成します
|
66 |
+
"""
|
67 |
+
|
68 |
model_url = {
|
69 |
"ImageUltra": "https://api.stability.ai/v2beta/stable-image/generate/ultra",
|
70 |
"ImageCore": "https://api.stability.ai/v2beta/stable-image/generate/core",
|
|
|
84 |
}
|
85 |
|
86 |
|
87 |
+
translations = {
|
88 |
+
"en": {
|
89 |
+
"api_key": "API Key",
|
90 |
+
"api_key_placeholder": "Enter your API key",
|
91 |
+
"model_label": "Model",
|
92 |
+
"mode_label": "Mode",
|
93 |
+
"prompt_placeholder": "Enter your prompt",
|
94 |
+
"negative_prompt_placeholder": "Enter a negative prompt",
|
95 |
+
"seed_label": "Seed",
|
96 |
+
"randomize_seed_label": "Randomize seed",
|
97 |
+
"aspect_label": "Aspect ratio",
|
98 |
+
"run_button": "Run",
|
99 |
+
"result_label": "Result",
|
100 |
+
"copy_field_placeholder": "Copy the field",
|
101 |
+
"Negative_prompt": "Negative prompt",
|
102 |
+
"Advanced_Settings": "Advanced Settings",
|
103 |
+
"Example": "Example",
|
104 |
+
"Generate": "Generate",
|
105 |
+
"Upscale": "Upscale",
|
106 |
+
"Edit": "Edit",
|
107 |
+
"Control": "Control",
|
108 |
+
"Submode": "Submode",
|
109 |
+
"Conservative": "Conservative",
|
110 |
+
"Creative": "Creative",
|
111 |
+
"Erase": "Erase",
|
112 |
+
"Inpaint": "Inpaint",
|
113 |
+
"Outpaint": "Outpaint",
|
114 |
+
"Structure": "Structure",
|
115 |
+
"Sketch": "Sketch",
|
116 |
+
"Search_and_Replace": "Search and Replace",
|
117 |
+
"Remove_Background": "Remove Background",
|
118 |
+
"input_image": "Input Image",
|
119 |
+
"style_preset": "Style preset",
|
120 |
+
"preset_description": "This parameter is only available for ImageCore model.",
|
121 |
+
"Search_prompt_placeholder": "Enter a search prompt",
|
122 |
+
"Control_Strength": "Control Strength",
|
123 |
+
"overview": overview,
|
124 |
+
"overview_label": "How to use",
|
125 |
+
"title": title,
|
126 |
+
},
|
127 |
+
"ja": {
|
128 |
+
"api_key": "APIキー",
|
129 |
+
"api_key_placeholder": "APIキーを入力してください",
|
130 |
+
"model_label": "モデル",
|
131 |
+
"mode_label": "モード",
|
132 |
+
"prompt_placeholder": "プロンプトを入力してください",
|
133 |
+
"negative_prompt_placeholder": "ネガティブプロンプトを入力してください",
|
134 |
+
"seed_label": "シード",
|
135 |
+
"randomize_seed_label": "シードをランダム化",
|
136 |
+
"aspect_label": "アスペクト比",
|
137 |
+
"run_button": "実行",
|
138 |
+
"result_label": "結果",
|
139 |
+
"copy_field_placeholder": "ここに貼り付け用の情報が出てきます",
|
140 |
+
"Negative_prompt": "ネガティブプロンプト",
|
141 |
+
"Advanced_Settings": "追加設定",
|
142 |
+
"Example": "例",
|
143 |
+
"Generate": "テキストから生成",
|
144 |
+
"Upscale": "アップスケール",
|
145 |
+
"Edit": "画像の編集",
|
146 |
+
"Control": "コントロールモード",
|
147 |
+
"Submode": "サブモード",
|
148 |
+
"Conservative": "通常のアップスケール",
|
149 |
+
"Creative": "クリエィティブなアップスケール",
|
150 |
+
"Erase": "消去",
|
151 |
+
"Inpaint": "インペイント",
|
152 |
+
"Outpaint": "アウトペイント(拡張)",
|
153 |
+
"Structure": "構図",
|
154 |
+
"Sketch": "スケッチ",
|
155 |
+
"Search_and_Replace": "検索と置き換え",
|
156 |
+
"Remove_Background": "背景削除",
|
157 |
+
"input_image": "入力画像",
|
158 |
+
"style_preset": "スタイルのプリセット",
|
159 |
+
"preset_description": "このパラメータはimage coreのときにだけ有効になります",
|
160 |
+
"Search_prompt_placeholder": "探したい要素を入力してください",
|
161 |
+
"Control_Strength": "コントロールネットの適用強度",
|
162 |
+
"overview": overview_jp,
|
163 |
+
"overview_label": "使い方",
|
164 |
+
"title": title_jp,
|
165 |
+
},
|
166 |
+
}
|
167 |
+
|
168 |
+
lang = "ja"
|
169 |
+
|
170 |
+
|
171 |
def bytes_to_image(image):
|
172 |
image = BytesIO(image)
|
173 |
image = Image.open(image).convert("RGB")
|
|
|
222 |
"seed": seed,
|
223 |
"aspect_ratio": aspect,
|
224 |
}
|
225 |
+
data_rmbg = {
|
226 |
+
"output_format": "png",
|
227 |
+
}
|
228 |
if input_image is not None:
|
229 |
file["image"] = image_to_bytes(input_image)
|
230 |
if mask is not None:
|
231 |
file["mask"] = image_to_bytes(mask)
|
232 |
|
233 |
+
if mode == translations[lang]["Generate"]:
|
234 |
file["none"] = ""
|
235 |
if model == "Stable Image Ultra (8B + workflow)":
|
236 |
url = model_url["ImageUltra"]
|
|
|
246 |
elif model == "Stable Diffusion 3 Large Turbo (8B Turbo)":
|
247 |
url = model_url["StableDiffusion3"]
|
248 |
data["model"] = "sd3-large-turbo"
|
|
|
249 |
else:
|
250 |
raise ValueError("Invalid model type")
|
251 |
|
252 |
+
elif mode == translations[lang]["Upscale"]:
|
253 |
+
if submode == translations[lang]["Conservative"]:
|
254 |
url = service_url["Conservative_Upscale"]
|
255 |
+
elif submode == translations[lang]["Creative"]:
|
256 |
url = service_url["Creative_Upscale"]
|
257 |
|
258 |
+
elif mode == translations[lang]["Edit"]:
|
259 |
+
if submode == translations[lang]["Erase"]:
|
260 |
url = service_url["Erase"]
|
261 |
+
elif submode == translations[lang]["Inpaint"]:
|
262 |
url = service_url["Inpaint"]
|
263 |
+
elif submode == translations[lang]["Outpaint"]:
|
264 |
url = service_url["Outpaint"]
|
265 |
data["left"] = op_left
|
266 |
data["right"] = op_right
|
267 |
data["up"] = op_up
|
268 |
data["down"] = op_down
|
269 |
+
elif submode == translations[lang]["Search_and_Replace"]:
|
270 |
url = service_url["SR"]
|
271 |
data["search_prompt"] = search_prompt
|
272 |
+
elif submode == translations[lang]["Remove_Background"]:
|
273 |
+
data = data_rmbg
|
274 |
url = service_url["RMBG"]
|
275 |
|
276 |
+
elif mode == translations[lang]["Control"]:
|
277 |
data["control_strength"] = CNstrength
|
278 |
+
if submode == translations[lang]["Sketch"]:
|
279 |
url = service_url["Sketch"]
|
280 |
+
elif submode == translations[lang]["Structure"]:
|
281 |
url = service_url["Structure"]
|
|
|
282 |
response = send_request(url, api_key, file, data)
|
283 |
+
|
284 |
if response.status_code == 200:
|
285 |
+
if (
|
286 |
+
mode == translations[lang]["Upscale"]
|
287 |
+
and submode == translations[lang]["Creative"]
|
288 |
+
):
|
289 |
generation_id = response.json().get("id")
|
290 |
if not generation_id:
|
291 |
raise Exception("No generation ID returned for creative upscale")
|
|
|
344 |
img_input_update = gr.update(visible=False)
|
345 |
mask_update = gr.update(visible=False)
|
346 |
|
347 |
+
if mode == translations[lang]["Generate"]:
|
348 |
submode_update = gr.update(visible=False)
|
349 |
+
elif mode == translations[lang]["Upscale"]:
|
350 |
submode_update = gr.update(
|
351 |
+
choices=[
|
352 |
+
translations[lang]["Conservative"],
|
353 |
+
translations[lang]["Creative"],
|
354 |
+
],
|
355 |
+
value=translations[lang]["Conservative"],
|
356 |
+
visible=True,
|
357 |
)
|
358 |
img_input_update = gr.update(visible=True)
|
359 |
image_label_update = gr.update(visible=True)
|
360 |
+
elif mode == translations[lang]["Edit"]:
|
361 |
submode_update = gr.update(
|
362 |
choices=[
|
363 |
+
translations[lang]["Erase"],
|
364 |
+
translations[lang]["Inpaint"],
|
365 |
+
translations[lang]["Outpaint"],
|
366 |
+
translations[lang]["Search_and_Replace"],
|
367 |
+
translations[lang]["Remove_Background"],
|
368 |
],
|
369 |
+
value=translations[lang]["Erase"],
|
370 |
visible=True,
|
371 |
)
|
372 |
img_input_update = gr.update(visible=True)
|
373 |
image_label_update = gr.update(visible=True)
|
374 |
+
elif mode == translations[lang]["Control"]:
|
375 |
submode_update = gr.update(
|
376 |
+
choices=[
|
377 |
+
translations[lang]["Structure"],
|
378 |
+
translations[lang]["Sketch"],
|
379 |
+
],
|
380 |
+
value=translations[lang]["Structure"],
|
381 |
+
visible=True,
|
382 |
)
|
383 |
img_input_update = gr.update(visible=True)
|
384 |
image_label_update = gr.update(visible=True)
|
|
|
392 |
cn = gr.update(visible=False)
|
393 |
search_prompt = gr.update(visible=False)
|
394 |
|
395 |
+
if submode in [translations[lang]["Erase"], translations[lang]["Inpaint"]]:
|
396 |
mask = gr.update(visible=True)
|
397 |
|
398 |
else:
|
399 |
+
if submode == translations[lang]["Outpaint"]:
|
400 |
outpaint = gr.update(visible=True)
|
401 |
|
402 |
+
elif submode in [translations[lang]["Structure"], translations[lang]["Sketch"]]:
|
403 |
cn = gr.update(visible=True)
|
404 |
|
405 |
+
elif submode == translations[lang]["Search_and_Replace"]:
|
406 |
search_prompt = gr.update(visible=True)
|
407 |
|
408 |
return mask, outpaint, cn, search_prompt
|
|
|
411 |
with gr.Blocks(css=css, theme="NoCrypt/miku") as demo:
|
412 |
with gr.Column(elem_id="col-container"):
|
413 |
gr.Markdown(
|
414 |
+
translations[lang]["title"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
415 |
)
|
416 |
+
with gr.Accordion(translations[lang]["overview_label"], open=False):
|
417 |
+
gr.Markdown(
|
418 |
+
translations[lang]["overview"],
|
419 |
+
)
|
420 |
|
421 |
with gr.Row():
|
422 |
api_key = gr.Text(
|
423 |
+
label=translations[lang]["api_key"],
|
424 |
type="password",
|
425 |
+
placeholder=translations[lang]["api_key_placeholder"],
|
426 |
max_lines=1,
|
427 |
container=False,
|
428 |
)
|
429 |
|
430 |
with gr.Row():
|
431 |
model = gr.Dropdown(
|
432 |
+
label=translations[lang]["model_label"],
|
433 |
+
choices=[
|
434 |
+
"Stable Image Ultra (8B + workflow)",
|
435 |
+
"Stable Image Core (2B + workflow)",
|
436 |
+
"Stable Diffusion 3 Large Turbo (8B Turbo)",
|
437 |
+
"Stable Diffusion 3 Large (8B)",
|
438 |
+
"Stable Diffusion 3 Medium (2B)",
|
439 |
+
],
|
440 |
+
value="Stable Image Ultra (8B + workflow)",
|
441 |
)
|
442 |
mode = gr.Dropdown(
|
443 |
+
label=translations[lang]["mode_label"],
|
444 |
+
choices=[
|
445 |
+
translations[lang]["Generate"],
|
446 |
+
translations[lang]["Upscale"],
|
447 |
+
translations[lang]["Edit"],
|
448 |
+
translations[lang]["Control"],
|
449 |
+
],
|
450 |
+
value=translations[lang]["Generate"],
|
451 |
)
|
452 |
|
453 |
submode = gr.Dropdown(
|
454 |
+
label=translations[lang]["Submode"],
|
455 |
+
choices=["None"],
|
456 |
+
visible=False,
|
457 |
+
value="None",
|
458 |
)
|
459 |
|
460 |
with gr.Row():
|
|
|
463 |
label="Prompt",
|
464 |
show_label=False,
|
465 |
max_lines=1,
|
466 |
+
placeholder=translations[lang]["prompt_placeholder"],
|
467 |
container=False,
|
468 |
)
|
469 |
search_prompt = gr.Text(
|
|
|
471 |
visible=False,
|
472 |
show_label=False,
|
473 |
max_lines=1,
|
474 |
+
placeholder=translations[lang]["Search_prompt_placeholder"],
|
475 |
)
|
476 |
+
run_button = gr.Button(translations[lang]["run_button"], scale=0)
|
477 |
+
with gr.Row():
|
478 |
+
gr.Examples(
|
479 |
+
label=translations[lang]["Example"], examples=examples, inputs=[prompt]
|
480 |
+
)
|
481 |
with gr.Row():
|
482 |
with gr.Column():
|
483 |
+
image_label = gr.Markdown(
|
484 |
+
value=translations[lang]["input_image"], visible=False
|
485 |
+
)
|
486 |
image = gr.Image(
|
487 |
type="pil",
|
488 |
label="img input",
|
|
|
506 |
)
|
507 |
|
508 |
with gr.Row():
|
509 |
+
result = gr.Image(
|
510 |
+
label=translations[lang]["result_label"], width="20vw", height="20%"
|
511 |
+
)
|
512 |
|
513 |
+
with gr.Accordion(translations[lang]["Advanced_Settings"], open=False):
|
514 |
negative_prompt = gr.Text(
|
515 |
+
label=translations[lang]["Negative_prompt"],
|
516 |
max_lines=1,
|
517 |
+
placeholder=translations[lang]["negative_prompt_placeholder"],
|
518 |
)
|
519 |
seed = gr.Slider(
|
520 |
+
label=translations[lang]["seed_label"],
|
521 |
minimum=0,
|
522 |
maximum=MAX_SEED,
|
523 |
step=1,
|
524 |
value=0,
|
525 |
)
|
526 |
CN_strength = gr.Slider(
|
527 |
+
label=translations[lang]["Control_Strength"],
|
528 |
minimum=0,
|
529 |
maximum=1,
|
530 |
step=0.01,
|
531 |
value=0.5,
|
532 |
visible=False,
|
533 |
)
|
534 |
+
randomize_seed = gr.Checkbox(
|
535 |
+
label=translations[lang]["randomize_seed_label"], value=True
|
536 |
+
)
|
537 |
aspect = gr.Radio(
|
538 |
choices=[
|
539 |
"1:1",
|
|
|
546 |
"9:16",
|
547 |
"9:21",
|
548 |
],
|
549 |
+
label=translations[lang]["aspect_label"],
|
550 |
value="1:1",
|
551 |
)
|
552 |
with gr.Row(visible=False) as style:
|
|
|
570 |
"pixel-art",
|
571 |
"tile-texture",
|
572 |
],
|
573 |
+
label=translations[lang]["style_preset"],
|
574 |
value="anime",
|
575 |
+
info=translations[lang]["preset_description"],
|
576 |
)
|
577 |
with gr.Row(visible=False) as outpaint_scale:
|
578 |
paint = gr.Markdown(value="Outpain Scale")
|
|
|
589 |
label="down", minimum=0, maximum=2000, step=4, value=200
|
590 |
)
|
591 |
|
|
|
|
|
592 |
copy_filed = gr.TextArea(
|
593 |
value="",
|
594 |
label="Copy Field",
|
595 |
max_lines=1,
|
596 |
+
placeholder=translations[lang]["copy_field_placeholder"],
|
597 |
show_copy_button=True,
|
598 |
container=False,
|
599 |
)
|
600 |
gr.Markdown(
|
601 |
+
f"""
|
602 |
## License
|
603 |
This work is licensed under a
|
604 |
[Creative Commons Attribution-NonCommercial 4.0 International License][cc-by-nc].
|