Delete app-backup.py
Browse files- app-backup.py +0 -286
app-backup.py
DELETED
|
@@ -1,286 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
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(
|
| 10 |
-
content,
|
| 11 |
-
qr_type,
|
| 12 |
-
fill_color,
|
| 13 |
-
back_color,
|
| 14 |
-
box_size,
|
| 15 |
-
border_size,
|
| 16 |
-
error_correction
|
| 17 |
-
):
|
| 18 |
-
# QR ์ฝ๋ ๋ฐ์ดํฐ ํฌ๋งทํ
|
| 19 |
-
formatted_data = format_data(content, qr_type)
|
| 20 |
-
|
| 21 |
-
# ์๋ฌ ์์ ๋ ๋ฒจ ์ค์
|
| 22 |
-
error_levels = {
|
| 23 |
-
"Low (7%)": qrcode.constants.ERROR_CORRECT_L,
|
| 24 |
-
"Medium (15%)": qrcode.constants.ERROR_CORRECT_M,
|
| 25 |
-
"Quartile (25%)": qrcode.constants.ERROR_CORRECT_Q,
|
| 26 |
-
"High (30%)": qrcode.constants.ERROR_CORRECT_H
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
# QR ์ฝ๋ ์์ฑ
|
| 30 |
-
qr = qrcode.QRCode(
|
| 31 |
-
version=1,
|
| 32 |
-
error_correction=error_levels[error_correction],
|
| 33 |
-
box_size=box_size,
|
| 34 |
-
border=border_size,
|
| 35 |
-
)
|
| 36 |
-
|
| 37 |
-
qr.add_data(formatted_data)
|
| 38 |
-
qr.make(fit=True)
|
| 39 |
-
|
| 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)
|
| 46 |
-
filename = f"qrfile/qr_{timestamp}_{random_id}.png"
|
| 47 |
-
|
| 48 |
-
# ๋๋ ํ ๋ฆฌ ํ์ธ ๋ฐ ์์ฑ
|
| 49 |
-
os.makedirs("qrfile", exist_ok=True)
|
| 50 |
-
|
| 51 |
-
# ์ด๋ฏธ์ง ์ ์ฅ
|
| 52 |
-
qr_img.save(filename)
|
| 53 |
-
cleanup_old_files("qrfile/", max_files=100)
|
| 54 |
-
|
| 55 |
-
return filename, formatted_data
|
| 56 |
-
|
| 57 |
-
# ๋ฐ์ดํฐ ํฌ๋งทํ
ํจ์
|
| 58 |
-
def format_data(content, qr_type):
|
| 59 |
-
if not content:
|
| 60 |
-
return ""
|
| 61 |
-
|
| 62 |
-
format_rules = {
|
| 63 |
-
"URL": lambda x: f"https://{x}" if not x.startswith(('http://', 'https://')) else x,
|
| 64 |
-
"Email": lambda x: f"mailto:{x}",
|
| 65 |
-
"Phone": lambda x: f"tel:{x}",
|
| 66 |
-
"SMS": lambda x: f"sms:{x}",
|
| 67 |
-
"WhatsApp": lambda x: f"whatsapp://send?text={x}",
|
| 68 |
-
"Location": lambda x: f"geo:{x}",
|
| 69 |
-
"Wi-Fi": lambda x: f"WIFI:S:{x};;",
|
| 70 |
-
"Text": lambda x: x,
|
| 71 |
-
"vCard": lambda x: f"BEGIN:VCARD\nVERSION:3.0\n{x}\nEND:VCARD"
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
return format_rules[qr_type](content.strip())
|
| 75 |
-
|
| 76 |
-
# ํ์ผ ์ ๋ฆฌ ํจ์
|
| 77 |
-
def cleanup_old_files(directory, max_files):
|
| 78 |
-
files = [f for f in os.listdir(directory) if f.endswith('.png')]
|
| 79 |
-
if len(files) > max_files:
|
| 80 |
-
files.sort(key=lambda x: os.path.getctime(os.path.join(directory, x)))
|
| 81 |
-
for f in files[:-max_files]:
|
| 82 |
-
try:
|
| 83 |
-
os.remove(os.path.join(directory, f))
|
| 84 |
-
except:
|
| 85 |
-
continue
|
| 86 |
-
|
| 87 |
-
def get_example_placeholder(qr_type):
|
| 88 |
-
examples = {
|
| 89 |
-
"URL": "example.com or https://example.com",
|
| 90 |
-
"Email": "example@email.com",
|
| 91 |
-
"Phone": "+1234567890",
|
| 92 |
-
"SMS": "+1234567890",
|
| 93 |
-
"WhatsApp": "Hello World!",
|
| 94 |
-
"Location": "37.7749,-122.4194",
|
| 95 |
-
"Wi-Fi": "MyWiFiNetwork",
|
| 96 |
-
"Text": "Any text you want to encode",
|
| 97 |
-
"vCard": "FN:John Doe\nTEL:+1234567890\nEMAIL:john@example.com"
|
| 98 |
-
}
|
| 99 |
-
return examples.get(qr_type, "Enter your content here...")
|
| 100 |
-
|
| 101 |
-
def format_example_text(qr_type):
|
| 102 |
-
examples = {
|
| 103 |
-
"URL": "โข Direct URL: https://example.com\nโข Without https: example.com",
|
| 104 |
-
"Email": "โข Basic: example@email.com\nโข With subject: example@email.com?subject=Hello",
|
| 105 |
-
"Phone": "โข International: +1234567890\nโข Local: 01012345678",
|
| 106 |
-
"SMS": "โข Basic: +1234567890\nโข With message: +1234567890?body=Hello",
|
| 107 |
-
"WhatsApp": "โข Message: Hello World!\nโข With number: +1234567890:Hello",
|
| 108 |
-
"Location": "โข Coordinates: 37.7749,-122.4194\nโข With zoom: 37.7749,-122.4194,15z",
|
| 109 |
-
"Wi-Fi": "โข Network name only: MyWiFiNetwork\nโข With password: WIFI:S:MyNetwork;P:password;;",
|
| 110 |
-
"Text": "โข Simple text: Hello World!\nโข Multiple lines: Line 1\\nLine 2",
|
| 111 |
-
"vCard": "โข Basic:\nFN:John Doe\nTEL:+1234567890\nEMAIL:john@example.com\nโข Extended:\nFN:John Doe\nTEL:+1234567890\nEMAIL:john@example.com\nADR:;;123 Street;City;State;12345;Country"
|
| 112 |
-
}
|
| 113 |
-
return examples.get(qr_type, "Enter your content here...")
|
| 114 |
-
|
| 115 |
-
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
| 116 |
-
def create_interface():
|
| 117 |
-
# ํ
๋ง ์ค์
|
| 118 |
-
theme = gr.themes.Soft(
|
| 119 |
-
primary_hue="blue",
|
| 120 |
-
secondary_hue="indigo",
|
| 121 |
-
).set(
|
| 122 |
-
body_background_fill="*neutral_50",
|
| 123 |
-
block_background_fill="*neutral_100",
|
| 124 |
-
button_primary_background_fill="*primary_500",
|
| 125 |
-
)
|
| 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
|
| 134 |
-
Create customized QR codes for various purposes with professional styling options.
|
| 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):
|
| 146 |
-
# ์
๋ ฅ ์น์
|
| 147 |
-
qr_type = gr.Dropdown(
|
| 148 |
-
choices=[
|
| 149 |
-
"URL",
|
| 150 |
-
"Email",
|
| 151 |
-
"Phone",
|
| 152 |
-
"SMS",
|
| 153 |
-
"WhatsApp",
|
| 154 |
-
"Location",
|
| 155 |
-
"Wi-Fi",
|
| 156 |
-
"Text",
|
| 157 |
-
"vCard"
|
| 158 |
-
],
|
| 159 |
-
value="URL",
|
| 160 |
-
label="QR Code Type"
|
| 161 |
-
)
|
| 162 |
-
|
| 163 |
-
content = gr.Textbox(
|
| 164 |
-
label="Content",
|
| 165 |
-
placeholder="Enter your content here...",
|
| 166 |
-
lines=3
|
| 167 |
-
)
|
| 168 |
-
|
| 169 |
-
example_format = gr.Textbox(
|
| 170 |
-
value=format_example_text("URL"),
|
| 171 |
-
label="Format Examples",
|
| 172 |
-
interactive=False,
|
| 173 |
-
lines=6
|
| 174 |
-
)
|
| 175 |
-
|
| 176 |
-
with gr.Row():
|
| 177 |
-
fill_color = gr.ColorPicker(
|
| 178 |
-
label="QR Code Color",
|
| 179 |
-
value="#000000"
|
| 180 |
-
)
|
| 181 |
-
back_color = gr.ColorPicker(
|
| 182 |
-
label="Background Color",
|
| 183 |
-
value="#FFFFFF"
|
| 184 |
-
)
|
| 185 |
-
|
| 186 |
-
with gr.Row():
|
| 187 |
-
box_size = gr.Slider(
|
| 188 |
-
minimum=1,
|
| 189 |
-
maximum=20,
|
| 190 |
-
value=10,
|
| 191 |
-
step=1,
|
| 192 |
-
label="QR Code Size"
|
| 193 |
-
)
|
| 194 |
-
border_size = gr.Slider(
|
| 195 |
-
minimum=0,
|
| 196 |
-
maximum=10,
|
| 197 |
-
value=4,
|
| 198 |
-
step=1,
|
| 199 |
-
label="Border Size"
|
| 200 |
-
)
|
| 201 |
-
|
| 202 |
-
error_correction = gr.Dropdown(
|
| 203 |
-
choices=[
|
| 204 |
-
"Low (7%)",
|
| 205 |
-
"Medium (15%)",
|
| 206 |
-
"Quartile (25%)",
|
| 207 |
-
"High (30%)"
|
| 208 |
-
],
|
| 209 |
-
value="Medium (15%)",
|
| 210 |
-
label="Error Correction Level"
|
| 211 |
-
)
|
| 212 |
-
|
| 213 |
-
generate_btn = gr.Button(
|
| 214 |
-
"Generate QR Code",
|
| 215 |
-
variant="primary"
|
| 216 |
-
)
|
| 217 |
-
|
| 218 |
-
with gr.Column(scale=1):
|
| 219 |
-
# ์ถ๋ ฅ ์น์
|
| 220 |
-
output_image = gr.Image(
|
| 221 |
-
label="Generated QR Code",
|
| 222 |
-
type="filepath"
|
| 223 |
-
)
|
| 224 |
-
output_data = gr.Textbox(
|
| 225 |
-
label="Formatted Data",
|
| 226 |
-
interactive=False
|
| 227 |
-
)
|
| 228 |
-
|
| 229 |
-
def update_example(qr_type):
|
| 230 |
-
return format_example_text(qr_type)
|
| 231 |
-
|
| 232 |
-
# ์ด๋ฒคํธ ํธ๋ค๋ฌ
|
| 233 |
-
qr_type.change(
|
| 234 |
-
fn=update_example,
|
| 235 |
-
inputs=[qr_type],
|
| 236 |
-
outputs=example_format
|
| 237 |
-
)
|
| 238 |
-
|
| 239 |
-
generate_btn.click(
|
| 240 |
-
fn=create_qr,
|
| 241 |
-
inputs=[
|
| 242 |
-
content,
|
| 243 |
-
qr_type,
|
| 244 |
-
fill_color,
|
| 245 |
-
back_color,
|
| 246 |
-
box_size,
|
| 247 |
-
border_size,
|
| 248 |
-
error_correction
|
| 249 |
-
],
|
| 250 |
-
outputs=[output_image, output_data]
|
| 251 |
-
)
|
| 252 |
-
|
| 253 |
-
# ์ฌ์ฉ ์๋ด
|
| 254 |
-
gr.Markdown(
|
| 255 |
-
"""
|
| 256 |
-
### ๐ Instructions
|
| 257 |
-
1. Select the QR code type from the dropdown menu
|
| 258 |
-
2. Enter your content following the format examples shown
|
| 259 |
-
3. Customize the appearance using the color pickers and sliders
|
| 260 |
-
4. Click 'Generate QR Code' to create your custom QR code
|
| 261 |
-
|
| 262 |
-
### ๐ก Tips
|
| 263 |
-
- Use higher error correction levels for better scan reliability
|
| 264 |
-
- Ensure sufficient contrast between QR code and background colors
|
| 265 |
-
- Keep the content concise for better readability
|
| 266 |
-
- Follow the format examples for best results
|
| 267 |
-
"""
|
| 268 |
-
)
|
| 269 |
-
|
| 270 |
-
return demo
|
| 271 |
-
|
| 272 |
-
if __name__ == "__main__":
|
| 273 |
-
try:
|
| 274 |
-
# ์ถ๋ ฅ ๋๋ ํ ๋ฆฌ ์์ฑ
|
| 275 |
-
os.makedirs("qrfile", exist_ok=True)
|
| 276 |
-
|
| 277 |
-
# ์ธํฐํ์ด์ค ์์ฑ ๋ฐ ์คํ
|
| 278 |
-
demo = create_interface()
|
| 279 |
-
demo.launch(
|
| 280 |
-
server_name="0.0.0.0", # ๋ชจ๋ IP์์ ์ ๊ทผ ๊ฐ๋ฅ
|
| 281 |
-
server_port=7860, # ํฌํธ ์ง์
|
| 282 |
-
share=True, # ๊ณต์ ๋งํฌ ์์ฑ
|
| 283 |
-
debug=True # ๋๋ฒ๊ทธ ๋ชจ๋ ํ์ฑํ
|
| 284 |
-
)
|
| 285 |
-
except Exception as e:
|
| 286 |
-
print(f"Error starting the application: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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