File size: 1,380 Bytes
6f7822a
 
 
5782cdf
6f7822a
5782cdf
 
6f7822a
 
 
 
5782cdf
6f7822a
 
 
 
 
 
5782cdf
6f7822a
 
 
 
 
 
 
 
 
 
 
5782cdf
6f7822a
 
 
 
5782cdf
6f7822a
 
5782cdf
6f7822a
5782cdf
6f7822a
 
5782cdf
 
6f7822a
5782cdf
6f7822a
 
5782cdf
 
6f7822a
 
5782cdf
6a460b2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import qrcode
import gradio as gr
from io import BytesIO
from PIL import Image

def generate_vcard(name, contact_number, email, designation, work_address):
    # Format the information as a vCard
    vcard = f"""
BEGIN:VCARD
VERSION:3.0
FN:{name}
TEL;TYPE=WORK,VOICE:{contact_number}
EMAIL;TYPE=PREF,INTERNET:{email}
TITLE:{designation}
ADR;TYPE=WORK:;;{work_address}
END:VCARD
    """

    # Generate the QR code
    qr = qrcode.QRCode(
        version=1,
        error_correction=qrcode.constants.ERROR_CORRECT_L,
        box_size=10,
        border=4,
    )
    qr.add_data(vcard)
    qr.make(fit=True)

    img = qr.make_image(fill_color="black", back_color="white")

    # Save the image to a BytesIO object
    buffer = BytesIO()
    img.save(buffer, format="PNG")
    buffer.seek(0)

    # Convert the BytesIO object to an Image
    return Image.open(buffer)

# Create the Gradio interface
iface = gr.Interface(
    fn=generate_vcard,
    inputs=[
        gr.Textbox(label="Name"),
        gr.Textbox(label="Contact Number"),
        gr.Textbox(label="Email"),
        gr.Textbox(label="Designation"),
        gr.Textbox(label="Work Address")
    ],
    outputs=gr.Image(type="pil"),
    title="QR Code Generator for vCard",
    description="Fill in your details and generate a QR code containing your information in vCard format."
)

# Launch the interface
iface.launch()