Spaces:
Sleeping
Sleeping
File size: 962 Bytes
2f22acd 2b0226f 2f22acd 2b0226f 3cbd884 2b0226f 3cbd884 2b0226f 2f22acd 3cbd884 2f22acd 66e8fda 2f22acd 2b0226f 2f22acd 66e8fda 2f22acd 3cbd884 | 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 45 46 47 | import gradio as gr
import qrcode
from PIL import Image
def generate_qr(text):
if not text or text.strip() == "":
return None
try:
qr = qrcode.QRCode(
version=1,
box_size=10,
border=5
)
qr.add_data(text)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
# 🔥 IMPORTANT FIX: convert to pure PIL Image
img = img.convert("RGB")
return img
except Exception as e:
print("ERROR:", e) # shows in logs
return None
with gr.Blocks() as demo:
gr.Markdown("# 🔳 QR Code Generator")
text_input = gr.Textbox(
placeholder="Enter text or URL...",
label="Input Data"
)
btn = gr.Button("Generate QR")
qr_output = gr.Image(type="pil", label="QR Code")
btn.click(
fn=generate_qr,
inputs=text_input,
outputs=qr_output
)
demo.launch() |