from PIL import Image, ImageDraw, ImageFont import gradio as gr # Function to generate the certificate with user input def generate_certificate(name, id_num, date): # Open the certificate template (ensure the path is correct) template = Image.open("ID.png") # Update this path if running locally draw = ImageDraw.Draw(template) # Load font with specified size (ensure you have the TTF file available) font = ImageFont.truetype(r'/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf', 70) name_position = (700, 800) # Adjusted position for the recipient's name id_position = (700, 900) # Adjusted position for ID number date_position = (700, 1200) # Adjusted position for the date # Check if inputs are provided before drawing if name: # Only draw if name is provided draw.text(name_position, name, font=font, fill="black") # For recipient's name if id_num: # Only draw if ID number is provided draw.text(id_position, id_num, font=font, fill="black") # For ID number if date: # Only draw if date is provided draw.text(date_position, date, font=font, fill="black") # For the date # Save the generated certificate output_path = "generated_certificate.png" template.save(output_path) # Return the path to the generated certificate return output_path # Set up the Gradio interface iface = gr.Interface( fn=generate_certificate, inputs=[gr.Textbox(label="Name (e.g., Sarah Abdullah"), gr.Textbox(label="ID Number"), gr.Textbox(label="Date (e.g., October 6, 2024)")], outputs="image" ) # Launch the Gradio interface iface.launch()