File size: 550 Bytes
a576ea6
 
 
 
bbf2dd1
 
 
 
 
 
 
 
 
a576ea6
 
bbf2dd1
 
 
 
a576ea6
 
bbf2dd1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)