ginipick commited on
Commit
64c13d4
ยท
verified ยท
1 Parent(s): 729e7f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -183,7 +183,6 @@ def generate_background(prompt: str, aspect_ratio: str) -> Image.Image:
183
 
184
 
185
  def create_position_grid():
186
- """3x3 ์œ„์น˜ ์„ ํƒ ๊ทธ๋ฆฌ๋“œ๋ฅผ ์ƒ์„ฑํ•˜๋Š” HTML"""
187
  return """
188
  <div class="position-grid" style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 150px; margin: auto;">
189
  <button class="position-btn" data-pos="top-left" onclick="updatePosition(this)">โ†–</button>
@@ -208,13 +207,11 @@ def create_position_grid():
208
  btn.style.backgroundColor = '#2196F3';
209
  btn.style.color = 'white';
210
 
211
- // position State ์—…๋ฐ์ดํŠธ
212
- const positionState = document.querySelector('#position-state');
213
- if (positionState) {
214
- positionState.value = btn.dataset.pos;
215
- // ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ ๋ฐœ์ƒ
216
- positionState.dispatchEvent(new Event('change'));
217
- }
218
  }
219
 
220
  // ์ดˆ๊ธฐ ์„ ํƒ ๋ฒ„ํŠผ ์Šคํƒ€์ผ ์„ค์ •
@@ -223,8 +220,6 @@ def create_position_grid():
223
  </script>
224
  """
225
 
226
-
227
-
228
  def calculate_object_position(position: str, bg_size: tuple[int, int], obj_size: tuple[int, int]) -> tuple[int, int]:
229
  """์˜ค๋ธŒ์ ํŠธ์˜ ์œ„์น˜ ๊ณ„์‚ฐ"""
230
  bg_width, bg_height = bg_size
@@ -486,11 +481,11 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
486
  scale=1
487
  )
488
 
489
-
490
  with gr.Row(visible=False) as object_controls:
491
  with gr.Column(scale=1):
492
  position_grid = gr.HTML(create_position_grid())
493
- position = gr.State(value="bottom-center", elem_id="position-state")
494
  with gr.Column(scale=1):
495
  scale_slider = gr.Slider(
496
  minimum=10,
@@ -499,7 +494,7 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
499
  step=10,
500
  label="Object Size (%)"
501
  )
502
-
503
 
504
 
505
  process_btn = gr.Button(
 
183
 
184
 
185
  def create_position_grid():
 
186
  return """
187
  <div class="position-grid" style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 150px; margin: auto;">
188
  <button class="position-btn" data-pos="top-left" onclick="updatePosition(this)">โ†–</button>
 
207
  btn.style.backgroundColor = '#2196F3';
208
  btn.style.color = 'white';
209
 
210
+ // Gradio์— ์ด๋ฒคํŠธ ๋ฐœ์ƒ
211
+ const event = new CustomEvent('position-update', {
212
+ detail: { position: btn.dataset.pos }
213
+ });
214
+ document.dispatchEvent(event);
 
 
215
  }
216
 
217
  // ์ดˆ๊ธฐ ์„ ํƒ ๋ฒ„ํŠผ ์Šคํƒ€์ผ ์„ค์ •
 
220
  </script>
221
  """
222
 
 
 
223
  def calculate_object_position(position: str, bg_size: tuple[int, int], obj_size: tuple[int, int]) -> tuple[int, int]:
224
  """์˜ค๋ธŒ์ ํŠธ์˜ ์œ„์น˜ ๊ณ„์‚ฐ"""
225
  bg_width, bg_height = bg_size
 
481
  scale=1
482
  )
483
 
484
+ # UI ๋ถ€๋ถ„์—์„œ position State ๋ถ€๋ถ„ ์ˆ˜์ •
485
  with gr.Row(visible=False) as object_controls:
486
  with gr.Column(scale=1):
487
  position_grid = gr.HTML(create_position_grid())
488
+ position = gr.State(value="bottom-center") # elem_id ์ œ๊ฑฐ
489
  with gr.Column(scale=1):
490
  scale_slider = gr.Slider(
491
  minimum=10,
 
494
  step=10,
495
  label="Object Size (%)"
496
  )
497
+
498
 
499
 
500
  process_btn = gr.Button(