Kvikontent commited on
Commit
de237db
·
1 Parent(s): 1be3839

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -32
app.py CHANGED
@@ -1,46 +1,30 @@
1
  import gradio as gr
2
  import qrcode
3
- from PIL import Image, ImageDraw
4
- import io
5
 
6
-
7
- def generate_qr_code(url, logo, qr_color):
8
- # Create QR code instance
9
  qr = qrcode.QRCode(
10
  version=1,
11
  error_correction=qrcode.constants.ERROR_CORRECT_L,
12
  box_size=10,
13
  border=4,
14
  )
15
-
16
- # Add URL to the QR code
17
  qr.add_data(url)
18
  qr.make(fit=True)
 
 
 
 
 
19
 
20
- # Create the QR code image
21
- qr_image = qr.make_image(fill_color=qr_color, back_color="#ffffff") # Set QR code color here
22
-
23
- # Add logo if provided
24
- if logo and len(logo) > 0:
25
- logo_image = Image.open(logo[0]).convert("RGBA")
26
- qr_image.paste(logo_image, (125, 125), logo_image)
27
-
28
- return qr_image
29
-
30
-
31
- inputs = [
32
- gr.Textbox(label="URL to Site"),
33
- gr.inputs.Image(label="Logo (Optional)"),
34
- gr.ColorPicker(label="QR Code Color"),
35
- ]
36
-
37
- outputs = gr.outputs.Image(type="pil")
38
-
39
- gr.Interface(
40
  fn=generate_qr_code,
41
- inputs=inputs,
42
- outputs=outputs,
43
  title="QR Code Generator",
44
- description="Generate QR codes with customizable options",
45
- theme="huggingface",
46
- ).launch(share=True)
 
 
 
1
  import gradio as gr
2
  import qrcode
 
 
3
 
4
+ def generate_qr_code(url):
5
+ # Create a QR code instance
 
6
  qr = qrcode.QRCode(
7
  version=1,
8
  error_correction=qrcode.constants.ERROR_CORRECT_L,
9
  box_size=10,
10
  border=4,
11
  )
12
+ # Add data to the QR code
 
13
  qr.add_data(url)
14
  qr.make(fit=True)
15
+ # Generate the QR code image
16
+ qr_image = qr.make_image(fill_color="black", back_color="white")
17
+ # Save the QR code image to a file
18
+ qr_image.save("qr_code.png")
19
+ return "qr_code.png"
20
 
21
+ iface = gr.Interface(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  fn=generate_qr_code,
23
+ inputs="text",
24
+ outputs="file",
25
  title="QR Code Generator",
26
+ description="Generate a QR code from a URL",
27
+ example="https://www.example.com",
28
+ )
29
+
30
+ iface.launch()