-
Notifications
You must be signed in to change notification settings - Fork 6
/
certificate.py
81 lines (62 loc) · 3.21 KB
/
certificate.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import cv2
import os
import base64
import streamlit as st
from st_click_detector import click_detector
import numpy
import sys
from PIL import Image, ImageDraw
with open('style.css') as f:
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
font = cv2.FONT_HERSHEY_SIMPLEX
fontScale = 3
activities = ["Get certificate","About"]
st.sidebar.image("images\\logo.png")
choice=st.sidebar.selectbox("Select Activty",activities)
def get_binary_file_downloader_html(bin_file, file_label='File'):
with open(bin_file, 'rb') as f:
data = f.read()
bin_str = base64.b64encode(data).decode()
href = f'<a href="data:application/octet-stream;base64,{bin_str}" download="{os.path.basename(bin_file)}"> Download {file_label}</a>'
return href
def annotate(name):
# this line of code is used to display the Images on the site which are clickable
st.write("Select Below Templates")
content = """
<a id="Image_1" href="#"><img src="https://i.ibb.co/5WvJgFQ/new-Certificate-template-1.png" alt="new-Certificate-template-1" border="0" width="300px" aspect-ratio="16:9" ></a>
<a id="Image_2" href="#"><img src="https://i.ibb.co/CmhrK9d/new-Certificate-template-2.png" alt="new-Certificate-template-2" border="0" width="300px" aspect-ratio="16:9" ></a>
<a id="Image_3" href="#"><img src="https://i.ibb.co/hgqg4Hs/Certificate-template-3.png" alt="Certificate-template-3" border="0" width="300px" aspect-ratio="16:9" ></a>
"""
# we store the Id of the clicked image in Clicked Variable
clicked = click_detector(content)
# st.markdown(f"**{clicked} clicked**" )
# the path will be default to the defualt image
path = "images\\img.png"
# we cross check id with the paths available and assign the path for the selected image
if(clicked == "Image_1"):
path = "certificate_templates\\new_Certificate-template-1.png"
if (clicked == "Image_2"):
path = "certificate_templates\\new_Certificate-template-2.png"
if (clicked == "Image_3"):
path = "certificate_templates\\Certificate-template-3.png"
certi = cv2.imread(path)
if(clicked=="Image_3"):
original = cv2.putText(certi, name, (600, 850),font, fontScale, (255, 255, 255), thickness=5)
else:
original = cv2.putText(certi, name, (600, 790),font, fontScale, (0, 0, 0), thickness=5)
cv2.imwrite("Certificate.jpg",original)
if st.button("View certificate"):
st.image(original, caption=None, width=350, use_column_width=None, clamp=False, channels='BGR',output_format='PNG')
st.markdown(get_binary_file_downloader_html('Certificate.jpg', 'Certificate'), unsafe_allow_html=True)
if choice =="Get certificate":
st.title("Get Your Certificate")
na=st.text_input('Enter your name')
if len(na)>0:
annotate(na)
else:
st.write("Please enter Your name in the Above Field To download the Certificate")
#st.markdown(get_binary_file_downloader_html(original, 'Picture'), unsafe_allow_html=True)
if choice =="About":
st.subheader("Cerficate App")
st.markdown("</> with ❤ by Anirudh Soni" )
st.markdown("connect with me 😃 (https://www.linkedin.com/in/heyanirudh)")