Spaces:
Sleeping
Sleeping
Commit
·
536ba94
1
Parent(s):
23c19e0
Enhance app.py to support an 'other' section in CV parsing for miscellaneous content. Update email generation prompt to include additional information and contact details. Refine response handling to ensure only the generated email is displayed, improving user experience and clarity.
Browse files
app.py
CHANGED
@@ -16,6 +16,7 @@ def parse_cv_sections(text: str) -> Dict[str, str]:
|
|
16 |
'experience': '',
|
17 |
'skills': '',
|
18 |
'projects': '',
|
|
|
19 |
}
|
20 |
|
21 |
# Common section headers in CVs
|
@@ -37,13 +38,20 @@ def parse_cv_sections(text: str) -> Dict[str, str]:
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
return sections
|
49 |
|
@@ -92,10 +100,12 @@ client = InferenceClient(token=access_token)
|
|
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"""
|
|
|
|
|
96 |
{job_description}
|
97 |
|
98 |
-
|
99 |
Experience:
|
100 |
{cv_sections['experience']}
|
101 |
|
@@ -105,17 +115,21 @@ Skills:
|
|
105 |
Education:
|
106 |
{cv_sections['education']}
|
107 |
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
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 |
-
|
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."""
|
@@ -204,8 +218,9 @@ with tab1:
|
|
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 |
-
|
208 |
-
|
|
|
209 |
else:
|
210 |
st.warning("Please upload a CV and enter a job description.")
|
211 |
|
|
|
16 |
'experience': '',
|
17 |
'skills': '',
|
18 |
'projects': '',
|
19 |
+
'other': '', # Added other section for miscellaneous content
|
20 |
}
|
21 |
|
22 |
# Common section headers in CVs
|
|
|
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 |
|
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 |
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."""
|
|
|
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 |
|