Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- requirements.txt +4 -0
- streamlitApp.py +73 -0
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
torch
|
3 |
+
transformers
|
4 |
+
numpy
|
streamlitApp.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import BertTokenizer, BertModel
|
3 |
+
import torch
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
# Load the pre-trained BERT model and tokenizer
|
7 |
+
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
|
8 |
+
model = BertModel.from_pretrained('bert-base-uncased')
|
9 |
+
|
10 |
+
# Define criteria for scoring
|
11 |
+
criteria = {
|
12 |
+
"technical": ["machine learning", "data", "preprocess", "decision tree", "SVM", "neural network", "hyperparameter"],
|
13 |
+
"problem_solving": ["cross-validation", "grid search", "evaluate", "optimize", "performance"],
|
14 |
+
"communication": ["I would", "then", "and", "also"]
|
15 |
+
}
|
16 |
+
|
17 |
+
# Function to encode a response using BERT
|
18 |
+
def encode_response(response):
|
19 |
+
inputs = tokenizer(response, return_tensors='pt', padding=True, truncation=True)
|
20 |
+
outputs = model(**inputs)
|
21 |
+
return outputs.last_hidden_state.mean(dim=1).squeeze().detach().numpy()
|
22 |
+
|
23 |
+
# Function to score the response based on predefined criteria
|
24 |
+
def score_response(response, criteria):
|
25 |
+
scores = {}
|
26 |
+
for criterion, keywords in criteria.items():
|
27 |
+
scores[criterion] = sum([1 for word in keywords if word in response]) / len(keywords)
|
28 |
+
return scores
|
29 |
+
|
30 |
+
# Function to rank candidates by average score
|
31 |
+
def rank_candidates(candidates):
|
32 |
+
for candidate in candidates:
|
33 |
+
avg_score = np.mean(list(candidate['scores'].values()))
|
34 |
+
candidate['avg_score'] = avg_score
|
35 |
+
ranked_candidates = sorted(candidates, key=lambda x: x['avg_score'], reverse=True)
|
36 |
+
return ranked_candidates
|
37 |
+
|
38 |
+
# Streamlit app
|
39 |
+
st.title("AI Role Candidate Screening")
|
40 |
+
|
41 |
+
# Input for the number of candidates
|
42 |
+
num_candidates = st.number_input("Enter the number of candidates:", min_value=1, max_value=10, value=3)
|
43 |
+
|
44 |
+
# Create input fields for candidate names and responses
|
45 |
+
mock_interviews = []
|
46 |
+
for i in range(num_candidates):
|
47 |
+
name = st.text_input(f"Enter the name of Candidate {i+1}:", key=f"name_{i}")
|
48 |
+
response = st.text_area(f"Enter the interview response for {name}:", key=f"response_{i}")
|
49 |
+
if name and response:
|
50 |
+
mock_interviews.append({"name": name, "response": response})
|
51 |
+
|
52 |
+
# Analyze the candidates when the user clicks the "Analyze" button
|
53 |
+
if st.button('Analyze Responses'):
|
54 |
+
if mock_interviews:
|
55 |
+
# Encode and score each candidate
|
56 |
+
scored_candidates = []
|
57 |
+
for candidate in mock_interviews:
|
58 |
+
scores = score_response(candidate['response'], criteria)
|
59 |
+
candidate['scores'] = scores
|
60 |
+
candidate['encoded'] = encode_response(candidate['response'])
|
61 |
+
scored_candidates.append(candidate)
|
62 |
+
|
63 |
+
# Rank the candidates based on scores
|
64 |
+
ranked_candidates = rank_candidates(scored_candidates)
|
65 |
+
|
66 |
+
# Display the results
|
67 |
+
st.write("### Candidate Rankings")
|
68 |
+
for rank, candidate in enumerate(ranked_candidates, 1):
|
69 |
+
st.write(f"**Rank {rank}: {candidate['name']}**")
|
70 |
+
st.write(f"Average Score: {candidate['avg_score']:.2f}")
|
71 |
+
st.write(f"Scores: {candidate['scores']}")
|
72 |
+
else:
|
73 |
+
st.write("Please enter candidate responses.")
|