SarahMarzouq commited on
Commit
7796bb3
1 Parent(s): 5e095da

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image, ImageDraw, ImageFont
2
+ import gradio as gr
3
+
4
+ # Function to generate the certificate with user input
5
+ def generate_certificate(name, id_num, date):
6
+ # Open the certificate template (ensure the path is correct)
7
+ template = Image.open("ID.png") # Update this path if running locally
8
+ draw = ImageDraw.Draw(template)
9
+
10
+ # Load font with specified size (ensure you have the TTF file available)
11
+ font = ImageFont.truetype(r'/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf', 70)
12
+
13
+
14
+ name_position = (700, 800) # Adjusted position for the recipient's name
15
+ id_position = (700, 900) # Adjusted position for ID number
16
+ date_position = (700, 1200) # Adjusted position for the date
17
+
18
+ # Check if inputs are provided before drawing
19
+ if name: # Only draw if name is provided
20
+ draw.text(name_position, name, font=font, fill="black") # For recipient's name
21
+ if id_num: # Only draw if ID number is provided
22
+ draw.text(id_position, id_num, font=font, fill="black") # For ID number
23
+ if date: # Only draw if date is provided
24
+ draw.text(date_position, date, font=font, fill="black") # For the date
25
+
26
+ # Save the generated certificate
27
+ output_path = "generated_certificate.png"
28
+ template.save(output_path)
29
+
30
+ # Return the path to the generated certificate
31
+ return output_path
32
+
33
+ # Set up the Gradio interface
34
+ iface = gr.Interface(
35
+ fn=generate_certificate,
36
+ inputs=[gr.Textbox(label="Name (e.g., Sarah Abdullah"), gr.Textbox(label="ID Number"), gr.Textbox(label="Date (e.g., October 6, 2024)")],
37
+ outputs="image"
38
+ )
39
+
40
+ # Launch the Gradio interface
41
+ iface.launch()