Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from src.data_preparation import load_data
|
4 |
+
from src.model import initialize_openai, fine_tune_model, extract_keywords, rate_skills, compare_candidates
|
5 |
+
|
6 |
+
st.title("MLE Trial Task")
|
7 |
+
|
8 |
+
# Upload OpenAI API Key
|
9 |
+
api_key = st.text_input("Enter your OpenAI API Key", type="password")
|
10 |
+
initialize_openai(api_key)
|
11 |
+
|
12 |
+
# Load training data
|
13 |
+
data = load_data("data/train_dataset.csv")
|
14 |
+
|
15 |
+
# Fine-tune the model
|
16 |
+
fine_tuned_model = "gpt-4o-2024-08-06"
|
17 |
+
|
18 |
+
# Streamlit app sections
|
19 |
+
st.sidebar.title("Navigation")
|
20 |
+
page = st.sidebar.radio("Go to", ["Evaluate Test Data", "Test with Random Data"])
|
21 |
+
|
22 |
+
if page == "Evaluate Test Data":
|
23 |
+
st.title("Evaluate Test Data")
|
24 |
+
|
25 |
+
uploaded_test_file = st.file_uploader("Upload Test Data CSV", type="csv")
|
26 |
+
|
27 |
+
if uploaded_test_file:
|
28 |
+
test_data = pd.read_csv(uploaded_test_file)
|
29 |
+
|
30 |
+
correct_predictions = 0
|
31 |
+
total_predictions = len(test_data)
|
32 |
+
|
33 |
+
for index, row in test_data.iterrows():
|
34 |
+
job_description = row['role']
|
35 |
+
candidateA_resume = row['candidateAResume']
|
36 |
+
candidateB_resume = row['candidateBResume']
|
37 |
+
candidateA_transcript = row['candidateATranscript']
|
38 |
+
candidateB_transcript = row['candidateBTranscript']
|
39 |
+
winner_id = row['winnerId']
|
40 |
+
|
41 |
+
candidateA_details = {
|
42 |
+
"keywords": extract_keywords(candidateA_resume, job_description, fine_tuned_model),
|
43 |
+
"skills": rate_skills(candidateA_transcript, job_description, fine_tuned_model),
|
44 |
+
"candidate_id": row['candidateAId']
|
45 |
+
}
|
46 |
+
candidateB_details = {
|
47 |
+
"keywords": extract_keywords(candidateB_resume, job_description, fine_tuned_model),
|
48 |
+
"skills": rate_skills(candidateB_transcript, job_description, fine_tuned_model),
|
49 |
+
"candidate_id": row['candidateBId']
|
50 |
+
}
|
51 |
+
|
52 |
+
preferred_candidate = compare_candidates(candidateA_details, candidateB_details, job_description, fine_tuned_model)
|
53 |
+
print(f"Preferred Candidate: {preferred_candidate}", f"Winner ID: {winner_id}")
|
54 |
+
if preferred_candidate == winner_id:
|
55 |
+
correct_predictions += 1
|
56 |
+
|
57 |
+
accuracy = correct_predictions / total_predictions
|
58 |
+
st.write(f"Accuracy: {accuracy}")
|
59 |
+
st.write(f"Preferred Candidates: {correct_predictions} out of {total_predictions}")
|
60 |
+
|
61 |
+
elif page == "Test with Random Data":
|
62 |
+
st.title("Test with Random Data")
|
63 |
+
|
64 |
+
job_description = st.text_area("Job Description")
|
65 |
+
candidateA_resume = st.text_area("Candidate A Resume")
|
66 |
+
candidateB_resume = st.text_area("Candidate B Resume")
|
67 |
+
candidateA_transcript = st.text_area("Candidate A Transcript")
|
68 |
+
candidateB_transcript = st.text_area("Candidate B Transcript")
|
69 |
+
|
70 |
+
if st.button("Compare Candidates"):
|
71 |
+
candidateA_details = {
|
72 |
+
"keywords": extract_keywords(candidateA_resume, job_description, fine_tuned_model),
|
73 |
+
"skills": rate_skills(candidateA_transcript, job_description, fine_tuned_model)
|
74 |
+
}
|
75 |
+
candidateB_details = {
|
76 |
+
"keywords": extract_keywords(candidateB_resume, job_description, fine_tuned_model),
|
77 |
+
"skills": rate_skills(candidateB_transcript, job_description, fine_tuned_model)
|
78 |
+
}
|
79 |
+
|
80 |
+
preferred_candidate = compare_candidates(candidateA_details, candidateB_details, job_description, fine_tuned_model)
|
81 |
+
st.write(f"Preferred Candidate: {preferred_candidate}")
|