Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ from datetime import datetime
|
|
6 |
from PIL import Image, ImageDraw
|
7 |
from math import cos, sin, radians
|
8 |
|
9 |
-
def create_border_decoration(qr_image,
|
10 |
# Convert QR image to RGB mode first
|
11 |
qr_image = qr_image.convert('RGB')
|
12 |
|
@@ -27,9 +27,9 @@ def create_border_decoration(qr_image, decoration_prompt="๐ธ"):
|
|
27 |
# Get draw object
|
28 |
draw = ImageDraw.Draw(decorated_image)
|
29 |
|
30 |
-
#
|
31 |
-
|
32 |
-
gap =
|
33 |
|
34 |
# ํ
๋๋ฆฌ๋ฅผ ๋ฐ๋ผ ์ ๋ค์ ์์น ๊ณ์ฐ
|
35 |
border_points = []
|
@@ -49,70 +49,97 @@ def create_border_decoration(qr_image, decoration_prompt="๐ธ"):
|
|
49 |
# ์ข์ธก ํ
๋๋ฆฌ
|
50 |
for y in range(new_height - padding//2, padding//2, -gap):
|
51 |
border_points.append((padding//2, y))
|
52 |
-
|
53 |
-
# ๊ฐ
|
54 |
for x, y in border_points:
|
55 |
-
if "
|
|
|
56 |
for angle in range(0, 360, 45):
|
57 |
-
x1 = x +
|
58 |
-
y1 = y +
|
59 |
draw.ellipse([x1-4, y1-4, x1+4, y1+4], fill='pink')
|
|
|
60 |
draw.ellipse([x-3, y-3, x+3, y+3], fill='yellow')
|
61 |
-
|
62 |
-
elif "
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
draw.
|
68 |
-
|
69 |
-
elif "
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
draw.ellipse([x-4, y-8, x+4, y+8], fill='green')
|
89 |
-
|
90 |
-
elif "๐ซ" in decoration_prompt: # ์์ฉ๋์ด
|
91 |
for i in range(5):
|
92 |
-
|
93 |
-
|
94 |
-
x1 = x +
|
95 |
-
y1 = y +
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
draw.
|
106 |
-
|
107 |
-
|
108 |
-
elif "
|
109 |
-
|
110 |
-
for
|
111 |
-
size
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
return decorated_image
|
115 |
|
|
|
|
|
116 |
def create_qr(content, qr_type, fill_color, back_color, box_size, border_size, error_correction, border_decoration="๐ธ Cherry Blossoms"):
|
117 |
# QR ์ฝ๋ ๋ฐ์ดํฐ ํฌ๋งทํ
|
118 |
formatted_data = format_data(content, qr_type)
|
@@ -202,7 +229,7 @@ def format_example_text(qr_type):
|
|
202 |
}
|
203 |
return examples.get(qr_type, "Enter your content here...")
|
204 |
|
205 |
-
|
206 |
def create_interface():
|
207 |
theme = gr.themes.Soft(
|
208 |
primary_hue="blue",
|
@@ -214,6 +241,8 @@ def create_interface():
|
|
214 |
)
|
215 |
|
216 |
with gr.Blocks(theme=theme, title="QR Canvas") as demo:
|
|
|
|
|
217 |
gr.Markdown(
|
218 |
"""
|
219 |
# ๐ฏ QR CANVAS
|
@@ -282,24 +311,25 @@ def create_interface():
|
|
282 |
value="Medium (15%)",
|
283 |
label="Error Correction Level"
|
284 |
)
|
285 |
-
|
286 |
border_decoration = gr.Dropdown(
|
287 |
choices=[
|
288 |
-
"
|
289 |
-
"
|
290 |
-
"
|
291 |
-
"
|
292 |
-
"
|
293 |
-
"
|
294 |
-
"
|
295 |
-
"
|
296 |
-
"
|
297 |
-
"
|
298 |
],
|
299 |
-
value="
|
300 |
label="Border Decoration Style"
|
301 |
)
|
302 |
-
|
|
|
303 |
generate_btn = gr.Button(
|
304 |
"Generate QR Code",
|
305 |
variant="primary"
|
|
|
6 |
from PIL import Image, ImageDraw
|
7 |
from math import cos, sin, radians
|
8 |
|
9 |
+
def create_border_decoration(qr_image, decoration_style="Flowers"):
|
10 |
# Convert QR image to RGB mode first
|
11 |
qr_image = qr_image.convert('RGB')
|
12 |
|
|
|
27 |
# Get draw object
|
28 |
draw = ImageDraw.Draw(decorated_image)
|
29 |
|
30 |
+
# ์ฅ์ ํฌ๊ธฐ ์ค์
|
31 |
+
deco_size = 12
|
32 |
+
gap = deco_size * 2 # ์ฅ์ ์ฌ์ด์ ๊ฐ๊ฒฉ
|
33 |
|
34 |
# ํ
๋๋ฆฌ๋ฅผ ๋ฐ๋ผ ์ ๋ค์ ์์น ๊ณ์ฐ
|
35 |
border_points = []
|
|
|
49 |
# ์ข์ธก ํ
๋๋ฆฌ
|
50 |
for y in range(new_height - padding//2, padding//2, -gap):
|
51 |
border_points.append((padding//2, y))
|
52 |
+
|
53 |
+
# ๊ฐ ์คํ์ผ์ ๋ฐ๋ฅธ ์ฅ์ ๊ทธ๋ฆฌ๊ธฐ
|
54 |
for x, y in border_points:
|
55 |
+
if decoration_style == "Flowers": # ๊ฝ ํจํด
|
56 |
+
# ๊ฝ์
|
57 |
for angle in range(0, 360, 45):
|
58 |
+
x1 = x + deco_size * cos(radians(angle))
|
59 |
+
y1 = y + deco_size * sin(radians(angle))
|
60 |
draw.ellipse([x1-4, y1-4, x1+4, y1+4], fill='pink')
|
61 |
+
# ๊ฝ ์ค์ฌ
|
62 |
draw.ellipse([x-3, y-3, x+3, y+3], fill='yellow')
|
63 |
+
|
64 |
+
elif decoration_style == "Hearts": # ํํธ ํจํด
|
65 |
+
# ์์ ํํธ๋ค์ ์ฐ์์ผ๋ก ๊ทธ๋ฆฌ๊ธฐ
|
66 |
+
heart_size = 6
|
67 |
+
draw.ellipse([x-heart_size, y-heart_size, x, y], fill='red')
|
68 |
+
draw.ellipse([x, y-heart_size, x+heart_size, y], fill='red')
|
69 |
+
draw.polygon([(x-heart_size, y), (x+heart_size, y), (x, y+heart_size)], fill='red')
|
70 |
+
|
71 |
+
elif decoration_style == "Waves": # ์จ์ด๋ธ ํจํด
|
72 |
+
wave_size = 10
|
73 |
+
draw.arc([x-wave_size, y-wave_size//2, x+wave_size, y+wave_size//2],
|
74 |
+
0, 180, fill='lightblue', width=2)
|
75 |
+
draw.arc([x-wave_size, y, x+wave_size, y+wave_size],
|
76 |
+
0, 180, fill='blue', width=2)
|
77 |
+
|
78 |
+
elif decoration_style == "Leaves": # ์ ํจํด
|
79 |
+
leaf_size = 8
|
80 |
+
# ๋ฉ์ธ ์
|
81 |
+
draw.ellipse([x-leaf_size, y-leaf_size//2, x+leaf_size, y+leaf_size//2],
|
82 |
+
fill='lightgreen')
|
83 |
+
# ์์ ์
|
84 |
+
draw.ellipse([x-leaf_size//2, y-leaf_size, x+leaf_size//2, y+leaf_size],
|
85 |
+
fill='darkgreen')
|
86 |
+
|
87 |
+
elif decoration_style == "Stars": # ๋ณ ํจํด
|
88 |
+
star_size = 6
|
89 |
+
points = []
|
|
|
|
|
|
|
90 |
for i in range(5):
|
91 |
+
angle = i * 72
|
92 |
+
# ์ธ๊ณฝ ์
|
93 |
+
x1 = x + star_size * cos(radians(angle))
|
94 |
+
y1 = y + star_size * sin(radians(angle))
|
95 |
+
points.append((x1, y1))
|
96 |
+
# ๋ด๋ถ ์
|
97 |
+
x2 = x + (star_size/2) * cos(radians(angle + 36))
|
98 |
+
y2 = y + (star_size/2) * sin(radians(angle + 36))
|
99 |
+
points.append((x2, y2))
|
100 |
+
draw.polygon(points, fill='gold')
|
101 |
+
|
102 |
+
elif decoration_style == "Chains": # ์ฒด์ธ ํจํด
|
103 |
+
chain_size = 8
|
104 |
+
draw.ellipse([x-chain_size, y-chain_size//2, x+chain_size, y+chain_size//2],
|
105 |
+
outline='gray', width=2)
|
106 |
+
|
107 |
+
elif decoration_style == "Bubbles": # ๋ฒ๋ธ ํจํด
|
108 |
+
bubble_sizes = [6, 4, 2]
|
109 |
+
for size in bubble_sizes:
|
110 |
+
draw.ellipse([x-size, y-size, x+size, y+size],
|
111 |
+
outline='skyblue', width=1)
|
112 |
+
|
113 |
+
elif decoration_style == "Vines": # ๋ฉ๊ตด ํจํด
|
114 |
+
vine_size = 10
|
115 |
+
# ๋ฉ์ธ ๋ฉ๊ตด
|
116 |
+
draw.arc([x-vine_size, y-vine_size, x+vine_size, y+vine_size],
|
117 |
+
0, 180, fill='green', width=2)
|
118 |
+
# ์์ ์
|
119 |
+
draw.ellipse([x-3, y-3, x+3, y+3], fill='lightgreen')
|
120 |
+
|
121 |
+
elif decoration_style == "Diamonds": # ๋ค์ด์๋ชฌ๋ ํจํด
|
122 |
+
diamond_size = 6
|
123 |
+
points = [
|
124 |
+
(x, y-diamond_size), # ์๋จ
|
125 |
+
(x+diamond_size, y), # ์ฐ์ธก
|
126 |
+
(x, y+diamond_size), # ํ๋จ
|
127 |
+
(x-diamond_size, y) # ์ข์ธก
|
128 |
+
]
|
129 |
+
draw.polygon(points, outline='purple', width=1)
|
130 |
+
|
131 |
+
elif decoration_style == "Lace": # ๋ ์ด์ค ํจํด
|
132 |
+
lace_size = 8
|
133 |
+
# ๋ ์ด์ค ์ํ ํจํด
|
134 |
+
draw.arc([x-lace_size, y-lace_size, x+lace_size, y+lace_size],
|
135 |
+
0, 180, fill='gray', width=1)
|
136 |
+
draw.arc([x-lace_size//2, y-lace_size//2, x+lace_size//2, y+lace_size//2],
|
137 |
+
180, 360, fill='gray', width=1)
|
138 |
|
139 |
return decorated_image
|
140 |
|
141 |
+
|
142 |
+
|
143 |
def create_qr(content, qr_type, fill_color, back_color, box_size, border_size, error_correction, border_decoration="๐ธ Cherry Blossoms"):
|
144 |
# QR ์ฝ๋ ๋ฐ์ดํฐ ํฌ๋งทํ
|
145 |
formatted_data = format_data(content, qr_type)
|
|
|
229 |
}
|
230 |
return examples.get(qr_type, "Enter your content here...")
|
231 |
|
232 |
+
|
233 |
def create_interface():
|
234 |
theme = gr.themes.Soft(
|
235 |
primary_hue="blue",
|
|
|
241 |
)
|
242 |
|
243 |
with gr.Blocks(theme=theme, title="QR Canvas") as demo:
|
244 |
+
|
245 |
+
|
246 |
gr.Markdown(
|
247 |
"""
|
248 |
# ๐ฏ QR CANVAS
|
|
|
311 |
value="Medium (15%)",
|
312 |
label="Error Correction Level"
|
313 |
)
|
314 |
+
|
315 |
border_decoration = gr.Dropdown(
|
316 |
choices=[
|
317 |
+
"Flowers", # ๊ฝ ํจํด
|
318 |
+
"Hearts", # ํํธ ํจํด
|
319 |
+
"Waves", # ์จ์ด๋ธ ํจํด
|
320 |
+
"Leaves", # ์ ํจํด
|
321 |
+
"Stars", # ๋ณ ํจํด
|
322 |
+
"Chains", # ์ฒด์ธ ํจํด
|
323 |
+
"Bubbles", # ๋ฒ๋ธ ํจํด
|
324 |
+
"Vines", # ๋ฉ๊ตด ํจํด
|
325 |
+
"Diamonds", # ๋ค์ด์๋ชฌ๋ ํจํด
|
326 |
+
"Lace" # ๋ ์ด์ค ํจํด
|
327 |
],
|
328 |
+
value="Flowers",
|
329 |
label="Border Decoration Style"
|
330 |
)
|
331 |
+
|
332 |
+
|
333 |
generate_btn = gr.Button(
|
334 |
"Generate QR Code",
|
335 |
variant="primary"
|