Kensium commited on
Commit
5dd50e1
Β·
verified Β·
1 Parent(s): a719c03

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -38
app.py CHANGED
@@ -1,38 +1,85 @@
1
- # Q&A Chatbot
2
- from langchain.llms import OpenAI
3
-
4
- #from dotenv import load_dotenv
5
-
6
- #load_dotenv() # take environment variables from .env.
7
-
8
- import streamlit as st
9
- import os
10
-
11
-
12
- ## Function to load OpenAI model and get respones
13
-
14
- def get_openai_response(question):
15
- llm=OpenAI(model_name="text-davinci-003",temperature=0.5)
16
- response=llm(question)
17
- return response
18
-
19
- ##initialize our streamlit app
20
-
21
- st.set_page_config(page_title="Q&A Demo")
22
-
23
- st.header("Langchain Application")
24
-
25
- input=st.text_input("Input: ",key="input")
26
- response=get_openai_response(input)
27
-
28
- submit=st.button("Ask the question")
29
-
30
- ## If ask button is clicked
31
-
32
- if submit:
33
- st.subheader("The Response is")
34
- st.write(response)
35
-
36
-
37
-
38
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import PyPDF2
3
+ import re
4
+
5
+ # Function to extract text from a PDF
6
+ def extract_text_from_pdf(uploaded_file):
7
+ pdf_reader = PyPDF2.PdfReader(uploaded_file)
8
+ text = " ".join([page.extract_text() for page in pdf_reader.pages if page.extract_text()])
9
+ return text
10
+
11
+ # Function to extract skills from text (reference resumes and user resumes)
12
+ def extract_skills_from_text(text):
13
+ # A simple way to extract skills based on words in the resume.
14
+ # This can be more advanced by integrating NER (Named Entity Recognition) or using predefined skill lists.
15
+ skills = re.findall(r'\b[A-Za-z]+\b', text.lower()) # Extract words
16
+ skills = set(skills) # Remove duplicates
17
+ return skills
18
+
19
+ # Function to evaluate user's resume based on job description
20
+ def evaluate_resume(candidate_text, job_description_text):
21
+ # Extract skills dynamically from job description
22
+ job_description_skills = extract_skills_from_text(job_description_text)
23
+
24
+ # Extract skills from candidate's resume
25
+ candidate_skills = extract_skills_from_text(candidate_text)
26
+
27
+ # Calculate matching skills
28
+ matching_skills = job_description_skills.intersection(candidate_skills)
29
+ missing_skills = job_description_skills.difference(candidate_skills)
30
+
31
+ # Calculate improvement skills (skills present in the JD but not in candidate's resume)
32
+ improvement_skills = job_description_skills.difference(matching_skills)
33
+
34
+ # Calculate matching percentage (based on skills)
35
+ matching_percentage = (len(matching_skills) / len(job_description_skills)) * 100 if len(job_description_skills) > 0 else 0
36
+
37
+ result = {
38
+ "matching_skills": list(matching_skills),
39
+ "missing_skills": list(missing_skills),
40
+ "improvement_skills": list(improvement_skills),
41
+ "matching_percentage": round(matching_percentage, 2)
42
+ }
43
+
44
+ return result
45
+
46
+ # Streamlit UI
47
+ st.title("πŸ“„ Resume Screening with Job Description Matching")
48
+ st.write("Upload a candidate's resume and provide a job description to check the matching percentage based on skills.")
49
+
50
+ # Upload job description
51
+ st.subheader("Upload Job Description")
52
+ job_description_file = st.file_uploader("Upload Job Description (PDF)", type=["pdf"])
53
+
54
+ # Upload candidate resume
55
+ st.subheader("Upload Candidate Resume")
56
+ uploaded_file = st.file_uploader("Upload Candidate Resume (PDF)", type=["pdf"])
57
+
58
+ if uploaded_file and job_description_file:
59
+ st.write("πŸ” **Processing resume and job description...**")
60
+
61
+ # Extract text from candidate resume
62
+ candidate_text = extract_text_from_pdf(uploaded_file)
63
+
64
+ # Extract text from job description
65
+ job_description_text = extract_text_from_pdf(job_description_file)
66
+
67
+ # Evaluate resume based on job description
68
+ evaluation = evaluate_resume(candidate_text, job_description_text)
69
+
70
+ # Display results
71
+ st.subheader("πŸ“Œ Evaluation Result:")
72
+ st.write(f"**πŸ”’ Matching Percentage:** {evaluation['matching_percentage']}%")
73
+ # st.write(f"**βœ… Matching Skills:** {', '.join(evaluation['matching_skills']) or 'None'}")
74
+ # st.write(f"**❌ Missing Skills:** {', '.join(evaluation['missing_skills']) or 'None'}")
75
+ st.write(f"**πŸ’‘ Improvement Skills (Required but Missing):** {', '.join(evaluation['improvement_skills']) or 'None'}")
76
+
77
+
78
+ if evaluation["matching_percentage"] > 70:
79
+ st.success("βœ… Resume is a strong match for the job description!")
80
+ elif evaluation["matching_percentage"] > 40:
81
+ st.warning("⚠️ Resume is a partial match for the job description.")
82
+ else:
83
+ st.error("❌ Resume does not match well with the job description.")
84
+ else:
85
+ st.write("Please upload both the job description and candidate resume.")