XMMR12 commited on
Commit
a7dd399
·
verified ·
1 Parent(s): adf0dc3

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +67 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import qrcode
3
+ from PIL import Image
4
+ import io
5
+
6
+ def generate_qrcode(text):
7
+ """
8
+ Generate a QR code image from input text
9
+ """
10
+ # Create QR code instance
11
+ qr = qrcode.QRCode(
12
+ version=1,
13
+ error_correction=qrcode.constants.ERROR_CORRECT_L,
14
+ box_size=10,
15
+ border=4,
16
+ )
17
+
18
+ # Add data to the QR code
19
+ qr.add_data(text)
20
+ qr.make(fit=True)
21
+
22
+ # Create an image from the QR code
23
+ img = qr.make_image(fill_color="black", back_color="white")
24
+
25
+ # Convert to PIL Image
26
+ pil_img = img.get_image()
27
+
28
+ return pil_img
29
+
30
+ # Create Gradio interface
31
+ with gr.Blocks() as app:
32
+ gr.Markdown("## 🧾 QR Code Generator")
33
+ gr.Markdown("Enter text or a URL to generate a QR code")
34
+
35
+ with gr.Row():
36
+ text_input = gr.Textbox(
37
+ label="Input Text/URL",
38
+ placeholder="Enter text or URL here...",
39
+ max_lines=1
40
+ )
41
+
42
+ with gr.Row():
43
+ generate_btn = gr.Button("Generate QR Code")
44
+
45
+ with gr.Row():
46
+ image_output = gr.Image(label="Generated QR Code")
47
+
48
+ # Set up event handler
49
+ generate_btn.click(
50
+ fn=generate_qrcode,
51
+ inputs=text_input,
52
+ outputs=image_output
53
+ )
54
+
55
+ # Example inputs
56
+ gr.Examples(
57
+ examples=[
58
+ "https://www.example.com",
59
+ "Hello World!",
60
+ "mailto:[email protected]",
61
+ "WIFI:S:MyNetwork;T:WPA;P:MyPassword;;"
62
+ ],
63
+ inputs=text_input
64
+ )
65
+
66
+ # Launch the app
67
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ qrcode
3
+ pillow