Spaces:
Sleeping
Sleeping
File size: 882 Bytes
358c8af eabda9e 358c8af |
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 37 38 39 40 41 42 43 44 |
import gradio as gr
import qrcode
from PIL import Image
import numpy as np
def generate_qr_code(url):
# Check if the URL is not empty
if not url:
return "Please enter a URL."
# Create 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)
# Create an image from the QR code data
img = qr.make_image(fill_color="black", back_color="white")
# Convert the image to a numpy array
img_array = np.array(img)
# Convert the numpy array to a PIL Image
img_pil = Image.fromarray(img_array)
return img_pil
iface = gr.Interface(fn=generate_qr_code,
inputs="text",
outputs="image")
iface.launch(debug = True)
|