CoolFace
Apppublic

Alexvatti/QR-Code-Generation

sourceHugging Faceupdated 2y agoView on Hugging Face
1likes
app.py39 linesDownload Raw Back to root
1import qrcode2import gradio as gr3from io import BytesIO4 5def generate_qr(url):6    """Generates a QR code from a given URL and returns the image and download link."""7    qr = qrcode.QRCode(8        version=1,9        error_correction=qrcode.constants.ERROR_CORRECT_L,10        box_size=10,11        border=412    )13    qr.add_data(url)14    qr.make(fit=True)15    16    img = qr.make_image(fill="black", back_color="white")17 18    # Save to BytesIO for download19    img_io = BytesIO()20    img.save(img_io, format="PNG")21    img_io.seek(0)22    23    # Ensure file remains open when accessed24    return img, ("qr_code.png", img_io.getvalue())25 26iface = gr.Interface(27    fn=generate_qr,28    inputs=gr.Textbox(label="Enter URL"),29    outputs=[30        gr.Image(label="Generated QR Code"),31        gr.File(label="Download QR Code")32    ],33    title="QR Code Generator",34    description="Enter a URL to generate and download a QR Code."35)36 37iface.launch()38 39