File size: 865 Bytes
7324c34
cee8667
6a5e75e
 
1d0a868
de237db
 
7324c34
 
e992434
7324c34
cee8667
7324c34
de237db
7324c34
 
de237db
 
6a5e75e
 
 
 
 
 
 
7324c34
de237db
e992434
de237db
6a5e75e
cee8667
de237db
 
 
 
6a5e75e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gradio as gr
import qrcode
from PIL import Image
from io import BytesIO

def generate_qr_code(url):
    # Create a QR code instance
    qr = qrcode.QRCode(
        version=1,
        error_correction=qrcode.constants.ERROR_CORRECT_L,
        box_size=10,
        border=4,
    )
    # Add data to the QR code
    qr.add_data(url)
    qr.make(fit=True)
    # Generate the QR code image
    qr_image = qr.make_image(fill_color="black", back_color="white")
    
    # Convert PIL image to bytes
    image_bytes = BytesIO()
    qr_image.save(image_bytes, format="PNG")
    image_bytes = image_bytes.getvalue()
    
    return image_bytes

iface = gr.Interface(
    fn=generate_qr_code,
    inputs="text",
    outputs="image",
    title="QR Code Generator",
    description="Generate a QR code from a URL",
    example="https://www.example.com",
)

iface.launch()