Spaces:
Sleeping
Sleeping
| import pandas as pd | |
| import gradio as gr | |
| def create_vcf(row): | |
| vcf_template = """BEGIN:VCARD | |
| VERSION:3.0 | |
| PRODID:-//Apple Inc.//iPhone OS 17.2.1//EN | |
| N:{name} | |
| ORG:BAT Bangladesh;{function} | |
| TITLE:{designation} | |
| TEL;type=CELL;type=VOICE;type=pref:{number} | |
| EMAIL:{email} | |
| END:VCARD""" | |
| return vcf_template.format( | |
| name=row['Name'], | |
| function=row['Function'], | |
| designation=row['Designation'], | |
| number=row['Number'], | |
| email=row['Email'] | |
| ) | |
| def generate_vcf(file): | |
| df = pd.read_excel(file) | |
| df['Number'] = df['Number'].astype(str) # Ensure phone numbers are strings | |
| vcf_data = df.apply(create_vcf, axis=1).str.cat(sep='\n\n') | |
| vcf_file_name = '/tmp/BAT New Contacts.vcf' | |
| with open(vcf_file_name, 'w') as vcf_file: | |
| vcf_file.write(vcf_data) | |
| return vcf_file_name | |
| # Define custom CSS and HTML | |
| css = """ | |
| .gradio-container { | |
| background: rgb(14, 43, 99); | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| color: #fff; /* Text color for better readability */ | |
| padding: 20px; /* Padding for the container */ | |
| } | |
| .gradio-input, .gradio-output { | |
| background: rgb(28, 56, 113); | |
| color: #fff; /* Text color for input and output fields */ | |
| } | |
| footer { | |
| display: none !important; | |
| } | |
| """ | |
| html_content = """ | |
| <div style="text-align: center; margin-bottom: 20px;"> | |
| <img src="https://i.ibb.co/RbQRzcy/APMEA-CENTRAL-White.png" border="0" alt='BAT Bangladesh Logo' style='max-width: 300px;'> | |
| </div> | |
| <p style="text-align: center; color: #fff;">Upload an Excel file containing contact information in the following format: Name, Designation, Function, GRADE, Email, Number. The output will be a VCF file containing the contact information.</p> | |
| """ | |
| with gr.Blocks(css=css) as demo: | |
| gr.HTML(html_content) | |
| gr.Interface( | |
| fn=generate_vcf, | |
| inputs=gr.File(label="Upload Excel File"), | |
| outputs=gr.File(label="Download VCF File"), | |
| ) | |
| demo.launch() | |