File size: 2,211 Bytes
1a4514d
6989a37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3a012f
6989a37
 
1a4514d
6989a37
 
e3a012f
6989a37
 
 
 
 
 
 
1a4514d
6989a37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3a012f
6989a37
 
 
 
 
 
e3a012f
6989a37
 
 
 
 
 
 
 
e3a012f
6989a37
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import pandas as pd
import gradio as gr

# Function to create a vCard entry from a DataFrame row
def create_vcf(row):
    vcf_template = """BEGIN:VCARD
VERSION:3.0
PRODID:-//Apple Inc.//iPhone OS 17.2.1//EN
N:{name}
FN:{name}
ORG:BAT Bangladesh;{function}
TITLE:{designation}
TEL;TYPE=CELL;TYPE=VOICE;TYPE=pref:{number}
EMAIL:{email}
END:VCARD"""
    # Formatting the row data into vCard format
    return vcf_template.format(
        name=row['Name'],
        function=row['Function'],
        designation=row['Designation'],
        number=row['Number'],
        email=row['Email']
    )

# Function to generate the VCF file from the uploaded Excel data
def generate_vcf(file):
    # Load Excel file
    df = pd.read_excel(file)
    df['Number'] = df['Number'].astype(str)  # Convert phone numbers to string to avoid formatting issues
    
    # Combine each vCard entry into a single VCF file content
    vcf_data = df.apply(create_vcf, axis=1).str.cat(sep='\n\n')
    
    # Write the VCF data to a file
    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

# Custom CSS and HTML for a refined UI
css = """
.gradio-container {
    background: rgb(14, 43, 99);
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #fff;
    padding: 20px;
}
.gradio-input, .gradio-output {
    background: rgb(28, 56, 113);
    color: #fff;
}
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>
"""

# Gradio Interface
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()