File size: 7,933 Bytes
e906b56
46168b6
9b0ddf5
e906b56
 
9b0ddf5
e906b56
 
 
 
 
 
 
 
 
 
 
 
 
 
9b0ddf5
 
e906b56
 
 
 
 
 
 
6241d6e
 
e906b56
 
 
 
 
 
 
 
 
 
 
 
 
9b0ddf5
 
6241d6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b0ddf5
 
e906b56
 
6241d6e
 
 
 
 
 
 
 
 
 
 
 
 
 
9b0ddf5
 
6241d6e
 
b524cb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b0ddf5
b524cb9
 
9b0ddf5
b524cb9
 
6241d6e
e906b56
 
6241d6e
e906b56
 
 
2ed3ac9
 
6241d6e
e906b56
 
 
 
 
 
 
 
 
6241d6e
 
 
 
 
 
 
 
 
 
 
e906b56
6241d6e
 
 
 
 
 
 
 
 
 
 
b524cb9
 
 
 
 
 
 
 
 
 
 
8e2a2e4
 
e906b56
 
387b735
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import gradio as gr
import os
from openai import OpenAI

# Set your OpenAI API key
client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])

jd_summary_global = ""  # Global variable to store the job description summary

def process_jd(text):
    global jd_summary_global  # Declare the global variable
    if not text.strip():  # Check if the text is empty or contains only whitespace
        jd_summary_global = "No JD"  # Update the global variable
        return "No JD"
    
    try:
        # Structuring a prompt to ask GPT-3.5 to summarize the job description
        prompt = f"Summarize the following job description into its job nature, responsibilities, and requirements:\n\n{text}"
        
        # Uploading text to OpenAI 
        response = client.chat.completions.create(model="gpt-3.5-turbo", messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt}])
        jd_summary = response.choices[0].message.content.strip()
        jd_summary_global = jd_summary  # Update the global variable
        return jd_summary
    except Exception as e:
        return str(e)

def cv_rating(cv_data):
    global jd_summary_global  # Declare the global variable
    global cv_rating_global
    
    if len(jd_summary_global) <= 1 or jd_summary_global == "No JD":  
        return "No JD in the previous tab."
    if len(cv_data) <= 1:
        return "No CV data"
    try:
        # Construct a prompt to ask GPT-3.5 to rate the CV based on the job description summary
        prompt = f"""
        Job Description Summary: {jd_summary_global}
        CV Data: {cv_data}
        
        Rate the compatibility of the CV with the job description and provide strengths, weaknesses, and recommendations to strengthen the CV.
        """
        # Uploading text to OpenAI 
        response = client.chat.completions.create(model="gpt-3.5-turbo", messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt}])
        cv_rating_global= response.choices[0].message.content.strip()
        return cv_rating_global
    except Exception as e:
        return str(e)

def create_cover_letter(additional_info):
    global jd_summary_global  # Declare the global variable
    global cv_rating_global
    if len(jd_summary_global) <= 1 or jd_summary_global == "No JD":  
        return "No JD in the previous tab."
    if len(cv_rating_global) <= 1:
        return "No CV data"
    try:
        # Constructing a prompt for GPT-3.5 to create a tailored cover letter
        prompt = f"""
        Job Description: {jd_summary_global}
        CV Data: {cv_rating_global}
        Additional Information: {additional_info}

        Create a tailored cover letter based on the job description and CV data provided:
        """
        # Uploading text to OpenAI 
        response = client.chat.completions.create(model="gpt-3.5-turbo", messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt}])
        return response.choices[0].message.content.strip()
    except Exception as e:
        return str(e)

def interview_qa(additional_info):
    global cv_rating_global
    if len(cv_rating_global) <= 1:
        return "No CV data"
    try:
        # Constructing a prompt for GPT-3.5 to create interview questions and answers
        prompt = f"""
        CV Data: {cv_rating_global}
        Additional Information: {additional_info}

        Generate at least 10 interview questions and provide potential answers based on the CV data and additional information provided:
        """
        # Uploading text to OpenAI 
        response = client.chat.completions.create(model="gpt-3.5-turbo", messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt}])
        return response.choices[0].message.content.strip()
    except Exception as e:
        return str(e)
        
