|
import gradio as gr |
|
from PIL import Image, ImageDraw, ImageFont |
|
|
|
def generate_certificate(name): |
|
|
|
certificate = Image.open("certificate_template.png") |
|
draw = ImageDraw.Draw(certificate) |
|
|
|
|
|
try: |
|
font = ImageFont.truetype("LuxuriousScript-Regular.ttf", 150) |
|
except IOError: |
|
font = ImageFont.load_default() |
|
|
|
|
|
bbox = draw.textbbox((0, 0), name, font=font) |
|
text_width = bbox[2] - bbox[0] |
|
text_height = bbox[3] - bbox[1] |
|
|
|
|
|
position = ((certificate.width - text_width) // 2, (certificate.height - text_height) // 2) |
|
|
|
|
|
draw.text(position, name, font=font, fill="black") |
|
|
|
|
|
certificate.save(f"{name}_certificate.png") |
|
|
|
|
|
return certificate, f"{name}_certificate.png" |
|
|
|
|
|
iface = gr.Interface( |
|
fn=generate_certificate, |
|
inputs=gr.Textbox(label="Enter Your Name"), |
|
outputs=[gr.Image(type="pil"), gr.File(label="Download Certificate")], |
|
title="π Generate your Certificate for participation", |
|
description="Enter your name below to generate your personalized certificate.", |
|
live=True |
|
) |
|
|
|
|
|
iface.launch() |
|
|
|
|
|
|
|
|
|
|