File size: 3,060 Bytes
e906b56
 
 
 
35a7b2b
e906b56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35a7b2b
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
import gradio as gr
import openai

# Set your OpenAI API key
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 = openai.ChatCompletion.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
    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 = openai.ChatCompletion.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.",
)

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.",
)
bespokecv = gr.TabbedInterface([jd_sum, cv_rate_interface],tab_names=['Job Description Summarizer','CV ATS Rating'])

if __name__ == "__main__":
    bespokecv.launch(auth=(os.environ['username'], os.environ['password']))