Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,18 +2,21 @@ import gradio as gr
|
|
2 |
import qrcode
|
3 |
import re
|
4 |
|
5 |
-
def generate_qr(
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
11 |
|
12 |
iface = gr.Interface(
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
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)
|