File size: 2,370 Bytes
f4df8f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import openai
import streamlit as st
import base64
import os



openai.api_key = os.environ["api_key"]

def main():
    st.set_page_config(page_title="Cover Letter GPT", page_icon=":pencil2:")
    st.markdown(
        """
        <h1 style='text-align: center;'>Cover Letter GPT</h1>
        <style>
            body {
            color: black;
            background-color: yellow;
            }
            
        </style>
        """,
        unsafe_allow_html=True
    )

    company_name = st.text_input("Enter the company name")
    job_position = st.text_input("Enter the job position")
    job_description = st.text_area("Enter the job description")
    qualifications = st.text_area("Enter your qualifications")
    word_count = st.text_input("Enter the word count of cover letter (maximum: 300): ")

    options = ["Default", "Formal", "Friendly", "Professional", "Humorous"]
    tone = st.selectbox('Select the tone for the letter', options)

    if st.button("Generate Cover Letter"):
        # Call the OpenAI GPT-3 API to generate the cover letter
        # using the inputs from the user
        if not all([company_name, job_position, job_description, qualifications, word_count]):
            st.warning("Please fill in all the input fields.")
        else:
            generated_text = generate_cover_letter(
                company_name, job_position, job_description, qualifications, word_count, tone
            )
    
            # Display the generated cover letter on the page
            #st.write(generated_text)
            st.markdown(f"<div style='background-color:#F5F5F5; padding:10px'>{generated_text}</div>", unsafe_allow_html=True)

    
def generate_cover_letter(company_name, job_position, job_description, qualifications, word_count, tone):
    prompt = f"Write a cover letter. The following are the instructions:\n 1) Word count: {word_count}\ntone for letter: {tone}\nCompany name: {company_name}\nJob Position: {job_position}\nThe following details the job description:\n{job_description}\nThe following are my qualifications: {qualifications}\n"
    response = openai.Completion.create(
        engine="text-davinci-002",
        prompt=prompt,
        max_tokens=2048,
        temperature=0.85,
        n=1,
        stop=None,
        timeout=60
    )
    return response.choices[0].text

if __name__ == "__main__":
    main()