-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathstreamlit_app.py
54 lines (43 loc) · 1.48 KB
/
streamlit_app.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
import pdfkit
from jinja2 import Environment, PackageLoader, select_autoescape, FileSystemLoader
from datetime import date
import streamlit as st
from streamlit.components.v1 import iframe
st.set_page_config(layout="centered", page_icon="🎓", page_title="Diploma Generator")
st.title("🎓 Diploma PDF Generator")
st.write(
"This app shows you how you can use Streamlit to make a PDF generator app in just a few lines of code!"
)
left, right = st.columns(2)
right.write("Here's the template we'll be using:")
right.image("template.png", width=300)
env = Environment(loader=FileSystemLoader("."), autoescape=select_autoescape())
template = env.get_template("template.html")
left.write("Fill in the data:")
form = left.form("template_form")
student = form.text_input("Student name")
course = form.selectbox(
"Choose course",
["Report Generation in Streamlit", "Advanced Cryptography"],
index=0,
)
grade = form.slider("Grade", 1, 100, 60)
submit = form.form_submit_button("Generate PDF")
if submit:
html = template.render(
student=student,
course=course,
grade=f"{grade}/100",
date=date.today().strftime("%B %d, %Y"),
)
pdf = pdfkit.from_string(html, False)
st.balloons()
right.success("🎉 Your diploma was generated!")
# st.write(html, unsafe_allow_html=True)
# st.write("")
right.download_button(
"⬇️ Download PDF",
data=pdf,
file_name="diploma.pdf",
mime="application/octet-stream",
)