File size: 1,875 Bytes
9804404
 
 
 
36b90c8
 
 
 
 
 
43c4a6e
7796bb3
36b90c8
 
 
 
 
 
 
 
 
a26b867
36b90c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f05ecf5
48b280c
36b90c8
7796bb3
 
36b90c8
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
import gradio as gr
from PIL import Image, ImageDraw, ImageFont
import pandas as pd

def generate_certificates(Excel_file):
    output_paths = []
    df = pd.read_excel(Excel_file.name)

    required_columns = ['name', 'ID', 'date', 'event']
    if not all(col in df.columns for col in required_columns):
        return "Error: Excel file must contain 'name', 'ID', 'date', and 'event' columns."
    
    df['date'] = pd.to_datetime(df['date'], errors='coerce')
    df['formatted_date'] = df['date'].dt.strftime('%b %d, %Y')

    for _, row in df.iterrows():
        name = row['name']
        id_num = row['ID']
        formatted_date = row['formatted_date']
        event_s = row['event']

        template = Image.open("CertificateOfAttendance.png")
        draw = ImageDraw.Draw(template)

        font = ImageFont.truetype('LiberationMono-Regular.ttf', 70)
        font1 = ImageFont.truetype('LiberationMono-Regular.ttf', 35)
        font2 = ImageFont.truetype('LiberationMono-Regular.ttf', 40)

        name_position = (700, 800)
        id_position = (670, 910)
        date_position = (850, 1200)
        event_position = (565, 1041)

        draw.text(name_position, name, font=font, fill="black")
        draw.text(id_position, str(id_num), font=font2, fill="black")
        draw.text(date_position, formatted_date, font=font2, fill="black")
        draw.text(event_position, event_s, font=font1, fill="black")

        output_path = f"generated_certificate_{name}.png"
        template.save(output_path)
        output_paths.append(output_path)

    return output_paths

Excel_gradio = gr.Interface(
    fn=generate_certificates,
    inputs=gr.File(label="Upload Excel File"),  
    title="QuickCerts",
    description="Upload an Excel File with ('name', 'ID', 'date', and 'event') Columns to Generate Certificates",
    outputs="gallery" 
)

Excel_gradio.launch()