CoolFace
Apppublic

LeRobot-worldwide-hackathon/certificate

sourceHugging Faceupdated 1y agoView on Hugging Face
5likes
app.py48 linesDownload Raw Back to root
1import gradio as gr2from PIL import Image, ImageDraw, ImageFont3 4def generate_certificate(name):5    # Load certificate template (you can replace this with your own image)6    certificate = Image.open("certificate_template.png")7    draw = ImageDraw.Draw(certificate)8    9    # Use a nice script font (Luxurious Script or similar)10    try:11        font = ImageFont.truetype("LuxuriousScript-Regular.ttf", 150)  # Ensure you have the font file12    except IOError:13        font = ImageFont.load_default()  # Fallback font if the specific one is not found14    15    # Get the bounding box of the text to calculate its width and height16    bbox = draw.textbbox((0, 0), name, font=font)  # Get the bounding box of the text17    text_width = bbox[2] - bbox[0]  # Width from bbox18    text_height = bbox[3] - bbox[1]  # Height from bbox19    20    # Calculate position to center the name21    position = ((certificate.width - text_width) // 2, (certificate.height - text_height) // 2)22    23    # Add the participant's name to the certificate in the center24    draw.text(position, name, font=font, fill="black")25    26    # Save the generated certificate with the name27    certificate.save(f"{name}_certificate.png")28    29    # Return the image to be displayed and downloaded in the Gradio interface30    return certificate, f"{name}_certificate.png"31 32# Define the Gradio interface33iface = gr.Interface(34    fn=generate_certificate, 35    inputs=gr.Textbox(label="Enter Your Name"), 36    outputs=[gr.Image(type="pil"), gr.File(label="Download Certificate")],  # Added file output for download37    title="๐ŸŽ“ Generate your Certificate for participation",38    description="Enter your name below to generate your personalized certificate.",39    live=True40)41 42# Launch the interface43iface.launch()44 45 46 47 48