Adityadn commited on
Commit
b8adac9
·
verified ·
1 Parent(s): 0c98104

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -31
app.py CHANGED
@@ -1,57 +1,45 @@
1
  import qrcode
2
- from PIL import Image
3
  import gradio as gr
4
 
5
- # Function to generate QR code with a logo
6
- def generate_qr_with_logo(data: str, logo_path: str):
 
 
 
 
 
 
7
  # Create the QR code
8
  qr = qrcode.QRCode(
9
  version=1,
10
- error_correction=qrcode.constants.ERROR_CORRECT_H, # High error correction for logo
11
  box_size=10,
12
  border=4,
13
  )
14
- qr.add_data(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
- # # Open the logo image
21
- # logo = Image.open(logo_path) # Provide logo path
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(data: str):
43
- result = generate_qr_with_logo(data)
44
  return result
45
 
46
  # Create a Gradio interface
47
  interface = gr.Interface(
48
  fn=qr_code_interface,
49
- inputs=[
50
- gr.Textbox(label="Enter Data for QR Code", placeholder="Enter URL or text here..."),
51
- # gr.File(label="Upload Logo", type="file") # File input for the logo
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