jmesplana commited on
Commit
e906b56
·
1 Parent(s): 16e88e8

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -0
app.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import config
3
+ import openai
4
+
5
+ # Set your OpenAI API key
6
+ openai.api_key = config.OPENAI_API_KEY
7
+
8
+ jd_summary_global = "" # Global variable to store the job description summary
9
+
10
+ def process_jd(text):
11
+ global jd_summary_global # Declare the global variable
12
+ if not text.strip(): # Check if the text is empty or contains only whitespace
13
+ jd_summary_global = "No JD" # Update the global variable
14
+ return "No JD"
15
+
16
+ try:
17
+ # Structuring a prompt to ask GPT-3.5 to summarize the job description
18
+ prompt = f"Summarize the following job description into its job nature, responsibilities, and requirements:\n\n{text}"
19
+
20
+ # Uploading text to OpenAI
21
+ response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt}])
22
+ jd_summary = response['choices'][0]['message']['content'].strip()
23
+ jd_summary_global = jd_summary # Update the global variable
24
+ return jd_summary
25
+ except Exception as e:
26
+ return str(e)
27
+
28
+ def cv_rating(cv_data):
29
+ global jd_summary_global # Declare the global variable
30
+ if len(jd_summary_global) <= 1 or jd_summary_global == "No JD":
31
+ return "No JD in the previous tab."
32
+ if len(cv_data) <= 1:
33
+ return "No CV data"
34
+ try:
35
+ # Construct a prompt to ask GPT-3.5 to rate the CV based on the job description summary
36
+ prompt = f"""
37
+ Job Description Summary: {jd_summary_global}
38
+ CV Data: {cv_data}
39
+
40
+ Rate the compatibility of the CV with the job description and provide strengths, weaknesses, and recommendations to strengthen the CV.
41
+ """
42
+ # Uploading text to OpenAI
43
+ response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt}])
44
+ return response['choices'][0]['message']['content'].strip()
45
+ except Exception as e:
46
+ return str(e)
47
+
48
+ jd_sum = gr.Interface(
49
+ fn=process_jd, # function to process the text
50
+ inputs=gr.Textbox(lines=30, label="Job Description"),
51
+ outputs=gr.Textbox(lines=30, label="JD Summary", show_copy_button=True),
52
+ live=False,
53
+ title="Job Description Summarizer",
54
+ description="An app to summarize job descriptions into job nature, responsibilities, and requirements.",
55
+ )
56
+
57
+ cv_rate_interface = gr.Interface(
58
+ fn=cv_rating,
59
+ inputs=gr.Textbox(lines=30, label="CV Data", placeholder="Paste the CV data here"),
60
+ outputs=gr.Textbox(lines=30, label="ATS Rating System", show_copy_button=True),
61
+ live=False,
62
+ title="CV Rating",
63
+ description="An app to rate CV compatibility with job description, providing strengths, weaknesses, and recommendations.",
64
+ )
65
+ bespokecv = gr.TabbedInterface([jd_sum, cv_rate_interface],tab_names=['Job Description Summarizer','CV ATS Rating'])
66
+
67
+ if __name__ == "__main__":
68
+ bespokecv.launch(share=True)