qrcode-maker / app.py
abhijitdas2821's picture
Update app.py
2b0226f verified
raw
history blame contribute delete
962 Bytes
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()