barghavani commited on
Commit
d2c3acc
·
verified ·
1 Parent(s): 6dc8685

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -10
app.py CHANGED
@@ -37,27 +37,64 @@ def calculate_resume_score(resume_text, job_description):
37
  score = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:2])[0][0]
38
  return score
39
 
40
- def format_resume_to_yaml(api_key, file_content, job_description):
41
  """Formats the content of a resume PDF file to YAML and calculates its relevance to a job description."""
42
  if not file_content:
43
  raise ValueError("The uploaded file is empty.")
44
 
 
45
  os.environ['OPENAI_API_KEY'] = api_key
46
  resume_text = extract_text_from_pdf_binary(file_content)
47
 
48
- # Additional step to calculate the resume score relative to the job description.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  resume_score = calculate_resume_score(resume_text, job_description)
50
-
51
- # Formatting the resume to YAML (the existing implementation continues here)...
52
- # Assume llm_chain.predict and other logic here as before.
53
 
54
- # For demonstration, return both formatted resume (in real use, integrate this properly) and score.
55
- return "Formatted Resume in YAML (placeholder)", resume_score
56
 
57
  def main():
58
  """Main function to launch the Gradio interface with job description input."""
59
  iface = gr.Interface(
60
- fn=format_resume_to_yaml,
61
  inputs=[
62
  Textbox(label="Enter your OpenAI API Key"),
63
  File(label="Upload your PDF resume", type="binary"),
@@ -67,8 +104,8 @@ def main():
67
  Textbox(label="Formatted Resume in YAML"),
68
  Textbox(label="Resume Score")
69
  ],
70
- title="Resume to YAML Formatter with ATS Scoring",
71
- description="Upload a PDF resume, paste the job description, and enter your OpenAI API key to get the resume formatted to a YAML template and score its relevance to the job."
72
  )
73
  iface.launch(debug=True, share=True)
74
 
 
37
  score = cosine_similarity(tfidf_matrix[0:1], tfidf_matrix[1:2])[0][0]
38
  return score
39
 
40
+ def format_resume_and_score(api_key, file_content, job_description):
41
  """Formats the content of a resume PDF file to YAML and calculates its relevance to a job description."""
42
  if not file_content:
43
  raise ValueError("The uploaded file is empty.")
44
 
45
+ # Set the OpenAI API key
46
  os.environ['OPENAI_API_KEY'] = api_key
47
  resume_text = extract_text_from_pdf_binary(file_content)
48
 
49
+ # Formatting the resume to YAML
50
+ template = """Format the provided resume to this YAML template:
51
+ ---
52
+ name: ''
53
+ phoneNumbers:
54
+ - ''
55
+ websites:
56
+ - ''
57
+ emails:
58
+ - ''
59
+ dateOfBirth: ''
60
+ addresses:
61
+ - street: ''
62
+ city: ''
63
+ state: ''
64
+ zip: ''
65
+ country: ''
66
+ summary: ''
67
+ education:
68
+ - school: ''
69
+ degree: ''
70
+ fieldOfStudy: ''
71
+ startDate: ''
72
+ endDate: ''
73
+ workExperience:
74
+ - company: ''
75
+ position: ''
76
+ startDate: ''
77
+ endDate: ''
78
+ skills:
79
+ - name: ''
80
+ certifications:
81
+ - name: ''
82
+ """
83
+ prompt = PromptTemplate(input_variables=["resume_text"], template=template)
84
+ memory = ConversationBufferMemory(memory_key="resume_text")
85
+
86
+ llm_chain = LLMChain(llm=ChatOpenAI(model="gpt-3.5-turbo"), prompt=prompt, verbose=True, memory=memory)
87
+ formatted_resume = llm_chain.predict(human_input=resume_text)
88
+
89
+ # Calculate the resume score relative to the job description.
90
  resume_score = calculate_resume_score(resume_text, job_description)
 
 
 
91
 
92
+ return formatted_resume, resume_score
 
93
 
94
  def main():
95
  """Main function to launch the Gradio interface with job description input."""
96
  iface = gr.Interface(
97
+ fn=format_resume_and_score,
98
  inputs=[
99
  Textbox(label="Enter your OpenAI API Key"),
100
  File(label="Upload your PDF resume", type="binary"),
 
104
  Textbox(label="Formatted Resume in YAML"),
105
  Textbox(label="Resume Score")
106
  ],
107
+ title="Resume Formatter and Relevance Scorer",
108
+ description="Upload a PDF resume, paste the job description, and enter your OpenAI API key to format your resume to a YAML template and score its relevance to the job."
109
  )
110
  iface.launch(debug=True, share=True)
111