aiqtech commited on
Commit
00d9bae
Β·
verified Β·
1 Parent(s): c1f1cf6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -12
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(prompt, "cuda", True)
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="Prompt",
96
- info="Describe what to inpaint the mask with",
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="Model",
104
  )
105
- run_button = gr.Button("Generate")
106
 
107
  with gr.Row():
108
  input_image = gr.ImageMask(
109
  type="pil",
110
- label="Input Image",
111
  crop_size=(1024, 1024),
112
  layers=False
113
  )
114
 
115
  result = ImageSlider(
116
  interactive=False,
117
- label="Generated Image",
118
  )
119
 
120
- use_as_input_button = gr.Button("Use as Input Image", visible=False)
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)