ssboost commited on
Commit
d1d6c1b
ยท
verified ยท
1 Parent(s): 83f9d7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -41
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(0,0,0,0.08);
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
- transition: box-shadow 0.3s;
46
  }
47
  .image-container:hover {
48
  box-shadow: var(--shadow);
49
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- .footer { visibility: hidden; }
 
 
 
 
 
 
 
 
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
- with gr.Tabs():
98
- with gr.TabItem("์˜ˆ์‹œ ๊ฒฐ๊ณผ ๋ณด๊ธฐ"):
99
- # ๋ฉ”์ธ ๋ทฐ ์ปดํฌ๋„ŒํŠธ ๋จผ์ € ์ •์˜
100
- with gr.Row():
101
- example_input_image = gr.Image(label="์ž…๋ ฅ ์ด๋ฏธ์ง€", elem_classes="image-container")
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.HTML('<div class="section-title"><img src="https://cdn-icons-png.flaticon.com/512/681/681443.png"> ์ƒํ’ˆ ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€ ์˜ˆ์‹œ ๊ฐค๋Ÿฌ๋ฆฌ</div>')
112
- with gr.Row(elem_classes="example-gallery"):
113
- for idx, ex in enumerate(product_background_examples):
114
- item = gr.Image(value=ex[5], show_label=False, elem_classes="example-item")
115
- item.select(fn=load_example, inputs=None,
116
- outputs=[example_input_image,
117
- example_bg_type,
118
- example_bg_option,
119
- example_product_name,
120
- example_additional_info,
121
- example_output_image])
122
-
123
- # ์ฒซ ๋ฒˆ์งธ ์˜ˆ์‹œ ๏ฟฝ๏ฟฝ๋™ ๋กœ๋“œ
124
- demo.load(fn=load_first_example,
125
- outputs=[example_input_image,
126
- example_bg_type,
127
- example_bg_option,
128
- example_product_name,
129
- example_additional_info,
130
- example_output_image])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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%")