Cover Letter Generator

Currently working on a Open Ai based coverletter Generator. The code is as below

import streamlit as st
import io
import os
import openai as ai
from PyPDF2 import PdfReader

ai.api_key = ' '

# πŸ“ AI-Powered Cover Letter Generator

Generate a cover letter. All you need to do is:
1. Upload your resume or copy your resume/experiences
2. Paste a relevant job description
3. Input some other relevant user/job data

# radio for upload or copy paste option         
res_format =
    "Do you want to upload or paste your resume/key experience",
    ('Upload', 'Paste'))

if res_format == 'Upload':
    # upload_resume
    res_file = st.file_uploader('πŸ“ Upload your resume in pdf format')
    if res_file:
        pdf_reader = PdfReader(res_file)

        # Collect text from pdf
        res_text = ""
        for page in pdf_reader.pages:
            res_text += page.extract_text()
    # use the pasted contents instead
    res_text = st.text_input('Pasted resume elements')

with st.form('input_form'):
    # other inputs
    job_desc = st.text_input('Pasted job description')
    user_name = st.text_input('Your name')
    company = st.text_input('Company name')
    manager = st.text_input('Hiring manager')
    role = st.text_input('Job title/role')
    referral = st.text_input('How did you find out about this opportunity?')
    ai_temp = st.number_input('AI Temperature (0.0-1.0) Input how creative the API can be',value=.99)

    # submit button
    submitted = st.form_submit_button("Generate Cover Letter")

# if the form is submitted run the openai completion   
if submitted:

       completion = ai.ChatCompletion.create(
      model = "gpt-3.5-turbo",
      messages = [
        {"role": "user", "content" : f"You will need to generate a cover letter based on specific resume and a job description"},
        {"role": "user", "content" : f"My resume text: {res_text}"},
        {"role": "user", "content" : f"The job description is: {job_desc}"},
        {"role": "user", "content" : f"The candidate's name to include on the cover letter: {user_name}"},
        {"role": "user", "content" : f"The job title/role : {role}"},
        {"role": "user", "content" : f"The hiring manager is: {manager}"},
        {"role": "user", "content" : f"How you heard about the opportunity: {referral}"},
        {"role": "user", "content" : f"The company to which you are generating the cover letter for: {company}"},
        {"role": "user", "content" : f"The cover letter should have three content paragraphs"},
        {"role": "user", "content" : f""" 
        In the first paragraph focus on the following: you will convey who you are, what position you are interested in, and where you heard
        about it, and summarize what you have to offer based on the above resume
            {"role": "user", "content" : f""" 
        In the second paragraph focus on why the candidate is a great fit drawing parallels between the experience included in the resume 
        and the qualifications on the job description.
                {"role": "user", "content" : f""" 
        In the 3RD PARAGRAPH: Conclusion
        Restate your interest in the organization and/or job and summarize what you have to offer and thank the reader for their time and consideration.
        {"role": "user", "content" : f""" 
        note that contact information may be found in the included resume text and use and/or summarize specific resume context for the letter
        {"role": "user", "content" : f"Use {user_name} as the candidate"},
        {"role": "user", "content" : f"Generate a specific cover letter based on the above. Generate the response and include appropriate spacing between the paragraph text"}

    response_out = completion['choices'][0]['message']['content']

    # include an option to download a txt file
    st.download_button('Download the cover_letter', response_out)

The code is working, but in place of whatever entries the user is taking like Name, Company, role etc its coming like [Name][Company] etc. Attaching a screenshot for better understanding.

Can anybody please try this code and inform the error. Please suggest solutions


Whatever the user has entered those names, company name, hiring manager’s names should come. That’s actually not coming

It seems like it’s working fine to me. I filled in all the job/user data, and tried uploading and also pasting my resume, and it worked fine.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.