Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,46 @@ import qrcode
|
|
3 |
import random
|
4 |
import os
|
5 |
from datetime import datetime
|
6 |
-
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
# QR ์ฝ๋ ์์ฑ์ ์ํ ๋ฉ์ธ ํจ์
|
9 |
def create_qr(
|
@@ -13,7 +52,8 @@ def create_qr(
|
|
13 |
back_color,
|
14 |
box_size,
|
15 |
border_size,
|
16 |
-
error_correction
|
|
|
17 |
):
|
18 |
# QR ์ฝ๋ ๋ฐ์ดํฐ ํฌ๋งทํ
|
19 |
formatted_data = format_data(content, qr_type)
|
@@ -40,6 +80,10 @@ def create_qr(
|
|
40 |
# QR ์ด๋ฏธ์ง ์์ฑ
|
41 |
qr_img = qr.make_image(fill_color=fill_color, back_color=back_color)
|
42 |
|
|
|
|
|
|
|
|
|
43 |
# ํ์ผ ์ ์ฅ
|
44 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
45 |
random_id = random.randint(1000, 9999)
|
@@ -126,8 +170,6 @@ def create_interface():
|
|
126 |
|
127 |
# ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
128 |
with gr.Blocks(theme=theme, title="QR Canvas") as demo:
|
129 |
-
|
130 |
-
# Inside create_interface() function, fixing the indentation:
|
131 |
gr.Markdown(
|
132 |
"""
|
133 |
# ๐ฏ QR CANVAS
|
@@ -135,11 +177,9 @@ def create_interface():
|
|
135 |
"""
|
136 |
)
|
137 |
|
138 |
-
# Fixed indentation to match the surrounding block
|
139 |
gr.HTML("""<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fginipick-QR-Canvas.hf.space">
|
140 |
<img src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fginipick-QR-Canvas.hf.space&countColor=%23263759" />
|
141 |
</a>""")
|
142 |
-
|
143 |
|
144 |
with gr.Row():
|
145 |
with gr.Column(scale=2):
|
@@ -199,6 +239,17 @@ def create_interface():
|
|
199 |
label="Border Size"
|
200 |
)
|
201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
error_correction = gr.Dropdown(
|
203 |
choices=[
|
204 |
"Low (7%)",
|
@@ -245,7 +296,8 @@ def create_interface():
|
|
245 |
back_color,
|
246 |
box_size,
|
247 |
border_size,
|
248 |
-
error_correction
|
|
|
249 |
],
|
250 |
outputs=[output_image, output_data]
|
251 |
)
|
|
|
3 |
import random
|
4 |
import os
|
5 |
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, decoration_type="flowers"):
|
10 |
+
# Get the size of the QR code image
|
11 |
+
width, height = qr_image.size
|
12 |
+
|
13 |
+
# Create a new image with padding for decoration
|
14 |
+
padding = 50 # Padding for decoration
|
15 |
+
new_width = width + (padding * 2)
|
16 |
+
new_height = height + (padding * 2)
|
17 |
+
|
18 |
+
# Create new image with white background
|
19 |
+
decorated_image = Image.new('RGB', (new_width, new_height), 'white')
|
20 |
+
|
21 |
+
# Paste QR code in center
|
22 |
+
decorated_image.paste(qr_image, (padding, padding))
|
23 |
+
|
24 |
+
# Get draw object
|
25 |
+
draw = ImageDraw.Draw(decorated_image)
|
26 |
+
|
27 |
+
if decoration_type == "flowers":
|
28 |
+
# Draw simple flower patterns in corners
|
29 |
+
corner_positions = [
|
30 |
+
(padding//2, padding//2), # Top-left
|
31 |
+
(new_width - padding//2, padding//2), # Top-right
|
32 |
+
(padding//2, new_height - padding//2), # Bottom-left
|
33 |
+
(new_width - padding//2, new_height - padding//2) # Bottom-right
|
34 |
+
]
|
35 |
+
|
36 |
+
for x, y in corner_positions:
|
37 |
+
# Draw flower (simple version)
|
38 |
+
petal_size = 15
|
39 |
+
for angle in range(0, 360, 45): # 8 petals
|
40 |
+
x1 = x + petal_size * cos(radians(angle))
|
41 |
+
y1 = y + petal_size * sin(radians(angle))
|
42 |
+
draw.ellipse([x1-5, y1-5, x1+5, y1+5], fill='lightpink')
|
43 |
+
draw.ellipse([x-5, y-5, x+5, y+5], fill='yellow') # Center of flower
|
44 |
+
|
45 |
+
return decorated_image
|
46 |
|
47 |
# QR ์ฝ๋ ์์ฑ์ ์ํ ๋ฉ์ธ ํจ์
|
48 |
def create_qr(
|
|
|
52 |
back_color,
|
53 |
box_size,
|
54 |
border_size,
|
55 |
+
error_correction,
|
56 |
+
border_decoration="flowers" # New parameter
|
57 |
):
|
58 |
# QR ์ฝ๋ ๋ฐ์ดํฐ ํฌ๋งทํ
|
59 |
formatted_data = format_data(content, qr_type)
|
|
|
80 |
# QR ์ด๋ฏธ์ง ์์ฑ
|
81 |
qr_img = qr.make_image(fill_color=fill_color, back_color=back_color)
|
82 |
|
83 |
+
# Add border decoration if specified
|
84 |
+
if border_decoration != "none":
|
85 |
+
qr_img = create_border_decoration(qr_img, border_decoration)
|
86 |
+
|
87 |
# ํ์ผ ์ ์ฅ
|
88 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
89 |
random_id = random.randint(1000, 9999)
|
|
|
170 |
|
171 |
# ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
172 |
with gr.Blocks(theme=theme, title="QR Canvas") as demo:
|
|
|
|
|
173 |
gr.Markdown(
|
174 |
"""
|
175 |
# ๐ฏ QR CANVAS
|
|
|
177 |
"""
|
178 |
)
|
179 |
|
|
|
180 |
gr.HTML("""<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fginipick-QR-Canvas.hf.space">
|
181 |
<img src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fginipick-QR-Canvas.hf.space&countColor=%23263759" />
|
182 |
</a>""")
|
|
|
183 |
|
184 |
with gr.Row():
|
185 |
with gr.Column(scale=2):
|
|
|
239 |
label="Border Size"
|
240 |
)
|
241 |
|
242 |
+
border_decoration = gr.Dropdown(
|
243 |
+
choices=[
|
244 |
+
"none",
|
245 |
+
"flowers",
|
246 |
+
"simple",
|
247 |
+
"modern"
|
248 |
+
],
|
249 |
+
value="flowers",
|
250 |
+
label="Border Decoration"
|
251 |
+
)
|
252 |
+
|
253 |
error_correction = gr.Dropdown(
|
254 |
choices=[
|
255 |
"Low (7%)",
|
|
|
296 |
back_color,
|
297 |
box_size,
|
298 |
border_size,
|
299 |
+
error_correction,
|
300 |
+
border_decoration
|
301 |
],
|
302 |
outputs=[output_image, output_data]
|
303 |
)
|