fantos commited on
Commit
8bc44c9
Β·
verified Β·
1 Parent(s): 66cbb55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -7
app.py CHANGED
@@ -1,10 +1,15 @@
1
  import random
 
2
  import gradio as gr
3
  import numpy as np
4
  import spaces
5
  import torch
6
  from diffusers import AutoencoderKL
7
  from mixture_tiling_sdxl import StableDiffusionXLTilingPipeline
 
 
 
 
8
 
9
  MAX_SEED = np.iinfo(np.int32).max
10
  SCHEDULERS = [
@@ -36,7 +41,15 @@ pipe.enable_model_cpu_offload() # VRAM이 μ œν•œλœ 경우 μ‚¬μš©
36
  pipe.enable_vae_tiling()
37
  pipe.enable_vae_slicing()
38
 
39
- #region functions
 
 
 
 
 
 
 
 
40
  def select_scheduler(scheduler_name):
41
  scheduler_parts = scheduler_name.split("-")
42
  scheduler_class_name = scheduler_parts[0]
@@ -63,6 +76,11 @@ def predict(left_prompt, center_prompt, right_prompt, negative_prompt, left_gs,
63
  pipe.scheduler = select_scheduler(scheduler)
64
  generator = torch.Generator("cuda").manual_seed(generation_seed)
65
 
 
 
 
 
 
66
  target_height = int(target_height)
67
  target_width = int(target_width)
68
  tile_height = int(tile_height)
@@ -221,7 +239,9 @@ button:hover, .btn:hover {
221
 
222
  title = """
223
  <h1 align="center" style="margin-bottom: 0.2em;"> πŸ€— Panorama X3 Image </h1>
224
-
 
 
225
  """
226
 
227
  with gr.Blocks(css=css, title="SDXL Tiling Pipeline") as app:
@@ -234,21 +254,21 @@ with gr.Blocks(css=css, title="SDXL Tiling Pipeline") as app:
234
  with gr.Row():
235
  with gr.Column(variant="panel"):
236
  gr.Markdown("### Left Region")
237
- left_prompt = gr.Textbox(lines=4, placeholder="예: μšΈμ°½ν•œ 숲과 햇살이 λΉ„μΆ”λŠ” λ‚˜λ¬΄...", label="Left Prompt")
238
  left_gs = gr.Slider(minimum=0, maximum=15, value=7, step=1, label="Left CFG Scale")
239
  with gr.Column(variant="panel"):
240
  gr.Markdown("### Center Region")
241
- center_prompt = gr.Textbox(lines=4, placeholder="예: μž”μž”ν•œ ν˜Έμˆ˜μ™€ λ°˜μ§μ΄λŠ” 수면...", label="Center Prompt")
242
  center_gs = gr.Slider(minimum=0, maximum=15, value=7, step=1, label="Center CFG Scale")
243
  with gr.Column(variant="panel"):
244
  gr.Markdown("### Right Region")
245
- right_prompt = gr.Textbox(lines=4, placeholder="예: μ›…μž₯ν•œ μ‚°λ§₯κ³Ό ν•˜λŠ˜μ„ κ°€λ₯΄λŠ” ꡬ름...", label="Right Prompt")
246
  right_gs = gr.Slider(minimum=0, maximum=15, value=7, step=1, label="Right CFG Scale")
247
  with gr.Row():
248
  negative_prompt = gr.Textbox(
249
  lines=2,
250
  label="Negative Prompt",
251
- placeholder="예: blurry, low resolution, artifacts, poor details",
252
  value="blurry, low resolution, artifacts, poor details"
253
  )
254
  with gr.Row():
@@ -296,7 +316,6 @@ with gr.Blocks(css=css, title="SDXL Tiling Pipeline") as app:
296
  1024, 1920,
297
  1280
298
  ],
299
-
300
  [
301
  "Vibrant abstract strokes with fluid, swirling patterns in cool tones",
302
  "Interlocking geometric shapes bursting with color and texture",
 
1
  import random
2
+ import re
3
  import gradio as gr
4
  import numpy as np
5
  import spaces
6
  import torch
7
  from diffusers import AutoencoderKL
8
  from mixture_tiling_sdxl import StableDiffusionXLTilingPipeline
9
+ from transformers import pipeline
10
+
11
+ # ν•œκΈ€ μž…λ ₯ μ‹œ μ˜μ–΄λ‘œ λ²ˆμ—­ν•˜κΈ° μœ„ν•œ νŒŒμ΄ν”„λΌμΈ (CPUμ—μ„œ λ™μž‘)
12
+ translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
13
 
14
  MAX_SEED = np.iinfo(np.int32).max
15
  SCHEDULERS = [
 
41
  pipe.enable_vae_tiling()
42
  pipe.enable_vae_slicing()
43
 
44
+ #region helper functions
45
+ def translate_if_needed(text: str) -> str:
46
+ """ν…μŠ€νŠΈμ— ν•œκΈ€μ΄ ν¬ν•¨λœ 경우 μ˜μ–΄λ‘œ λ²ˆμ—­ν•˜μ—¬ λ°˜ν™˜."""
47
+ if re.search(r'[\uac00-\ud7a3]', text):
48
+ # λ²ˆμ—­ κ²°κ³ΌλŠ” 리슀트의 첫번째 μš”μ†Œμ˜ "translation_text" 킀에 있음
49
+ translated = translator(text)[0]["translation_text"]
50
+ return translated
51
+ return text
52
+
53
  def select_scheduler(scheduler_name):
54
  scheduler_parts = scheduler_name.split("-")
55
  scheduler_class_name = scheduler_parts[0]
 
76
  pipe.scheduler = select_scheduler(scheduler)
77
  generator = torch.Generator("cuda").manual_seed(generation_seed)
78
 
79
+ # ν•œκΈ€ ν”„λ‘¬ν”„νŠΈκ°€ μž…λ ₯된 경우 μ˜μ–΄λ‘œ λ²ˆμ—­
80
+ left_prompt = translate_if_needed(left_prompt)
81
+ center_prompt = translate_if_needed(center_prompt)
82
+ right_prompt = translate_if_needed(right_prompt)
83
+
84
  target_height = int(target_height)
85
  target_width = int(target_width)
86
  tile_height = int(tile_height)
 
239
 
240
  title = """
241
  <h1 align="center" style="margin-bottom: 0.2em;"> πŸ€— Panorama X3 Image </h1>
242
+ <p align="center" style="font-size:1.1em; color:#555;">
243
+ Left/Center/Right prompts (English/Korean allowed)
244
+ </p>
245
  """
246
 
247
  with gr.Blocks(css=css, title="SDXL Tiling Pipeline") as app:
 
254
  with gr.Row():
255
  with gr.Column(variant="panel"):
256
  gr.Markdown("### Left Region")
257
+ left_prompt = gr.Textbox(lines=4, placeholder="e.g., μšΈμ°½ν•œ 숲과 햇살이 λΉ„μΆ”λŠ” λ‚˜λ¬΄...", label="Left Prompt (English/Korean allowed)")
258
  left_gs = gr.Slider(minimum=0, maximum=15, value=7, step=1, label="Left CFG Scale")
259
  with gr.Column(variant="panel"):
260
  gr.Markdown("### Center Region")
261
+ center_prompt = gr.Textbox(lines=4, placeholder="e.g., μž”μž”ν•œ ν˜Έμˆ˜μ™€ λ°˜μ§μ΄λŠ” 수면...", label="Center Prompt (English/Korean allowed)")
262
  center_gs = gr.Slider(minimum=0, maximum=15, value=7, step=1, label="Center CFG Scale")
263
  with gr.Column(variant="panel"):
264
  gr.Markdown("### Right Region")
265
+ right_prompt = gr.Textbox(lines=4, placeholder="e.g., μ›…μž₯ν•œ μ‚°λ§₯κ³Ό ν•˜λŠ˜μ„ κ°€λ₯΄λŠ” ꡬ름...", label="Right Prompt (English/Korean allowed)")
266
  right_gs = gr.Slider(minimum=0, maximum=15, value=7, step=1, label="Right CFG Scale")
267
  with gr.Row():
268
  negative_prompt = gr.Textbox(
269
  lines=2,
270
  label="Negative Prompt",
271
+ placeholder="e.g., blurry, low resolution, artifacts, poor details",
272
  value="blurry, low resolution, artifacts, poor details"
273
  )
274
  with gr.Row():
 
316
  1024, 1920,
317
  1280
318
  ],
 
319
  [
320
  "Vibrant abstract strokes with fluid, swirling patterns in cool tones",
321
  "Interlocking geometric shapes bursting with color and texture",