def suggest_cv_content(additional_info):
    global jd_summary_global  # Accessing the global variable for job description summary
    global cv_rating_global   # Accessing the global variable for CV data
    
    if len(jd_summary_global) <= 1 or jd_summary_global == "No JD":  
        return "No JD in the previous tab."
    if len(cv_rating_global) <= 1:
        return "No CV data"
    
    try:
        # Constructing a prompt for GPT-3.5 to suggest tailored CV content
        prompt = f"""
        Given the following job description, generate a new CV to better match the job description. Also, ensure the suggestions are formatted in a way that is compatible with most ATS solutions.

        Job Description: {jd_summary_global}
        CV Data: {cv_rating_global}
        Additional Information: {additional_info}
        """
        # Uploading text to OpenAI 
        response = client.chat.completions.create(model="gpt-3.5-turbo",
            messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt}]
        )
        return response.choices[0].message.content.strip()
    except Exception as e:
        return str(e)

jd_sum = gr.Interface(
    fn=process_jd,  # function to process the text
    inputs=gr.Textbox(lines=30, label="Job Description"),
    outputs=gr.Textbox(lines=30, label="JD Summary", show_copy_button=True),
    live=False,
    title="Job Description Summarizer",
    description="An app to summarize job descriptions into job nature, responsibilities, and requirements. \
        For more info, check out: https://github.com/jmesplana/BespokeCV",
    api_name="jd_sum"
)

cv_rate_interface = gr.Interface(
    fn=cv_rating,
    inputs=gr.Textbox(lines=30, label="CV Data", placeholder="Paste the CV data here"),
    outputs=gr.Textbox(lines=30, label="ATS Rating System", show_copy_button=True),
    live=False,
    title="CV Rating",
    description="An app to rate CV compatibility with job description, providing strengths, weaknesses, and recommendations.",
    api_name="cv_rate_interface"
)

cover_letter_interface = gr.Interface(
    fn=create_cover_letter,
    inputs=[gr.Textbox(lines=10, label="Additional Information", placeholder="Add any additional information or preferences for your cover letter here")],
    outputs=gr.Textbox(lines=30, label="Output", show_copy_button=True),
    live=False,
    title="Cover Letter Creator",
    description="An app to create a tailored cover letter based on job description and CV data. You may input additional information in the additional information box to add highlight specific experiences/projects and/or skills.",
    api_name="cover_letter_interface"
)

interview_qa_interface = gr.Interface(
    fn=interview_qa,
    inputs=[gr.Textbox(lines=10, label="Additional Information", placeholder="Add any specific questions or additional information here")],
    outputs=gr.Textbox(lines=30, label="Output", show_copy_button=True),
    live=False,
    title="Interview Q&A",
    description="An app to generate interview questions and answers based on CV data and additional information.",
    api_name="interview_qa"
)

cv_suggestion_interface = gr.Interface(
    fn=suggest_cv_content,
    inputs=[gr.Textbox(lines=10, label="Additional Information", placeholder="Add any specific requests or additional information here")],
    outputs=gr.Textbox(lines=30, label="Output", show_copy_button=True),
    live=False,
    title="CV Content Suggestion",
    description="An app to suggest CV content tailored to the job description, optimized for ATS compatibility.",
    api_name="cv_suggestion"
)


bespokecv = gr.TabbedInterface([jd_sum, cv_rate_interface,cover_letter_interface,interview_qa_interface,cv_suggestion_interface],
                               tab_names=['Job Description Summarizer','CV ATS Rating','Cover Letter Generator','Interview Q&A','Suggested CV'])

if __name__ == "__main__":
    bespokecv.launch(share=True)