Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -36,6 +36,8 @@ def extract_info_with_claude(resume_content: bytes) -> str:
|
|
36 |
temp_file.write(resume_content)
|
37 |
temp_file_path = temp_file.name
|
38 |
|
|
|
|
|
39 |
prompt = """
|
40 |
Extract the following information from the given resume:
|
41 |
1. Full Name
|
@@ -49,6 +51,8 @@ def extract_info_with_claude(resume_content: bytes) -> str:
|
|
49 |
Extract all experiences, including projects, leadership, work experience, research, etc.
|
50 |
"""
|
51 |
|
|
|
|
|
52 |
try:
|
53 |
message = anthropic.messages.create(
|
54 |
model="claude-3-haiku-20240307",
|
@@ -69,23 +73,33 @@ def extract_info_with_claude(resume_content: bytes) -> str:
|
|
69 |
}]
|
70 |
)
|
71 |
extracted_info = message.content[0].text
|
|
|
|
|
|
|
72 |
except Exception as e:
|
73 |
extracted_info = f"An error occurred: {e}"
|
|
|
74 |
finally:
|
75 |
# Clean up the temporary file
|
76 |
os.unlink(temp_file_path)
|
|
|
77 |
|
78 |
return extracted_info
|
79 |
|
80 |
def parse_resume(uploaded_file: UploadedFile) -> Tuple[str, List[Dict]]:
|
81 |
"""Parse a resume file and return name and projects."""
|
82 |
try:
|
|
|
83 |
resume_content = uploaded_file.getvalue()
|
|
|
|
|
84 |
extracted_info = extract_info_with_claude(resume_content)
|
|
|
85 |
|
86 |
# Parse the extracted information
|
87 |
lines = extracted_info.split('\n')
|
88 |
name = lines[0].split(': ')[1] if len(lines) > 0 and ': ' in lines[0] else "Unknown"
|
|
|
89 |
|
90 |
projects = []
|
91 |
project_started = False
|
@@ -100,6 +114,9 @@ def parse_resume(uploaded_file: UploadedFile) -> Tuple[str, List[Dict]]:
|
|
100 |
project_description = project_parts[1]
|
101 |
projects.append({"name": project_name, "description": project_description})
|
102 |
|
|
|
|
|
|
|
103 |
# Store in MongoDB
|
104 |
resume_data = {
|
105 |
"name": name,
|
@@ -107,11 +124,12 @@ def parse_resume(uploaded_file: UploadedFile) -> Tuple[str, List[Dict]]:
|
|
107 |
"full_content": resume_content.decode('utf-8', errors='ignore')
|
108 |
}
|
109 |
resume_collection.insert_one(resume_data)
|
|
|
110 |
|
111 |
return name, projects
|
112 |
|
113 |
except Exception as e:
|
114 |
-
st.error(f"Error processing resume: {e}")
|
115 |
return "Unknown", []
|
116 |
|
117 |
def process_resumes(uploaded_files: List[UploadedFile]) -> Dict:
|
@@ -120,8 +138,10 @@ def process_resumes(uploaded_files: List[UploadedFile]) -> Dict:
|
|
120 |
progress_bar = st.progress(0)
|
121 |
|
122 |
for idx, file in enumerate(uploaded_files):
|
|
|
|
|
123 |
if file.type != "application/pdf":
|
124 |
-
st.warning(f"Skipping {file.name}: Not a PDF file")
|
125 |
continue
|
126 |
|
127 |
try:
|
@@ -132,8 +152,9 @@ def process_resumes(uploaded_files: List[UploadedFile]) -> Dict:
|
|
132 |
}
|
133 |
# Update progress
|
134 |
progress_bar.progress((idx + 1) / len(uploaded_files))
|
|
|
135 |
except Exception as e:
|
136 |
-
st.error(f"Error processing {file.name}: {e}")
|
137 |
|
138 |
return results
|
139 |
|
@@ -142,11 +163,19 @@ def display_results(results: Dict):
|
|
142 |
if not results:
|
143 |
return
|
144 |
|
145 |
-
st.subheader("Processed Resumes")
|
146 |
|
147 |
for filename, data in results.items():
|
148 |
with st.expander(f"π {data['name']} ({filename})"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
if data['projects']:
|
|
|
150 |
df = pd.DataFrame(data['projects'])
|
151 |
st.dataframe(
|
152 |
df,
|
@@ -157,13 +186,13 @@ def display_results(results: Dict):
|
|
157 |
hide_index=True
|
158 |
)
|
159 |
else:
|
160 |
-
st.info("No projects found in this resume")
|
161 |
|
162 |
def main():
|
163 |
-
st.title("IntraTalent Resume Processor")
|
164 |
|
165 |
# File uploader section
|
166 |
-
st.header("Upload Resumes")
|
167 |
uploaded_files = st.file_uploader(
|
168 |
"Upload up to 10 resumes (PDF only)",
|
169 |
type=['pdf'],
|
@@ -173,37 +202,40 @@ def main():
|
|
173 |
|
174 |
# Validate number of files
|
175 |
if uploaded_files and len(uploaded_files) > 10:
|
176 |
-
st.error("Maximum 10 files allowed. Please remove some files.")
|
177 |
return
|
178 |
|
179 |
# Process button
|
180 |
-
if uploaded_files and st.button("Process Resumes"):
|
181 |
with st.spinner("Processing resumes..."):
|
|
|
182 |
results = process_resumes(uploaded_files)
|
183 |
st.session_state['processed_results'] = results
|
|
|
184 |
display_results(results)
|
185 |
|
186 |
# Query section
|
187 |
-
st.header("Search Projects")
|
188 |
query = st.text_area(
|
189 |
"Enter your project requirements",
|
190 |
placeholder="Example: Looking for team members with experience in machine learning and computer vision...",
|
191 |
height=100
|
192 |
)
|
193 |
|
194 |
-
if query and st.button("Search"):
|
195 |
if 'processed_results' not in st.session_state:
|
196 |
-
st.warning("Please process some resumes first!")
|
197 |
return
|
198 |
|
199 |
with st.spinner("Searching for matches..."):
|
|
|
200 |
# Here you would implement the embedding and similarity search
|
201 |
# Using the code from your original script
|
202 |
-
st.success("Search completed!")
|
203 |
# Display results in a nice format
|
204 |
-
st.subheader("Top Matches")
|
205 |
# Placeholder for search results
|
206 |
-
st.info("Feature coming soon: Will display matching projects and candidates based on similarity search")
|
207 |
|
208 |
if __name__ == "__main__":
|
209 |
main()
|
|
|
36 |
temp_file.write(resume_content)
|
37 |
temp_file_path = temp_file.name
|
38 |
|
39 |
+
st.write("π Created temporary PDF file for Claude analysis")
|
40 |
+
|
41 |
prompt = """
|
42 |
Extract the following information from the given resume:
|
43 |
1. Full Name
|
|
|
51 |
Extract all experiences, including projects, leadership, work experience, research, etc.
|
52 |
"""
|
53 |
|
54 |
+
st.write("π€ Sending request to Claude API...")
|
55 |
+
|
56 |
try:
|
57 |
message = anthropic.messages.create(
|
58 |
model="claude-3-haiku-20240307",
|
|
|
73 |
}]
|
74 |
)
|
75 |
extracted_info = message.content[0].text
|
76 |
+
st.write("β
Received response from Claude:")
|
77 |
+
st.code(extracted_info, language="text")
|
78 |
+
|
79 |
except Exception as e:
|
80 |
extracted_info = f"An error occurred: {e}"
|
81 |
+
st.error(f"β API Error: {e}")
|
82 |
finally:
|
83 |
# Clean up the temporary file
|
84 |
os.unlink(temp_file_path)
|
85 |
+
st.write("ποΈ Cleaned up temporary file")
|
86 |
|
87 |
return extracted_info
|
88 |
|
89 |
def parse_resume(uploaded_file: UploadedFile) -> Tuple[str, List[Dict]]:
|
90 |
"""Parse a resume file and return name and projects."""
|
91 |
try:
|
92 |
+
st.write(f"π Processing resume: {uploaded_file.name}")
|
93 |
resume_content = uploaded_file.getvalue()
|
94 |
+
st.write("π Extracted raw content from PDF")
|
95 |
+
|
96 |
extracted_info = extract_info_with_claude(resume_content)
|
97 |
+
st.write("π Parsing extracted information...")
|
98 |
|
99 |
# Parse the extracted information
|
100 |
lines = extracted_info.split('\n')
|
101 |
name = lines[0].split(': ')[1] if len(lines) > 0 and ': ' in lines[0] else "Unknown"
|
102 |
+
st.write(f"π€ Extracted name: {name}")
|
103 |
|
104 |
projects = []
|
105 |
project_started = False
|
|
|
114 |
project_description = project_parts[1]
|
115 |
projects.append({"name": project_name, "description": project_description})
|
116 |
|
117 |
+
st.write("π Extracted projects:")
|
118 |
+
st.json(projects)
|
119 |
+
|
120 |
# Store in MongoDB
|
121 |
resume_data = {
|
122 |
"name": name,
|
|
|
124 |
"full_content": resume_content.decode('utf-8', errors='ignore')
|
125 |
}
|
126 |
resume_collection.insert_one(resume_data)
|
127 |
+
st.write("πΎ Stored data in MongoDB")
|
128 |
|
129 |
return name, projects
|
130 |
|
131 |
except Exception as e:
|
132 |
+
st.error(f"β Error processing resume: {e}")
|
133 |
return "Unknown", []
|
134 |
|
135 |
def process_resumes(uploaded_files: List[UploadedFile]) -> Dict:
|
|
|
138 |
progress_bar = st.progress(0)
|
139 |
|
140 |
for idx, file in enumerate(uploaded_files):
|
141 |
+
st.write(f"\n---\n### Processing file {idx + 1} of {len(uploaded_files)}")
|
142 |
+
|
143 |
if file.type != "application/pdf":
|
144 |
+
st.warning(f"β οΈ Skipping {file.name}: Not a PDF file")
|
145 |
continue
|
146 |
|
147 |
try:
|
|
|
152 |
}
|
153 |
# Update progress
|
154 |
progress_bar.progress((idx + 1) / len(uploaded_files))
|
155 |
+
st.write(f"β
Successfully processed {file.name}")
|
156 |
except Exception as e:
|
157 |
+
st.error(f"β Error processing {file.name}: {e}")
|
158 |
|
159 |
return results
|
160 |
|
|
|
163 |
if not results:
|
164 |
return
|
165 |
|
166 |
+
st.subheader("π Processed Resumes")
|
167 |
|
168 |
for filename, data in results.items():
|
169 |
with st.expander(f"π {data['name']} ({filename})"):
|
170 |
+
st.write("π·οΈ File details:")
|
171 |
+
st.json({
|
172 |
+
"filename": filename,
|
173 |
+
"name": data['name'],
|
174 |
+
"number_of_projects": len(data['projects'])
|
175 |
+
})
|
176 |
+
|
177 |
if data['projects']:
|
178 |
+
st.write("π Projects:")
|
179 |
df = pd.DataFrame(data['projects'])
|
180 |
st.dataframe(
|
181 |
df,
|
|
|
186 |
hide_index=True
|
187 |
)
|
188 |
else:
|
189 |
+
st.info("βΉοΈ No projects found in this resume")
|
190 |
|
191 |
def main():
|
192 |
+
st.title("π― IntraTalent Resume Processor")
|
193 |
|
194 |
# File uploader section
|
195 |
+
st.header("π€ Upload Resumes")
|
196 |
uploaded_files = st.file_uploader(
|
197 |
"Upload up to 10 resumes (PDF only)",
|
198 |
type=['pdf'],
|
|
|
202 |
|
203 |
# Validate number of files
|
204 |
if uploaded_files and len(uploaded_files) > 10:
|
205 |
+
st.error("β οΈ Maximum 10 files allowed. Please remove some files.")
|
206 |
return
|
207 |
|
208 |
# Process button
|
209 |
+
if uploaded_files and st.button("π Process Resumes"):
|
210 |
with st.spinner("Processing resumes..."):
|
211 |
+
st.write("π Starting resume processing...")
|
212 |
results = process_resumes(uploaded_files)
|
213 |
st.session_state['processed_results'] = results
|
214 |
+
st.write("β¨ Processing complete!")
|
215 |
display_results(results)
|
216 |
|
217 |
# Query section
|
218 |
+
st.header("π Search Projects")
|
219 |
query = st.text_area(
|
220 |
"Enter your project requirements",
|
221 |
placeholder="Example: Looking for team members with experience in machine learning and computer vision...",
|
222 |
height=100
|
223 |
)
|
224 |
|
225 |
+
if query and st.button("π Search"):
|
226 |
if 'processed_results' not in st.session_state:
|
227 |
+
st.warning("β οΈ Please process some resumes first!")
|
228 |
return
|
229 |
|
230 |
with st.spinner("Searching for matches..."):
|
231 |
+
st.write("π Preparing to search...")
|
232 |
# Here you would implement the embedding and similarity search
|
233 |
# Using the code from your original script
|
234 |
+
st.success("β
Search completed!")
|
235 |
# Display results in a nice format
|
236 |
+
st.subheader("π― Top Matches")
|
237 |
# Placeholder for search results
|
238 |
+
st.info("π Feature coming soon: Will display matching projects and candidates based on similarity search")
|
239 |
|
240 |
if __name__ == "__main__":
|
241 |
main()
|