Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
def create_vcf(row):
|
| 5 |
+
vcf_template = """BEGIN:VCARD
|
| 6 |
+
VERSION:3.0
|
| 7 |
+
PRODID:-//Apple Inc.//iPhone OS 17.2.1//EN
|
| 8 |
+
N:{name}
|
| 9 |
+
ORG:BAT Bangladesh;{function}
|
| 10 |
+
TITLE:{designation}
|
| 11 |
+
TEL;type=CELL;type=VOICE;type=pref:{number}
|
| 12 |
+
EMAIL:{email}
|
| 13 |
+
END:VCARD"""
|
| 14 |
+
return vcf_template.format(
|
| 15 |
+
name=row['Name'],
|
| 16 |
+
function=row['Function'],
|
| 17 |
+
designation=row['Designation'],
|
| 18 |
+
number=row['Number'],
|
| 19 |
+
email=row['Email']
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
def generate_vcf(file):
|
| 23 |
+
df = pd.read_excel(file)
|
| 24 |
+
df['Number'] = df['Number'].astype(str) # Ensure phone numbers are strings
|
| 25 |
+
vcf_data = df.apply(create_vcf, axis=1).str.cat(sep='\n\n')
|
| 26 |
+
|
| 27 |
+
vcf_file_name = '/tmp/BAT New Contacts.vcf'
|
| 28 |
+
with open(vcf_file_name, 'w') as vcf_file:
|
| 29 |
+
vcf_file.write(vcf_data)
|
| 30 |
+
|
| 31 |
+
return vcf_file_name
|
| 32 |
+
|
| 33 |
+
# Define custom CSS and HTML
|
| 34 |
+
css = """
|
| 35 |
+
.gradio-container {
|
| 36 |
+
background: rgb(14, 43, 99);
|
| 37 |
+
display: flex;
|
| 38 |
+
flex-direction: column;
|
| 39 |
+
align-items: center;
|
| 40 |
+
color: #fff; /* Text color for better readability */
|
| 41 |
+
padding: 20px; /* Padding for the container */
|
| 42 |
+
}
|
| 43 |
+
.gradio-input, .gradio-output {
|
| 44 |
+
background: rgb(28, 56, 113);
|
| 45 |
+
color: #fff; /* Text color for input and output fields */
|
| 46 |
+
}
|
| 47 |
+
footer {
|
| 48 |
+
display: none !important;
|
| 49 |
+
}
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
html_content = """
|
| 53 |
+
<div style="text-align: center; margin-bottom: 20px;">
|
| 54 |
+
<img src="https://i.ibb.co/RbQRzcy/APMEA-CENTRAL-White.png" border="0" alt='BAT Bangladesh Logo' style='max-width: 300px;'>
|
| 55 |
+
</div>
|
| 56 |
+
<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>
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
with gr.Blocks(css=css) as demo:
|
| 60 |
+
gr.HTML(html_content)
|
| 61 |
+
gr.Interface(
|
| 62 |
+
fn=generate_vcf,
|
| 63 |
+
inputs=gr.File(label="Upload Excel File"),
|
| 64 |
+
outputs=gr.File(label="Download VCF File"),
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
demo.launch()
|