Rahatara commited on
Commit
a9f78b2
·
verified ·
1 Parent(s): 0ee98d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
app.py CHANGED
@@ -1,13 +1,12 @@
1
  import gradio as gr
2
  import qrcode
3
  from PIL import Image
4
- import io
5
 
6
  def generate_qr(link):
7
  if link.strip() == "":
8
  return None
9
 
10
- # Create QR
11
  qr = qrcode.QRCode(
12
  version=1,
13
  box_size=10,
@@ -16,21 +15,19 @@ def generate_qr(link):
16
  qr.add_data(link)
17
  qr.make(fit=True)
18
 
 
19
  img = qr.make_image(fill_color="black", back_color="white")
20
 
21
- # Convert to displayable image
22
- buf = io.BytesIO()
23
- img.save(buf, format="PNG")
24
- buf.seek(0)
25
 
26
- return buf
27
 
28
- # Gradio UI
29
  with gr.Blocks(title="Simple QR Code Maker") as demo:
30
  gr.Markdown("### 🔳 Simple QR Code Maker\nEnter any link to generate a QR code instantly!")
31
 
32
  link_input = gr.Textbox(label="Enter URL", placeholder="https://example.com")
33
- output_image = gr.Image(label="Generated QR Code")
34
 
35
  generate_btn = gr.Button("Generate QR Code")
36
  generate_btn.click(fn=generate_qr, inputs=link_input, outputs=output_image)
 
1
  import gradio as gr
2
  import qrcode
3
  from PIL import Image
 
4
 
5
  def generate_qr(link):
6
  if link.strip() == "":
7
  return None
8
 
9
+ # Create QR code object
10
  qr = qrcode.QRCode(
11
  version=1,
12
  box_size=10,
 
15
  qr.add_data(link)
16
  qr.make(fit=True)
17
 
18
+ # Make the image (this is already a PIL image)
19
  img = qr.make_image(fill_color="black", back_color="white")
20
 
21
+ # Ensure it's in RGB mode for Gradio
22
+ img = img.convert("RGB")
 
 
23
 
24
+ return img
25
 
 
26
  with gr.Blocks(title="Simple QR Code Maker") as demo:
27
  gr.Markdown("### 🔳 Simple QR Code Maker\nEnter any link to generate a QR code instantly!")
28
 
29
  link_input = gr.Textbox(label="Enter URL", placeholder="https://example.com")
30
+ output_image = gr.Image(label="Generated QR Code", type="pil")
31
 
32
  generate_btn = gr.Button("Generate QR Code")
33
  generate_btn.click(fn=generate_qr, inputs=link_input, outputs=output_image)