Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ from diffusers import AutoencoderKL, TCDScheduler
|
|
5 |
from diffusers.models.model_loading_utils import load_state_dict
|
6 |
from gradio_imageslider import ImageSlider
|
7 |
from huggingface_hub import hf_hub_download
|
|
|
8 |
|
9 |
from controlnet_union import ControlNetModel_Union
|
10 |
from pipeline_fill_sd_xl import StableDiffusionXLFillPipeline
|
@@ -13,6 +14,9 @@ MODELS = {
|
|
13 |
"RealVisXL V5.0 Lightning": "SG161222/RealVisXL_V5.0_Lightning",
|
14 |
}
|
15 |
|
|
|
|
|
|
|
16 |
config_file = hf_hub_download(
|
17 |
"xinsir/controlnet-union-sdxl-1.0",
|
18 |
filename="config_promax.json",
|
@@ -44,15 +48,26 @@ pipe = StableDiffusionXLFillPipeline.from_pretrained(
|
|
44 |
|
45 |
pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
@spaces.GPU
|
49 |
def fill_image(prompt, image, model_selection):
|
|
|
|
|
|
|
50 |
(
|
51 |
prompt_embeds,
|
52 |
negative_prompt_embeds,
|
53 |
pooled_prompt_embeds,
|
54 |
negative_pooled_prompt_embeds,
|
55 |
-
) = pipe.encode_prompt(
|
56 |
|
57 |
source = image["background"]
|
58 |
mask = image["layers"][0]
|
@@ -76,11 +91,9 @@ def fill_image(prompt, image, model_selection):
|
|
76 |
|
77 |
yield source, cnet_image
|
78 |
|
79 |
-
|
80 |
def clear_result():
|
81 |
return gr.update(value=None)
|
82 |
|
83 |
-
|
84 |
css = """
|
85 |
footer {
|
86 |
visibility: hidden;
|
@@ -88,36 +101,35 @@ footer {
|
|
88 |
"""
|
89 |
|
90 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
91 |
-
# gr.HTML(title) μ€μ μ κ±°νκ³ μ¬κΈ°μλΆν° μμν©λλ€.
|
92 |
with gr.Row():
|
93 |
with gr.Column():
|
94 |
prompt = gr.Textbox(
|
95 |
-
label="
|
96 |
-
info="
|
97 |
lines=3,
|
98 |
)
|
99 |
with gr.Column():
|
100 |
model_selection = gr.Dropdown(
|
101 |
choices=list(MODELS.keys()),
|
102 |
value="RealVisXL V5.0 Lightning",
|
103 |
-
label="
|
104 |
)
|
105 |
-
run_button = gr.Button("
|
106 |
|
107 |
with gr.Row():
|
108 |
input_image = gr.ImageMask(
|
109 |
type="pil",
|
110 |
-
label="
|
111 |
crop_size=(1024, 1024),
|
112 |
layers=False
|
113 |
)
|
114 |
|
115 |
result = ImageSlider(
|
116 |
interactive=False,
|
117 |
-
label="
|
118 |
)
|
119 |
|
120 |
-
use_as_input_button = gr.Button("
|
121 |
|
122 |
def use_output_as_input(output_image):
|
123 |
return gr.update(value=output_image[1])
|
@@ -164,5 +176,4 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
164 |
outputs=use_as_input_button,
|
165 |
)
|
166 |
|
167 |
-
|
168 |
demo.launch(share=False)
|
|
|
5 |
from diffusers.models.model_loading_utils import load_state_dict
|
6 |
from gradio_imageslider import ImageSlider
|
7 |
from huggingface_hub import hf_hub_download
|
8 |
+
from transformers import pipeline
|
9 |
|
10 |
from controlnet_union import ControlNetModel_Union
|
11 |
from pipeline_fill_sd_xl import StableDiffusionXLFillPipeline
|
|
|
14 |
"RealVisXL V5.0 Lightning": "SG161222/RealVisXL_V5.0_Lightning",
|
15 |
}
|
16 |
|
17 |
+
# λ²μ λͺ¨λΈ λ‘λ
|
18 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
19 |
+
|
20 |
config_file = hf_hub_download(
|
21 |
"xinsir/controlnet-union-sdxl-1.0",
|
22 |
filename="config_promax.json",
|
|
|
48 |
|
49 |
pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
|
50 |
|
51 |
+
def translate_if_korean(text):
|
52 |
+
# μ
λ ₯λ ν
μ€νΈκ° νκΈμ ν¬ν¨νκ³ μλμ§ νμΈ
|
53 |
+
if any('\u3131' <= char <= '\u318E' or '\uAC00' <= char <= '\uD7A3' for char in text):
|
54 |
+
# νκΈμ΄ ν¬ν¨λμ΄ μλ€λ©΄ λ²μ
|
55 |
+
translated = translator(text)[0]['translation_text']
|
56 |
+
print(f"Translated prompt: {translated}") # λλ²κΉ
μ μν μΆλ ₯
|
57 |
+
return translated
|
58 |
+
return text
|
59 |
|
60 |
@spaces.GPU
|
61 |
def fill_image(prompt, image, model_selection):
|
62 |
+
# ν둬ννΈ λ²μ
|
63 |
+
translated_prompt = translate_if_korean(prompt)
|
64 |
+
|
65 |
(
|
66 |
prompt_embeds,
|
67 |
negative_prompt_embeds,
|
68 |
pooled_prompt_embeds,
|
69 |
negative_pooled_prompt_embeds,
|
70 |
+
) = pipe.encode_prompt(translated_prompt, "cuda", True)
|
71 |
|
72 |
source = image["background"]
|
73 |
mask = image["layers"][0]
|
|
|
91 |
|
92 |
yield source, cnet_image
|
93 |
|
|
|
94 |
def clear_result():
|
95 |
return gr.update(value=None)
|
96 |
|
|
|
97 |
css = """
|
98 |
footer {
|
99 |
visibility: hidden;
|
|
|
101 |
"""
|
102 |
|
103 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
|
104 |
with gr.Row():
|
105 |
with gr.Column():
|
106 |
prompt = gr.Textbox(
|
107 |
+
label="ν둬ννΈ",
|
108 |
+
info="λ§μ€ν¬μ μ±μλ£μ λ΄μ©μ μ€λͺ
νμΈμ (νκΈ λλ μμ΄)",
|
109 |
lines=3,
|
110 |
)
|
111 |
with gr.Column():
|
112 |
model_selection = gr.Dropdown(
|
113 |
choices=list(MODELS.keys()),
|
114 |
value="RealVisXL V5.0 Lightning",
|
115 |
+
label="λͺ¨λΈ",
|
116 |
)
|
117 |
+
run_button = gr.Button("μμ±")
|
118 |
|
119 |
with gr.Row():
|
120 |
input_image = gr.ImageMask(
|
121 |
type="pil",
|
122 |
+
label="μ
λ ₯ μ΄λ―Έμ§",
|
123 |
crop_size=(1024, 1024),
|
124 |
layers=False
|
125 |
)
|
126 |
|
127 |
result = ImageSlider(
|
128 |
interactive=False,
|
129 |
+
label="μμ±λ μ΄λ―Έμ§",
|
130 |
)
|
131 |
|
132 |
+
use_as_input_button = gr.Button("μ
λ ₯ μ΄λ―Έμ§λ‘ μ¬μ©", visible=False)
|
133 |
|
134 |
def use_output_as_input(output_image):
|
135 |
return gr.update(value=output_image[1])
|
|
|
176 |
outputs=use_as_input_button,
|
177 |
)
|
178 |
|
|
|
179 |
demo.launch(share=False)
|