Spaces:
Sleeping
Sleeping
File size: 2,400 Bytes
1a4514d 6989a37 75e60e4 6989a37 75e60e4 6989a37 75e60e4 6989a37 75e60e4 6989a37 75e60e4 6989a37 e3a012f 75e60e4 6989a37 75e60e4 6989a37 75e60e4 e3a012f 75e60e4 6989a37 1a4514d 6989a37 75e60e4 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 78 79 80 81 82 83 84 85 86 87 |
import pandas as pd
import gradio as gr
import hashlib
from datetime import datetime
# Function to create a vCard entry with UID and REV fields
def create_vcf(row):
# Generate a unique UID based on the email (using a hash for consistency)
email = row['Email']
uid = hashlib.md5(email.encode()).hexdigest()
rev = datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ') # Current timestamp for revision
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}
UID:{uid}
REV:{rev}
END:VCARD"""
return vcf_template.format(
name=row['Name'],
function=row['Function'],
designation=row['Designation'],
number=row['Number'],
email=email,
uid=uid,
rev=rev
)
# Function to generate the VCF file
def generate_vcf(file):
# Load the Excel file
df = pd.read_excel(file)
df['Number'] = df['Number'].astype(str) # Ensure phone numbers are strings
# Generate the VCF data
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
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()
|