QRCodeGenerator / app.py
schroneko's picture
Update app.py
bbf2dd1
raw
history blame
550 Bytes
import gradio as gr
import qrcode
import re
def generate_qr(input_text):
url_pattern = r'^https?://'
email_pattern = r'^[\w\.-]+@[\w\.-]+\.\w+$'
if not re.match(url_pattern, input_text) and not re.match(email_pattern, input_text):
raise gr.Error("Input must be a valid URL or Email address")
qr = qrcode.make(input_text)
return qr.get_image()
iface = gr.Interface(
fn=generate_qr,
inputs=gr.Textbox(label="URL or Email Address"),
outputs="image",
allow_flagging="never"
)
iface.launch(debug=True)