schroneko commited on
Commit
bbf2dd1
1 Parent(s): a576ea6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -2,18 +2,21 @@ import gradio as gr
2
  import qrcode
3
  import re
4
 
5
- def generate_qr(url):
6
- if not re.match(r'^https?://', url):
7
- raise gr.Error("Input must be a valid URL")
8
-
9
- qr = qrcode.make(url)
10
- return qr.get_image()
 
 
 
11
 
12
  iface = gr.Interface(
13
- fn=generate_qr,
14
- inputs=gr.Textbox(label="URL"),
15
- outputs="image",
16
- allow_flagging="never"
17
  )
18
 
19
- iface.launch(debug=True)
 
2
  import qrcode
3
  import re
4
 
5
+ def generate_qr(input_text):
6
+ url_pattern = r'^https?://'
7
+ email_pattern = r'^[\w\.-]+@[\w\.-]+\.\w+$'
8
+
9
+ if not re.match(url_pattern, input_text) and not re.match(email_pattern, input_text):
10
+ raise gr.Error("Input must be a valid URL or Email address")
11
+
12
+ qr = qrcode.make(input_text)
13
+ return qr.get_image()
14
 
15
  iface = gr.Interface(
16
+ fn=generate_qr,
17
+ inputs=gr.Textbox(label="URL or Email Address"),
18
+ outputs="image",
19
+ allow_flagging="never"
20
  )
21
 
22
+ iface.launch(debug=True)