Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -185,39 +185,16 @@ def generate_background(prompt: str, aspect_ratio: str) -> Image.Image:
|
|
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"
|
189 |
-
<button class="position-btn" data-pos="top-center"
|
190 |
-
<button class="position-btn" data-pos="top-right"
|
191 |
-
<button class="position-btn" data-pos="middle-left"
|
192 |
-
<button class="position-btn" data-pos="middle-center"
|
193 |
-
<button class="position-btn" data-pos="middle-right"
|
194 |
-
<button class="position-btn" data-pos="bottom-left"
|
195 |
-
<button class="position-btn" data-pos="bottom-center"
|
196 |
-
<button class="position-btn" data-pos="bottom-right"
|
197 |
</div>
|
198 |
-
<script>
|
199 |
-
function updatePosition(btn) {
|
200 |
-
// ๋ชจ๋ ๋ฒํผ์ ์คํ์ผ ์ด๊ธฐํ
|
201 |
-
document.querySelectorAll('.position-btn').forEach(b => {
|
202 |
-
b.style.backgroundColor = '';
|
203 |
-
b.style.color = '';
|
204 |
-
});
|
205 |
-
|
206 |
-
// ํด๋ฆญ๋ ๋ฒํผ ์คํ์ผ ๋ณ๊ฒฝ
|
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 |
-
// ์ด๊ธฐ ์ ํ ๋ฒํผ ์คํ์ผ ์ค์
|
218 |
-
document.querySelector('[data-default="true"]').style.backgroundColor = '#2196F3';
|
219 |
-
document.querySelector('[data-default="true"]').style.color = 'white';
|
220 |
-
</script>
|
221 |
"""
|
222 |
|
223 |
def calculate_object_position(position: str, bg_size: tuple[int, int], obj_size: tuple[int, int]) -> tuple[int, int]:
|
@@ -486,11 +463,18 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
486 |
scale=1
|
487 |
)
|
488 |
|
489 |
-
# UI ๋ถ๋ถ์์ position State ๋ถ๋ถ ์์
|
490 |
with gr.Row(visible=False) as object_controls:
|
491 |
with gr.Column(scale=1):
|
492 |
position_grid = gr.HTML(create_position_grid())
|
493 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
494 |
with gr.Column(scale=1):
|
495 |
scale_slider = gr.Slider(
|
496 |
minimum=10,
|
@@ -499,15 +483,13 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
499 |
step=5,
|
500 |
label="Object Size (%)"
|
501 |
)
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
interactive=False
|
509 |
)
|
510 |
-
# UI ๋ถ๋ถ์์ position State ์ถ๊ฐ
|
511 |
|
512 |
|
513 |
with gr.Column(scale=1):
|
|
|
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">โ</button>
|
189 |
+
<button class="position-btn" data-pos="top-center">โ</button>
|
190 |
+
<button class="position-btn" data-pos="top-right">โ</button>
|
191 |
+
<button class="position-btn" data-pos="middle-left">โ</button>
|
192 |
+
<button class="position-btn" data-pos="middle-center">โข</button>
|
193 |
+
<button class="position-btn" data-pos="middle-right">โ</button>
|
194 |
+
<button class="position-btn" data-pos="bottom-left">โ</button>
|
195 |
+
<button class="position-btn" data-pos="bottom-center" data-default="true">โ</button>
|
196 |
+
<button class="position-btn" data-pos="bottom-right">โ</button>
|
197 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
"""
|
199 |
|
200 |
def calculate_object_position(position: str, bg_size: tuple[int, int], obj_size: tuple[int, int]) -> tuple[int, int]:
|
|
|
463 |
scale=1
|
464 |
)
|
465 |
|
|
|
466 |
with gr.Row(visible=False) as object_controls:
|
467 |
with gr.Column(scale=1):
|
468 |
position_grid = gr.HTML(create_position_grid())
|
469 |
+
# Radio ๋ฒํผ์ผ๋ก ๋ณ๊ฒฝ
|
470 |
+
position = gr.Radio(
|
471 |
+
choices=["top-left", "top-center", "top-right",
|
472 |
+
"middle-left", "middle-center", "middle-right",
|
473 |
+
"bottom-left", "bottom-center", "bottom-right"],
|
474 |
+
value="bottom-center",
|
475 |
+
label="Position",
|
476 |
+
visible=False # UI์์๋ ์จ๊น
|
477 |
+
)
|
478 |
with gr.Column(scale=1):
|
479 |
scale_slider = gr.Slider(
|
480 |
minimum=10,
|
|
|
483 |
step=5,
|
484 |
label="Object Size (%)"
|
485 |
)
|
486 |
+
# ์์น ์ ํ ์ด๋ฒคํธ ์ฒ๋ฆฌ
|
487 |
+
position_grid.click(
|
488 |
+
fn=lambda evt: evt.index, # ํด๋ฆญ๋ ์์น์ ์ธ๋ฑ์ค ๋ฐํ
|
489 |
+
inputs=[],
|
490 |
+
outputs=[position],
|
491 |
+
preprocess=False
|
|
|
492 |
)
|
|
|
493 |
|
494 |
|
495 |
with gr.Column(scale=1):
|