Spaces:
Sleeping
Sleeping
| 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() | |