SarowarSaurav commited on
Commit
75e60e4
1 Parent(s): 6989a37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -1,8 +1,15 @@
1
  import pandas as pd
2
  import gradio as gr
 
 
3
 
4
- # Function to create a vCard entry from a DataFrame row
5
  def create_vcf(row):
 
 
 
 
 
6
  vcf_template = """BEGIN:VCARD
7
  VERSION:3.0
8
  PRODID:-//Apple Inc.//iPhone OS 17.2.1//EN
@@ -12,23 +19,26 @@ ORG:BAT Bangladesh;{function}
12
  TITLE:{designation}
13
  TEL;TYPE=CELL;TYPE=VOICE;TYPE=pref:{number}
14
  EMAIL:{email}
 
 
15
  END:VCARD"""
16
- # Formatting the row data into vCard format
17
  return vcf_template.format(
18
  name=row['Name'],
19
  function=row['Function'],
20
  designation=row['Designation'],
21
  number=row['Number'],
22
- email=row['Email']
 
 
23
  )
24
 
25
- # Function to generate the VCF file from the uploaded Excel data
26
  def generate_vcf(file):
27
- # Load Excel file
28
  df = pd.read_excel(file)
29
- df['Number'] = df['Number'].astype(str) # Convert phone numbers to string to avoid formatting issues
30
 
31
- # Combine each vCard entry into a single VCF file content
32
  vcf_data = df.apply(create_vcf, axis=1).str.cat(sep='\n\n')
33
 
34
  # Write the VCF data to a file
@@ -38,7 +48,7 @@ def generate_vcf(file):
38
 
39
  return vcf_file_name
40
 
41
- # Custom CSS and HTML for a refined UI
42
  css = """
43
  .gradio-container {
44
  background: rgb(14, 43, 99);
 
1
  import pandas as pd
2
  import gradio as gr
3
+ import hashlib
4
+ from datetime import datetime
5
 
6
+ # Function to create a vCard entry with UID and REV fields
7
  def create_vcf(row):
8
+ # Generate a unique UID based on the email (using a hash for consistency)
9
+ email = row['Email']
10
+ uid = hashlib.md5(email.encode()).hexdigest()
11
+ rev = datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ') # Current timestamp for revision
12
+
13
  vcf_template = """BEGIN:VCARD
14
  VERSION:3.0
15
  PRODID:-//Apple Inc.//iPhone OS 17.2.1//EN
 
19
  TITLE:{designation}
20
  TEL;TYPE=CELL;TYPE=VOICE;TYPE=pref:{number}
21
  EMAIL:{email}
22
+ UID:{uid}
23
+ REV:{rev}
24
  END:VCARD"""
 
25
  return vcf_template.format(
26
  name=row['Name'],
27
  function=row['Function'],
28
  designation=row['Designation'],
29
  number=row['Number'],
30
+ email=email,
31
+ uid=uid,
32
+ rev=rev
33
  )
34
 
35
+ # Function to generate the VCF file
36
  def generate_vcf(file):
37
+ # Load the Excel file
38
  df = pd.read_excel(file)
39
+ df['Number'] = df['Number'].astype(str) # Ensure phone numbers are strings
40
 
41
+ # Generate the VCF data
42
  vcf_data = df.apply(create_vcf, axis=1).str.cat(sep='\n\n')
43
 
44
  # Write the VCF data to a file
 
48
 
49
  return vcf_file_name
50
 
51
+ # Custom CSS and HTML
52
  css = """
53
  .gradio-container {
54
  background: rgb(14, 43, 99);