Build a Personalized Resume Generator with Streamlit and DocxTemplate

Afnan
3 min readFeb 14, 2023

--

Day 3, Experiment #3

I used help of OpenAI’s language model, ChatGPT, Streamlit and DocxTemplate to create this Personalized Resume Generator.

The project itself wasn’t that hard took me just a few hours to get the finished product after a little debugging.

Here’s the whole code :

import streamlit as st
from docxtpl import DocxTemplate
from io import BytesIO

# Define the questions
questions = [
"What is your full name?",
"What is your email address?",
"What is your phone number?",
"What is your current job title?",
"What is your work experience?",
"What are your key skills?",
"What is your education background?",
"What are your certifications and awards?",
"What is your desired job position?",
"What are your hobbies and interests?",
"Do you have any references? If so, please provide their contact information."
]

# Define the template file
template_file = "/path/to/resume_template.docx"

# Define helper functions for rendering the form and generating the resume
def render_form():
with st.form("resume-form"):
col1, col2 = st.beta_columns(2)
responses = []
for i, q in enumerate(questions):
if i <= 5:
response = col1.text_input(q)
else:
response = col2.text_input(q)
responses.append(response)
col1.write("")
col2.write("")
submitted = st.form_submit_button("Generate Resume")
return submitted, responses

def generate_resume(responses):
doc = DocxTemplate(template_file)
context = {
'full_name': responses[0],
'email': responses[1],
'phone_number': responses[2],
'current_job_title': responses[3],
'work_experience': responses[4],
'key_skills': responses[5],
'education_background': responses[6],
'certifications_awards': responses[7],
'desired_job_position': responses[8],
'hobbies_interests': responses[9],
'references': responses[10]
}
doc.render(context)
doc_bytes = BytesIO()
doc.save(doc_bytes)
return doc_bytes.getvalue()

#About

def about():
st.title("About")
st.write("This app is a Resume Generator built with Streamlit and DocxTemplate. It allows you to generate a personalized resume/CV by filling out a form with your information.")
st.write("""
Made with :heart: by AfnanKhan
""", unsafe_allow_html=True)

# Define the main function to run the app
def main():

st.set_page_config(page_title="Resume Generator", page_icon=":guardsman:", layout="wide")

# Set the page background color using the css property

st.markdown(
"""
<style>
body {
background-color: #F5F5F5;
}
</style>
""",
unsafe_allow_html=True
)
st.title("Resume Generator")

st.write("Welcome to the Resume Generator! Please fill out the form below to generate a personalized resume/CV.")

submitted, responses = render_form()

if submitted:
st.write("Generating your resume... Please wait.")
resume_buffer = generate_resume(responses)
st.write("Resume successfully generated!")
st.download_button(label="Download Generated Resume", data=resume_buffer, file_name="generated_resume.docx")
st.write("""
Made with :heart: by AfnanKhan
""", unsafe_allow_html=True)

# Add a button to link to the About page
st.sidebar.button("About", on_click=about)

if __name__ == "__main__":
main()

Code Walkthrough:

The code begins by importing the necessary packages, including Streamlit, DocxTemplate, and BytesIO. It then defines a list of questions to ask the user, which will be used to populate the resume.

The code then defines a helper function for rendering the form using the st.form context manager. This function creates a two-column layout and iterates through the list of questions, prompting the user for their responses. When the form is submitted, the function returns a boolean indicating whether the form was submitted and a list of the user's responses.

The generate_resume function takes the user's responses and uses them to populate a Word document template. This function uses the DocxTemplate package to open the template file and the user's responses to populate the appropriate fields. Finally, the function saves the generated resume to a BytesIO buffer and returns the contents of the buffer.

The about function simply displays information about the app and its author.

The main function is where everything comes together. It first sets the page configuration and background color using the st.set_page_config and st.markdown functions. It then defines the main content of the app using the st.title and st.write functions. Next, it calls the render_form function to prompt the user for their responses.

If the user submits the form, the app calls the generate_resume function to generate the resume and prompts the user to download it using the st.download_button function. Finally, the app displays a footer with information about the author and adds a button to link to the about page.

Final Result :

Screenshot By Author

You can check it out here : https://2cloud-s-my-resume-app-my-resume-app-vobuoi.streamlit.app/

Subscribe and clap to get new post notifications daily. As I’ll be daily uploading new scripts that i create with ChatGPT. Peace

--

--

No responses yet