Spaces:
Sleeping
Sleeping
Image editor frame resize
Browse files
app.py
CHANGED
|
@@ -474,71 +474,9 @@ human_ex_list = human_list_path
|
|
| 474 |
|
| 475 |
image_blocks = gr.Blocks().queue()
|
| 476 |
with image_blocks as demo:
|
| 477 |
-
#
|
| 478 |
gr.HTML("""
|
| 479 |
<style>
|
| 480 |
-
/* PC ๋ฐ ๋ชจ๋ฐ์ผ ๊ณตํต: ImageEditor ์ปจํ
์ด๋ */
|
| 481 |
-
#image-editor-fixed {
|
| 482 |
-
position: relative;
|
| 483 |
-
display: inline-block;
|
| 484 |
-
}
|
| 485 |
-
|
| 486 |
-
/* PC: ๊ณ ์ ํฌ๊ธฐ (384x512) */
|
| 487 |
-
@media (min-width: 768px) {
|
| 488 |
-
#image-editor-fixed canvas {
|
| 489 |
-
width: 384px !important;
|
| 490 |
-
height: 512px !important;
|
| 491 |
-
max-width: 384px !important;
|
| 492 |
-
max-height: 512px !important;
|
| 493 |
-
object-fit: contain !important;
|
| 494 |
-
}
|
| 495 |
-
#image-editor-fixed > div,
|
| 496 |
-
#image-editor-fixed .image-editor-container,
|
| 497 |
-
#image-editor-fixed .image-editor-wrapper,
|
| 498 |
-
#image-editor-fixed [class*="editor"],
|
| 499 |
-
#image-editor-fixed [class*="canvas"] {
|
| 500 |
-
width: 384px !important;
|
| 501 |
-
height: 512px !important;
|
| 502 |
-
max-width: 384px !important;
|
| 503 |
-
max-height: 512px !important;
|
| 504 |
-
}
|
| 505 |
-
#image-editor-fixed img {
|
| 506 |
-
width: 384px !important;
|
| 507 |
-
height: 512px !important;
|
| 508 |
-
max-width: 384px !important;
|
| 509 |
-
max-height: 512px !important;
|
| 510 |
-
object-fit: contain !important;
|
| 511 |
-
}
|
| 512 |
-
}
|
| 513 |
-
|
| 514 |
-
/* ๋ชจ๋ฐ์ผ: ํ๋ฉด ํฌ๊ธฐ์ ๋ง๊ฒ ์ค์ผ์ผ๋งํ๋ ๋น์จ ์ ์ง */
|
| 515 |
-
@media (max-width: 767px) {
|
| 516 |
-
#image-editor-fixed {
|
| 517 |
-
width: 100% !important;
|
| 518 |
-
max-width: 100% !important;
|
| 519 |
-
}
|
| 520 |
-
#image-editor-fixed canvas {
|
| 521 |
-
width: 100% !important;
|
| 522 |
-
max-width: 100% !important;
|
| 523 |
-
height: auto !important;
|
| 524 |
-
aspect-ratio: 3/4 !important;
|
| 525 |
-
object-fit: contain !important;
|
| 526 |
-
}
|
| 527 |
-
#image-editor-fixed > div,
|
| 528 |
-
#image-editor-fixed .image-editor-container,
|
| 529 |
-
#image-editor-fixed .image-editor-wrapper {
|
| 530 |
-
width: 100% !important;
|
| 531 |
-
max-width: 100% !important;
|
| 532 |
-
}
|
| 533 |
-
#image-editor-fixed img {
|
| 534 |
-
width: 100% !important;
|
| 535 |
-
max-width: 100% !important;
|
| 536 |
-
height: auto !important;
|
| 537 |
-
aspect-ratio: 3/4 !important;
|
| 538 |
-
object-fit: contain !important;
|
| 539 |
-
}
|
| 540 |
-
}
|
| 541 |
-
|
| 542 |
/* ์ถ๋ ฅ ์ด๋ฏธ์ง ํฌ๊ธฐ ๊ณ ์ : Masked image output ๋ฐ Output */
|
| 543 |
/* PC: ๊ณ ์ ํฌ๊ธฐ (384x512) */
|
| 544 |
@media (min-width: 768px) {
|
|
@@ -572,9 +510,20 @@ with image_blocks as demo:
|
|
| 572 |
max-width: 384px !important;
|
| 573 |
}
|
| 574 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 575 |
</style>
|
| 576 |
<script>
|
| 577 |
-
//
|
|
|
|
| 578 |
(function() {
|
| 579 |
const CANVAS_WIDTH = 384;
|
| 580 |
const CANVAS_HEIGHT = 512;
|
|
@@ -583,47 +532,31 @@ with image_blocks as demo:
|
|
| 583 |
const editor = document.querySelector('#image-editor-fixed');
|
| 584 |
if (!editor) return;
|
| 585 |
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
}
|
| 594 |
-
|
| 595 |
-
// ๋ชจ๋ฐ์ผ์์๋ CSS๋ก ํ์ ํฌ๊ธฐ๋ง ์กฐ์ , PC์์๋ ๊ณ ์ ํฌ๊ธฐ
|
| 596 |
-
const isMobile = window.innerWidth <= 767;
|
| 597 |
-
if (isMobile) {
|
| 598 |
-
// ๋ชจ๋ฐ์ผ: ํ๋ฉด ํฌ๊ธฐ์ ๋ง๊ฒ ํ์ํ๋ ๋น์จ ์ ์ง
|
| 599 |
-
const container = editor.closest('.gradio-column') || editor.parentElement;
|
| 600 |
-
if (container) {
|
| 601 |
-
const maxWidth = Math.min(container.offsetWidth - 20, 384);
|
| 602 |
-
const maxHeight = (maxWidth * 4) / 3;
|
| 603 |
-
canvas.style.width = maxWidth + 'px';
|
| 604 |
-
canvas.style.height = maxHeight + 'px';
|
| 605 |
-
canvas.style.maxWidth = '100%';
|
| 606 |
-
canvas.style.maxHeight = 'none';
|
| 607 |
}
|
| 608 |
-
}
|
| 609 |
-
// PC: ๊ณ ์ ํฌ๊ธฐ
|
| 610 |
-
canvas.style.width = CANVAS_WIDTH + 'px';
|
| 611 |
-
canvas.style.height = CANVAS_HEIGHT + 'px';
|
| 612 |
-
canvas.style.maxWidth = CANVAS_WIDTH + 'px';
|
| 613 |
-
canvas.style.maxHeight = CANVAS_HEIGHT + 'px';
|
| 614 |
-
}
|
| 615 |
}
|
| 616 |
|
| 617 |
// ์ด๊ธฐ ์คํ
|
|
|
|
|
|
|
|
|
|
|
|
|
| 618 |
if (document.readyState === 'loading') {
|
| 619 |
-
document.addEventListener('DOMContentLoaded',
|
| 620 |
} else {
|
| 621 |
-
|
| 622 |
}
|
| 623 |
|
| 624 |
// ์ด๋ฏธ์ง ๋ก๋ ํ ์ฌ์ ์ฉ
|
| 625 |
window.addEventListener('load', function() {
|
| 626 |
-
fixImageEditorCanvas
|
| 627 |
setTimeout(fixImageEditorCanvas, 500);
|
| 628 |
setTimeout(fixImageEditorCanvas, 1500);
|
| 629 |
});
|
|
@@ -635,7 +568,7 @@ with image_blocks as demo:
|
|
| 635 |
resizeTimeout = setTimeout(fixImageEditorCanvas, 300);
|
| 636 |
});
|
| 637 |
|
| 638 |
-
// MutationObserver๋ก ๋์ ๋ณ๊ฒฝ ๊ฐ์ง
|
| 639 |
const observer = new MutationObserver(function(mutations) {
|
| 640 |
fixImageEditorCanvas();
|
| 641 |
});
|
|
@@ -647,8 +580,7 @@ with image_blocks as demo:
|
|
| 647 |
observer.observe(editor, {
|
| 648 |
childList: true,
|
| 649 |
subtree: true,
|
| 650 |
-
attributes:
|
| 651 |
-
attributeFilter: ['style', 'class']
|
| 652 |
});
|
| 653 |
}
|
| 654 |
}, 1000);
|
|
@@ -660,7 +592,7 @@ with image_blocks as demo:
|
|
| 660 |
gr.Markdown("์ด๋ฏธ์ง๋ 3:4๋น์จ(384x512 ๋๋ 768x1024)๋ก ์ฌ๋ ค์ฃผ์ธ์")
|
| 661 |
with gr.Row():
|
| 662 |
with gr.Column():
|
| 663 |
-
imgs = gr.ImageEditor(sources='upload', type="pil", label='๋์ ์ด๋ฏธ์ง', interactive=True,
|
| 664 |
img_url_input = gr.Textbox(label="๋์ ์ด๋ฏธ์ง URL", placeholder="์) https://example.com/human_image.jpg")
|
| 665 |
with gr.Row():
|
| 666 |
with gr.Row():
|
|
|
|
| 474 |
|
| 475 |
image_blocks = gr.Blocks().queue()
|
| 476 |
with image_blocks as demo:
|
| 477 |
+
# ImageEditor์ canvas ์ค์ ํฌ๊ธฐ๋ง ๊ณ ์ ํ์ฌ ๋ธ๋ฌ์ ์์น ์ ํ๋ ์ ์ง (๊ธฐ๋ณธ ๊ธฐ๋ฅ ๋ณด์กด)
|
| 478 |
gr.HTML("""
|
| 479 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
/* ์ถ๋ ฅ ์ด๋ฏธ์ง ํฌ๊ธฐ ๊ณ ์ : Masked image output ๋ฐ Output */
|
| 481 |
/* PC: ๊ณ ์ ํฌ๊ธฐ (384x512) */
|
| 482 |
@media (min-width: 768px) {
|
|
|
|
| 510 |
max-width: 384px !important;
|
| 511 |
}
|
| 512 |
}
|
| 513 |
+
|
| 514 |
+
/* ImageEditor: ์ด๋ฏธ์ง๋ง ํ๋ ์ ์์ ๋ง์ถ๊ธฐ (UI ์์๋ ๊ฑด๋๋ฆฌ์ง ์์) */
|
| 515 |
+
#image-editor-fixed canvas {
|
| 516 |
+
object-fit: contain !important;
|
| 517 |
+
}
|
| 518 |
+
#image-editor-fixed img {
|
| 519 |
+
object-fit: contain !important;
|
| 520 |
+
max-width: 100% !important;
|
| 521 |
+
max-height: 100% !important;
|
| 522 |
+
}
|
| 523 |
</style>
|
| 524 |
<script>
|
| 525 |
+
// ImageEditor์ canvas ์ค์ ํฝ์
ํฌ๊ธฐ๋ง ๊ณ ์ ํ์ฌ ๋ธ๋ฌ์ ์์น ์ ํ๋ ์ ์ง
|
| 526 |
+
// ํ๋ ์๊ณผ UI ์์๋ Gradio์ ๊ธฐ๋ณธ ๋์์ ๋งก๊น
|
| 527 |
(function() {
|
| 528 |
const CANVAS_WIDTH = 384;
|
| 529 |
const CANVAS_HEIGHT = 512;
|
|
|
|
| 532 |
const editor = document.querySelector('#image-editor-fixed');
|
| 533 |
if (!editor) return;
|
| 534 |
|
| 535 |
+
// ImageEditor ๋ด๋ถ์ ๋ชจ๋ canvas ์ฐพ๊ธฐ
|
| 536 |
+
const canvases = editor.querySelectorAll('canvas');
|
| 537 |
+
canvases.forEach(function(canvas) {
|
| 538 |
+
// canvas์ ์ค์ ํฝ์
ํฌ๊ธฐ๋ ํญ์ ๊ณ ์ (๋ธ๋ฌ์ ์์น ์ ํ๋ ์ ์ง)
|
| 539 |
+
if (canvas.width !== CANVAS_WIDTH || canvas.height !== CANVAS_HEIGHT) {
|
| 540 |
+
canvas.width = CANVAS_WIDTH;
|
| 541 |
+
canvas.height = CANVAS_HEIGHT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 542 |
}
|
| 543 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 544 |
}
|
| 545 |
|
| 546 |
// ์ด๊ธฐ ์คํ
|
| 547 |
+
function init() {
|
| 548 |
+
fixImageEditorCanvas();
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
if (document.readyState === 'loading') {
|
| 552 |
+
document.addEventListener('DOMContentLoaded', init);
|
| 553 |
} else {
|
| 554 |
+
init();
|
| 555 |
}
|
| 556 |
|
| 557 |
// ์ด๋ฏธ์ง ๋ก๋ ํ ์ฌ์ ์ฉ
|
| 558 |
window.addEventListener('load', function() {
|
| 559 |
+
setTimeout(fixImageEditorCanvas, 100);
|
| 560 |
setTimeout(fixImageEditorCanvas, 500);
|
| 561 |
setTimeout(fixImageEditorCanvas, 1500);
|
| 562 |
});
|
|
|
|
| 568 |
resizeTimeout = setTimeout(fixImageEditorCanvas, 300);
|
| 569 |
});
|
| 570 |
|
| 571 |
+
// MutationObserver๋ก ๋์ ๋ณ๊ฒฝ ๊ฐ์ง (ImageEditor๊ฐ ๋์ ์ผ๋ก ๋ก๋๋ ๋)
|
| 572 |
const observer = new MutationObserver(function(mutations) {
|
| 573 |
fixImageEditorCanvas();
|
| 574 |
});
|
|
|
|
| 580 |
observer.observe(editor, {
|
| 581 |
childList: true,
|
| 582 |
subtree: true,
|
| 583 |
+
attributes: false
|
|
|
|
| 584 |
});
|
| 585 |
}
|
| 586 |
}, 1000);
|
|
|
|
| 592 |
gr.Markdown("์ด๋ฏธ์ง๋ 3:4๋น์จ(384x512 ๋๋ 768x1024)๋ก ์ฌ๋ ค์ฃผ์ธ์")
|
| 593 |
with gr.Row():
|
| 594 |
with gr.Column():
|
| 595 |
+
imgs = gr.ImageEditor(sources='upload', type="pil", label='๋์ ์ด๋ฏธ์ง', interactive=True, elem_id="image-editor-fixed")
|
| 596 |
img_url_input = gr.Textbox(label="๋์ ์ด๋ฏธ์ง URL", placeholder="์) https://example.com/human_image.jpg")
|
| 597 |
with gr.Row():
|
| 598 |
with gr.Row():
|