Dhahlan2000 commited on
Commit
dc6ab46
·
1 Parent(s): 02386cb

Refactor app.py to streamline CV parsing and email generation. Removed the 'other' section from CV parsing logic, simplifying the handling of miscellaneous content. Updated the email prompt to clarify instructions and enhance professionalism. Increased max_new_tokens for model generation to improve response quality. Improved UI feedback for generated emails in the Streamlit interface.

Browse files
Files changed (1) hide show
  1. app.py +12 -27
app.py CHANGED
@@ -16,7 +16,6 @@ def parse_cv_sections(text: str) -> Dict[str, str]:
16
  'experience': '',
17
  'skills': '',
18
  'projects': '',
19
- 'other': '', # Added other section for miscellaneous content
20
  }
21
 
22
  # Common section headers in CVs
@@ -38,20 +37,13 @@ def parse_cv_sections(text: str) -> Dict[str, str]:
38
  continue
39
 
40
  # Check if line is a section header
41
- section_found = False
42
  for section, pattern in section_patterns.items():
43
  if re.search(pattern, line, re.IGNORECASE):
44
  current_section = section
45
- section_found = True
46
  break
47
-
48
  if current_section and line:
49
- # If line doesn't match any known section and we haven't found a section yet,
50
- # put it in 'other'
51
- if not section_found and current_section is None:
52
- sections['other'] += line + '\n'
53
- else:
54
- sections[current_section] += line + '\n'
55
 
56
  return sections
57
 
@@ -100,12 +92,10 @@ client = InferenceClient(token=access_token)
100
 
101
  def create_email_prompt(job_description: str, cv_sections: Dict[str, str]) -> str:
102
  """Create a detailed prompt for email generation."""
103
- return f"""Based on the following information, generate only a professional job application email.
104
-
105
- Job Description:
106
  {job_description}
107
 
108
- CV Details:
109
  Experience:
110
  {cv_sections['experience']}
111
 
@@ -115,21 +105,17 @@ Skills:
115
  Education:
116
  {cv_sections['education']}
117
 
118
- Additional Information:
119
- {cv_sections['other']}
120
-
121
- Contact Information:
122
- {cv_sections['contact']}
123
-
124
- Guidelines:
125
  1. Start with a proper greeting
126
  2. First paragraph: Express interest in the position and mention how you found it
127
- 3. Second paragraph: Highlight 2-3 most relevant experiences that match the job requirements
128
  4. Third paragraph: Mention specific skills that align with the role
129
  5. Closing paragraph: Express enthusiasm for an interview and provide contact information
130
  6. End with a professional closing
131
 
132
- Generate only the email, without any additional text or explanations."""
 
 
133
 
134
  def conversation_predict(input_text: str, cv_sections: Dict[str, str]):
135
  """Generate a response using the model with improved prompting."""
@@ -141,7 +127,7 @@ def conversation_predict(input_text: str, cv_sections: Dict[str, str]):
141
  # Generate a response with the model
142
  outputs = model.generate(
143
  input_ids,
144
- max_new_tokens=512,
145
  temperature=0.7,
146
  top_p=0.95,
147
  do_sample=True
@@ -218,9 +204,8 @@ with tab1:
218
  if st.button("Generate Email"):
219
  if message and cv_file and isinstance(cv_sections, dict):
220
  response = conversation_predict(message, cv_sections)
221
- # Remove any potential prompt text from the response
222
- email_text = response.split("Email:")[-1].strip()
223
- st.text_area("Generated Email", email_text, height=400)
224
  else:
225
  st.warning("Please upload a CV and enter a job description.")
226
 
 
16
  'experience': '',
17
  'skills': '',
18
  'projects': '',
 
19
  }
20
 
21
  # Common section headers in CVs
 
37
  continue
38
 
39
  # Check if line is a section header
 
40
  for section, pattern in section_patterns.items():
41
  if re.search(pattern, line, re.IGNORECASE):
42
  current_section = section
 
43
  break
44
+
45
  if current_section and line:
46
+ sections[current_section] += line + '\n'
 
 
 
 
 
47
 
48
  return sections
49
 
 
92
 
93
  def create_email_prompt(job_description: str, cv_sections: Dict[str, str]) -> str:
94
  """Create a detailed prompt for email generation."""
95
+ return f"""Job Description:
 
 
96
  {job_description}
97
 
98
+ Your CV Details:
99
  Experience:
100
  {cv_sections['experience']}
101
 
 
105
  Education:
106
  {cv_sections['education']}
107
 
108
+ Instructions: Write a professional job application email following these guidelines:
 
 
 
 
 
 
109
  1. Start with a proper greeting
110
  2. First paragraph: Express interest in the position and mention how you found it
111
+ 3. Second paragraph: Highlight 2-3 most relevant experiences from your CV that match the job requirements
112
  4. Third paragraph: Mention specific skills that align with the role
113
  5. Closing paragraph: Express enthusiasm for an interview and provide contact information
114
  6. End with a professional closing
115
 
116
+ Keep the tone professional, confident, and enthusiastic. Be concise but impactful.
117
+
118
+ Email:"""
119
 
120
  def conversation_predict(input_text: str, cv_sections: Dict[str, str]):
121
  """Generate a response using the model with improved prompting."""
 
127
  # Generate a response with the model
128
  outputs = model.generate(
129
  input_ids,
130
+ max_new_tokens=2048,
131
  temperature=0.7,
132
  top_p=0.95,
133
  do_sample=True
 
204
  if st.button("Generate Email"):
205
  if message and cv_file and isinstance(cv_sections, dict):
206
  response = conversation_predict(message, cv_sections)
207
+ st.markdown("### Generated Email:")
208
+ st.markdown(response)
 
209
  else:
210
  st.warning("Please upload a CV and enter a job description.")
211