Spaces:
Running
Running
DEV_FINWIZ
commited on
Commit
·
6c7bd54
1
Parent(s):
3d0ea4e
initialcommit
Browse files- Driver.py +44 -0
- QR_Generator.py +65 -0
Driver.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from distutils.command.upload import upload
|
2 |
+
import gradio as gr
|
3 |
+
from QR_Generator import generate_qr
|
4 |
+
import qrcode
|
5 |
+
|
6 |
+
def tutorial():
|
7 |
+
url="https://github.com/devfinwiz/Dynamic-QRCode-Generator/raw/master/Tutorial.mp4"
|
8 |
+
QRcode = qrcode.QRCode(version=1,box_size=12,
|
9 |
+
error_correction=qrcode.constants.ERROR_CORRECT_H
|
10 |
+
)
|
11 |
+
# adding URL or text to QRcode
|
12 |
+
QRcode.add_data(url)
|
13 |
+
# generating QR code
|
14 |
+
QRcode.make()
|
15 |
+
# adding color to QR code
|
16 |
+
QRimg = QRcode.make_image(fill_color="white",back_color="black").convert('RGB')
|
17 |
+
|
18 |
+
#QRimg.save('Tutorial.png')
|
19 |
+
return QRimg
|
20 |
+
|
21 |
+
|
22 |
+
with gr.Blocks(title="QR Code Generator",css="#heading{background-color:#32a8a8}") as demo:
|
23 |
+
|
24 |
+
gr.Label(elem_id="heading",value="QR CODE GENERATOR",label="Title")
|
25 |
+
|
26 |
+
with gr.Tab("Input"):
|
27 |
+
text_input = gr.Textbox(label="URL",placeholder="URL To Be Mapped To QR code")
|
28 |
+
color_input = gr.ColorPicker(label="Pick A Color")
|
29 |
+
status=gr.Textbox(label="Status")
|
30 |
+
text_button = gr.Button("Generate QR Code",elem_id="generate_qr")
|
31 |
+
|
32 |
+
with gr.Tab("Output"):
|
33 |
+
with gr.Row():
|
34 |
+
image_output = gr.Image(label="QR Code").style(height=350,width=500)
|
35 |
+
|
36 |
+
with gr.Tab("View Demo"):
|
37 |
+
with gr.Row():
|
38 |
+
tut_button=gr.Button("View Demo Usage")
|
39 |
+
demo_video = gr.Image(label="Demo").style(height=350,width=500)
|
40 |
+
|
41 |
+
tut_button.click(tutorial,inputs=[],outputs=[demo_video])
|
42 |
+
text_button.click(generate_qr, inputs=[text_input,color_input], outputs=[status,image_output])
|
43 |
+
|
44 |
+
demo.launch(share=True)
|
QR_Generator.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from distutils.version import Version
|
2 |
+
from turtle import width
|
3 |
+
import qrcode
|
4 |
+
from PIL import Image
|
5 |
+
import requests
|
6 |
+
|
7 |
+
flag=0
|
8 |
+
|
9 |
+
def url_checker(url):
|
10 |
+
try:
|
11 |
+
#Get Url
|
12 |
+
get = requests.get(url)
|
13 |
+
# if the request succeeds
|
14 |
+
if get.status_code == 200:
|
15 |
+
return True
|
16 |
+
else:
|
17 |
+
return False
|
18 |
+
|
19 |
+
#Exception
|
20 |
+
except requests.exceptions.RequestException as e:
|
21 |
+
# print URL with Errs
|
22 |
+
raise SystemExit(f"{url}: is Not reachable \nErr: {e}")
|
23 |
+
|
24 |
+
def generate_qr(url,qr_color):
|
25 |
+
if(url==""):
|
26 |
+
return "Failed"
|
27 |
+
|
28 |
+
if(url_checker(url)):
|
29 |
+
|
30 |
+
#Logo_link = logoo
|
31 |
+
|
32 |
+
#logo = Image.open(Logo_link)
|
33 |
+
|
34 |
+
# taking base width
|
35 |
+
#basewidth = 190
|
36 |
+
|
37 |
+
# adjust image size
|
38 |
+
#wpercent = (basewidth/float(logo.size[0]))
|
39 |
+
#hsize = int((float(logo.size[1])*float(wpercent)))
|
40 |
+
#logo = logo.resize((basewidth, hsize), Image.ANTIALIAS)
|
41 |
+
|
42 |
+
QRcode = qrcode.QRCode(version=1,box_size=12,
|
43 |
+
error_correction=qrcode.constants.ERROR_CORRECT_H
|
44 |
+
)
|
45 |
+
|
46 |
+
# adding URL or text to QRcode
|
47 |
+
QRcode.add_data(url)
|
48 |
+
# generating QR code
|
49 |
+
QRcode.make()
|
50 |
+
|
51 |
+
# taking color name from user
|
52 |
+
QRcolor = qr_color
|
53 |
+
|
54 |
+
# adding color to QR code
|
55 |
+
QRimg = QRcode.make_image(
|
56 |
+
fill_color=QRcolor, back_color="black").convert('RGB')
|
57 |
+
|
58 |
+
#pos = ((QRimg.size[0] - logo.size[0]) // 2,
|
59 |
+
# (QRimg.size[1] - logo.size[1]) // 2)
|
60 |
+
#QRimg.paste(logo, pos)
|
61 |
+
|
62 |
+
# save the QR code generated
|
63 |
+
QRimg.save('Generated_QRCode.png')
|
64 |
+
|
65 |
+
return "Success",QRimg
|