Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
import os
|
| 2 |
-
import json
|
| 3 |
import logging
|
| 4 |
from PIL import Image
|
| 5 |
import gradio as gr
|
|
@@ -16,13 +15,17 @@ logger = logging.getLogger(__name__)
|
|
| 16 |
# ์บ์๋ ์ด๋ฏธ์ง ์ ์ฅ์
|
| 17 |
IMAGE_CACHE = {}
|
| 18 |
|
| 19 |
-
# CSS
|
| 20 |
custom_css = """
|
| 21 |
:root {
|
|
|
|
|
|
|
|
|
|
| 22 |
--background-color: #FFFFFF;
|
|
|
|
| 23 |
--text-color: #334155;
|
| 24 |
--border-radius: 18px;
|
| 25 |
-
--shadow: 0 8px 30px rgba(
|
| 26 |
}
|
| 27 |
|
| 28 |
.example-gallery {
|
|
@@ -31,30 +34,75 @@ custom_css = """
|
|
| 31 |
gap: 20px;
|
| 32 |
padding: 20px;
|
| 33 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
.example-item img {
|
| 35 |
width: 100%;
|
| 36 |
height: 120px;
|
| 37 |
object-fit: cover;
|
| 38 |
-
border-radius: var(--border-radius);
|
| 39 |
}
|
| 40 |
|
| 41 |
.image-container {
|
| 42 |
border-radius: var(--border-radius);
|
| 43 |
overflow: hidden;
|
|
|
|
|
|
|
| 44 |
background-color: white;
|
| 45 |
-
|
| 46 |
}
|
| 47 |
.image-container:hover {
|
| 48 |
box-shadow: var(--shadow);
|
| 49 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
"""
|
|
|
|
|
|
|
| 53 |
fontawesome_link = """
|
| 54 |
<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\" />
|
| 55 |
"""
|
| 56 |
|
| 57 |
-
# ์์ ์ด๋ฏธ์ง ์บ์ฑ ๋ฐ ๋ก๋
|
| 58 |
|
| 59 |
def load_image_cached(path):
|
| 60 |
if path not in IMAGE_CACHE:
|
|
@@ -94,43 +142,51 @@ def create_app():
|
|
| 94 |
font=[gr.themes.GoogleFont("Noto Sans KR"), "ui-sans-serif", "system-ui"]
|
| 95 |
)) as demo:
|
| 96 |
gr.HTML(fontawesome_link)
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
with gr.Column():
|
| 103 |
-
example_bg_type = gr.Textbox(label="๋ฐฐ๊ฒฝ ์ ํ", interactive=False)
|
| 104 |
-
example_bg_option = gr.Textbox(label="๋ฐฐ๊ฒฝ ์ ํ", interactive=False)
|
| 105 |
-
example_product_name = gr.Textbox(label="์ํ๋ช
", interactive=False)
|
| 106 |
-
example_additional_info = gr.Textbox(label="์ถ๊ฐ ์์ฒญ์ฌํญ", interactive=False)
|
| 107 |
-
example_output_image = gr.Image(label="๊ฒฐ๊ณผ ์ด๋ฏธ์ง", elem_classes="image-container")
|
| 108 |
-
|
| 109 |
-
# ์์ ๊ฐค๋ฌ๋ฆฌ
|
| 110 |
with gr.Column():
|
| 111 |
-
gr.
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
return demo
|
| 132 |
|
| 133 |
if __name__ == "__main__":
|
| 134 |
preload_example_images()
|
| 135 |
app = create_app()
|
| 136 |
-
app.launch(share=False, inbrowser=True)
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import logging
|
| 3 |
from PIL import Image
|
| 4 |
import gradio as gr
|
|
|
|
| 15 |
# ์บ์๋ ์ด๋ฏธ์ง ์ ์ฅ์
|
| 16 |
IMAGE_CACHE = {}
|
| 17 |
|
| 18 |
+
# ์ปค์คํ
CSS ์คํ์ผ (์๋ณธ๊ณผ ์์ ๋์ผ)
|
| 19 |
custom_css = """
|
| 20 |
:root {
|
| 21 |
+
--primary-color: #FB7F0D;
|
| 22 |
+
--secondary-color: #ff9a8b;
|
| 23 |
+
--accent-color: #FF6B6B;
|
| 24 |
--background-color: #FFFFFF;
|
| 25 |
+
--card-bg: #ffffff;
|
| 26 |
--text-color: #334155;
|
| 27 |
--border-radius: 18px;
|
| 28 |
+
--shadow: 0 8px 30px rgba(251, 127, 13, 0.08);
|
| 29 |
}
|
| 30 |
|
| 31 |
.example-gallery {
|
|
|
|
| 34 |
gap: 20px;
|
| 35 |
padding: 20px;
|
| 36 |
}
|
| 37 |
+
.example-item {
|
| 38 |
+
cursor: pointer;
|
| 39 |
+
border: 1px solid rgba(0, 0, 0, 0.1);
|
| 40 |
+
border-radius: var(--border-radius);
|
| 41 |
+
overflow: hidden;
|
| 42 |
+
transition: all 0.3s ease;
|
| 43 |
+
background: white;
|
| 44 |
+
}
|
| 45 |
+
.example-item:hover {
|
| 46 |
+
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
| 47 |
+
transform: translateY(-2px);
|
| 48 |
+
}
|
| 49 |
.example-item img {
|
| 50 |
width: 100%;
|
| 51 |
height: 120px;
|
| 52 |
object-fit: cover;
|
|
|
|
| 53 |
}
|
| 54 |
|
| 55 |
.image-container {
|
| 56 |
border-radius: var(--border-radius);
|
| 57 |
overflow: hidden;
|
| 58 |
+
border: 1px solid rgba(0, 0, 0, 0.08);
|
| 59 |
+
transition: all 0.3s ease;
|
| 60 |
background-color: white;
|
| 61 |
+
aspect-ratio: 1 / 1;
|
| 62 |
}
|
| 63 |
.image-container:hover {
|
| 64 |
box-shadow: var(--shadow);
|
| 65 |
}
|
| 66 |
+
.image-container img {
|
| 67 |
+
width: 100%;
|
| 68 |
+
height: 100%;
|
| 69 |
+
object-fit: contain;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
.section-title {
|
| 73 |
+
display: flex;
|
| 74 |
+
align-items: center;
|
| 75 |
+
font-size: 20px;
|
| 76 |
+
font-weight: 700;
|
| 77 |
+
color: #333333;
|
| 78 |
+
margin-bottom: 10px;
|
| 79 |
+
padding-bottom: 5px;
|
| 80 |
+
border-bottom: 2px solid #FB7F0D;
|
| 81 |
+
font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
|
| 82 |
+
}
|
| 83 |
+
.section-title img {
|
| 84 |
+
margin-right: 10px;
|
| 85 |
+
width: 24px;
|
| 86 |
+
height: 24px;
|
| 87 |
+
}
|
| 88 |
|
| 89 |
+
body {
|
| 90 |
+
font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
|
| 91 |
+
background-color: var(--background-color);
|
| 92 |
+
color: var(--text-color);
|
| 93 |
+
line-height: 1.6;
|
| 94 |
+
margin: 0;
|
| 95 |
+
padding: 0;
|
| 96 |
+
}
|
| 97 |
+
footer { visibility: hidden; }
|
| 98 |
"""
|
| 99 |
+
|
| 100 |
+
# FontAwesome ๋งํฌ
|
| 101 |
fontawesome_link = """
|
| 102 |
<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\" />
|
| 103 |
"""
|
| 104 |
|
| 105 |
+
# ์์ ์ด๋ฏธ์ง ์บ์ฑ ๋ฐ ๋ก๋ ํจ์
|
| 106 |
|
| 107 |
def load_image_cached(path):
|
| 108 |
if path not in IMAGE_CACHE:
|
|
|
|
| 142 |
font=[gr.themes.GoogleFont("Noto Sans KR"), "ui-sans-serif", "system-ui"]
|
| 143 |
)) as demo:
|
| 144 |
gr.HTML(fontawesome_link)
|
| 145 |
+
# ๋ฉ์ธ ๋ทฐ
|
| 146 |
+
with gr.Column(elem_classes="custom-section-group custom-frame"):
|
| 147 |
+
gr.HTML('<div class="section-title"><img src="https://cdn-icons-png.flaticon.com/512/681/681443.png"> ์ํ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง ์์ ๊ฐค๋ฌ๋ฆฌ</div>')
|
| 148 |
+
with gr.Row():
|
| 149 |
+
example_input_image = gr.Image(label="์
๋ ฅ ์ด๋ฏธ์ง", elem_classes="image-container")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
with gr.Column():
|
| 151 |
+
example_bg_type = gr.Textbox(label="๋ฐฐ๊ฒฝ ์ ํ", interactive=False)
|
| 152 |
+
example_bg_option = gr.Textbox(label="๋ฐฐ๊ฒฝ ์ ํ", interactive=False)
|
| 153 |
+
example_product_name = gr.Textbox(label="์ํ๋ช
", interactive=False)
|
| 154 |
+
example_additional_info = gr.Textbox(label="์ถ๊ฐ ์์ฒญ์ฌํญ", interactive=False)
|
| 155 |
+
example_output_image = gr.Image(label="๊ฒฐ๊ณผ ์ด๋ฏธ์ง", elem_classes="image-container")
|
| 156 |
+
|
| 157 |
+
# ๊ฐค๋ฌ๋ฆฌ ๋ทฐ
|
| 158 |
+
with gr.Column(elem_classes="custom-section-group"):
|
| 159 |
+
with gr.Row(elem_classes="example-gallery"):
|
| 160 |
+
for idx, ex in enumerate(product_background_examples):
|
| 161 |
+
item = gr.Image(value=ex[5], show_label=False, elem_classes="example-item")
|
| 162 |
+
item.select(
|
| 163 |
+
fn=load_example,
|
| 164 |
+
inputs=None,
|
| 165 |
+
outputs=[
|
| 166 |
+
example_input_image,
|
| 167 |
+
example_bg_type,
|
| 168 |
+
example_bg_option,
|
| 169 |
+
example_product_name,
|
| 170 |
+
example_additional_info,
|
| 171 |
+
example_output_image
|
| 172 |
+
]
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
# ์ฒซ ๋ฒ์งธ ์์ ์๋ ๋ก๋
|
| 176 |
+
demo.load(
|
| 177 |
+
fn=load_first_example,
|
| 178 |
+
outputs=[
|
| 179 |
+
example_input_image,
|
| 180 |
+
example_bg_type,
|
| 181 |
+
example_bg_option,
|
| 182 |
+
example_product_name,
|
| 183 |
+
example_additional_info,
|
| 184 |
+
example_output_image
|
| 185 |
+
]
|
| 186 |
+
)
|
| 187 |
return demo
|
| 188 |
|
| 189 |
if __name__ == "__main__":
|
| 190 |
preload_example_images()
|
| 191 |
app = create_app()
|
| 192 |
+
app.launch(share=False, inbrowser=True, width="100%")
|