Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,57 +1,45 @@
|
|
1 |
import qrcode
|
2 |
-
|
3 |
import gradio as gr
|
4 |
|
5 |
-
# Function to generate QR code
|
6 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
# Create the QR code
|
8 |
qr = qrcode.QRCode(
|
9 |
version=1,
|
10 |
-
error_correction=qrcode.constants.
|
11 |
box_size=10,
|
12 |
border=4,
|
13 |
)
|
14 |
-
qr.add_data(
|
15 |
qr.make(fit=True)
|
16 |
|
17 |
# Create an image for the QR code
|
18 |
img_qr = qr.make_image(fill='black', back_color='white')
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
-
# logo_size = 50 # Adjust size of the logo
|
23 |
-
# logo = logo.resize((logo_size, logo_size))
|
24 |
-
|
25 |
-
# # Get QR code dimensions
|
26 |
-
# qr_width, qr_height = img_qr.size
|
27 |
-
|
28 |
-
# # Calculate logo position to center it
|
29 |
-
# logo_x = (qr_width - logo_size) // 2
|
30 |
-
# logo_y = (qr_height - logo_size) // 2
|
31 |
-
|
32 |
-
# # Paste the logo onto the QR code
|
33 |
-
# img_qr.paste(logo, (logo_x, logo_y), logo)
|
34 |
-
|
35 |
-
# Save and return the final QR code with logo
|
36 |
-
output_path = "qr_with_logo.png"
|
37 |
img_qr.save(output_path)
|
38 |
|
39 |
return output_path
|
40 |
|
41 |
-
# Gradio Interface
|
42 |
-
def qr_code_interface(
|
43 |
-
result =
|
44 |
return result
|
45 |
|
46 |
# Create a Gradio interface
|
47 |
interface = gr.Interface(
|
48 |
fn=qr_code_interface,
|
49 |
-
inputs=
|
50 |
-
|
51 |
-
|
52 |
-
],
|
53 |
-
outputs=gr.Image(type="file", label="Generated QR Code with Logo"),
|
54 |
-
description="Generate a QR Code with your custom logo placed in the center. You can provide any text or URL as data and upload an image to be used as the logo.",
|
55 |
css="footer {visibility: hidden}"
|
56 |
)
|
57 |
|
|
|
1 |
import qrcode
|
2 |
+
import urllib.parse
|
3 |
import gradio as gr
|
4 |
|
5 |
+
# Function to process text and generate QR code
|
6 |
+
def txt2qrcode(text: str):
|
7 |
+
# Encode the text as URL-safe base64 or URL encoding
|
8 |
+
encoded_text = urllib.parse.quote(text) # URL encoding the input text
|
9 |
+
|
10 |
+
# Construct the final URL to embed into the QR code
|
11 |
+
final_url = f"https://flowly-ai.vercel.app/tools/qr/pro-qr-codes/read/{encoded_text}"
|
12 |
+
|
13 |
# Create the QR code
|
14 |
qr = qrcode.QRCode(
|
15 |
version=1,
|
16 |
+
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
17 |
box_size=10,
|
18 |
border=4,
|
19 |
)
|
20 |
+
qr.add_data(final_url)
|
21 |
qr.make(fit=True)
|
22 |
|
23 |
# Create an image for the QR code
|
24 |
img_qr = qr.make_image(fill='black', back_color='white')
|
25 |
|
26 |
+
# Save the QR code image and return the path
|
27 |
+
output_path = "qr_code.png"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
img_qr.save(output_path)
|
29 |
|
30 |
return output_path
|
31 |
|
32 |
+
# Gradio Interface for the QR code generation
|
33 |
+
def qr_code_interface(text: str):
|
34 |
+
result = txt2qrcode(text)
|
35 |
return result
|
36 |
|
37 |
# Create a Gradio interface
|
38 |
interface = gr.Interface(
|
39 |
fn=qr_code_interface,
|
40 |
+
inputs=gr.Textbox(label="Enter Text to Encode", placeholder="Enter your text here..."),
|
41 |
+
outputs=gr.Image(type="file", label="Generated QR Code"),
|
42 |
+
description="Generate a QR Code from your text. The input text will be URL encoded and embedded into a QR code pointing to a specific URL.",
|
|
|
|
|
|
|
43 |
css="footer {visibility: hidden}"
|
44 |
)
|
45 |
|