Automate Your Cover Letter Writing with Large Language models: Building a Cover Letter Generator with Replicate and Streamlit

Mohamed Boumaiza
4 min readOct 6, 2023

--

In today’s competitive job market, a well-crafted cover letter can make all the difference in landing your dream job. However, tailoring cover letters for each job application can be time-consuming and daunting. What if there was a way to automate this process and ensure that your cover letters are both personalized and professional?

In this article, we’ll explore the development of a Cover Letter Generator powered by LLM. We’ll dive into the tools and technologies used, walk through the user interface.

Setting Up the Project

Before we dive into the details, let’s talk about what inspired this project. Crafting unique cover letters for every job application is a tedious task that many job seekers face. With the goal of streamlining this process, we set out to create a tool that leverages the power of AI.

The technology stack we used includes

  • Streamlit: a Python library for building web applications
  • Replicate: a platform that provides access to powerful language models. These tools, combined with our development expertise, allowed us to create an intuitive and efficient Cover Letter Generator.
# Install the necessary Python packages
pip install streamlit replicate-api-client

1. Llama 2

The heart of our Cover Letter Generator is the Llama 2 language model. It is Meta’s open source large language model. This model represents the cutting edge of natural language processing (NLP) technology.

2. Replicate: platform providing access to LLMs

Replicate provides a seamless way to access and interact LLMs, making it a crucial component of our project. . With Replicate’s platform, we can tap into the full potential of Llama 2, ensuring that our Cover Letter Generator produces cover letters that are not only personalized but also compelling and persuasive.

import replicate
import os
os.environ["REPLICATE_API_TOKEN"] = "r8_" # put your api_token

3. Streamlit: Creating an Intuitive User Interface

User experience is paramount, so we designed a user-friendly interface using Streamlit. The interface includes input fields for essential details, such as the user’s name, company name, hiring manager’s name, job title, and how they heard about the job opportunity. Additionally, users can paste the job description and customize the AI’s creativity level with a temperature slider.

import streamlit as st

# Define the Streamlit app layout
st.title("Cover Letter Generator with Llama 2")

with st.form('form to generate cover letter'):
# User input for cover letter
st.markdown("### Cover Letter Details")
user_name = st.text_input("Name")
company = st.text_input("Company Name")
manager = st.text_input("Hiring Manager")
role = st.text_input("Job Title")
referral = st.text_input("How did you find out about this opportunity?")
prompt_input = st.text_area("Paste the job description")
temp = st.number_input('AI Temperature. Reflects the model creativity on a scale of 0 to 1', value=0.5)

# Generate LLM response
generate_cover_letter = st.form_submit_button("Generate Cover Letter")

Here is an example:

Generating Cover Letters

Now, let’s take a look at how the magic happens. Users input their details, paste the job description, and adjust the AI temperature to their liking. When they hit the “Generate Cover Letter” button, the Replicate API interacts with the Llama 2 model to generate a personalized cover letter.

import replicate
import streamlit as st

# ... (Previous code)

if generate_cover_letter:
# Prompts
pre_prompt = "You are a helpful assistant. You do not respond as 'User' or pretend to be 'User'. You only respond once as 'Assistant'."
# Create a prompt for LLM: Include user inputs, and job description in the prompt
prompt = f"The job description is: {prompt_input}\n"
prompt += f"The candidate's name to include on the cover letter: {user_name}\n"
prompt += f"The job title/role: {role}\n"
prompt += f"The hiring manager is: {manager}\n"
prompt += f"How I heard about the opportunity: {referral}\n."
prompt += "Generate a cover letter"
# Generate LLM response
with st.spinner("Generating response"):
response = replicate.run(
'a16z-infra/llama13b-v2-chat:df7690f1994d94e96ad9d568eac121aecf50684a0b0963b25a41cc40061269e5', # Llama 2 model
input={
"prompt": f"{pre_prompt} {prompt} Assistant:",
"temperature": temp,
}
)
# Extract and display the LLM-generated cover letter
generated_cover_letter = " ".join([item for item in response])

st.subheader("Generated Cover Letter:")
st.write(generated_cover_letter)
# Offer a download link for the generated cover letter
st.subheader("Download Generated Cover Letter:")
st.download_button("Download Cover Letter as TXT", generated_cover_letter, key="cover_letter")

Here is the output:

All Done!

Now your app is ready to launch :)

streamlit run app.py

Feel free to check out the whole code at: https://github.com/khames-lab/cover_letter_generator_using_Llama2_and_streamlit

--

--