Mohit5899 commited on
Commit
34a80f7
·
verified ·
1 Parent(s): 727bd4a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +157 -0
app.py ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from dotenv import load_dotenv
4
+ from groq import Groq
5
+ import PyPDF2
6
+
7
+ # Load environment variables
8
+ load_dotenv()
9
+
10
+ # Initialize Groq client
11
+ client = Groq(
12
+ api_key=os.getenv("GROQ_API_KEY"),
13
+ )
14
+
15
+ def extract_text_from_pdf(file):
16
+ reader = PyPDF2.PdfReader(file)
17
+ text = ''
18
+ for page_num in range(len(reader.pages)):
19
+ page = reader.pages[page_num]
20
+ text += page.extract_text()
21
+ return text
22
+
23
+ def analyze_job_description(job_description):
24
+ prompt = f"Here is a job description:\n\n{job_description}\n\nPlease extract the key requirements and skills needed for this position."
25
+ chat_completion = client.chat.completions.create(
26
+ messages=[
27
+ {
28
+ "role": "user",
29
+ "content": prompt,
30
+ }
31
+ ],
32
+ model="llama3-8b-8192",
33
+ )
34
+ return chat_completion.choices[0].message.content
35
+
36
+ def get_resume_feedback(content, job_requirements):
37
+ prompt = f"Here is the content of the resume:\n\n{content}\n\nBased on the following job requirements and skills:\n\n{job_requirements}\n\nPlease provide suggestions for improving this resume, including keyword optimization and ATS compatibility checks."
38
+ chat_completion = client.chat.completions.create(
39
+ messages=[
40
+ {
41
+ "role": "user",
42
+ "content": prompt,
43
+ }
44
+ ],
45
+ model="llama3-8b-8192",
46
+ )
47
+ return chat_completion.choices[0].message.content
48
+
49
+ def score_resume_against_job_description(resume_text, job_description_text):
50
+ resume_words = set(resume_text.lower().split())
51
+ job_description_words = set(job_description_text.lower().split())
52
+ common_words = resume_words.intersection(job_description_words)
53
+ score = len(common_words) / len(job_description_words) * 100
54
+ return score
55
+
56
+ def chat_with_llm(resume_text, job_description_text, user_question):
57
+ prompt = f"Here is the content of the resume:\n\n{resume_text}\n\nHere is the job description:\n\n{job_description_text}\n\nQuestion: {user_question}\n\nAnswer:"
58
+ chat_completion = client.chat.completions.create(
59
+ messages=[
60
+ {
61
+ "role": "user",
62
+ "content": prompt,
63
+ }
64
+ ],
65
+ model="llama3-8b-8192",
66
+ )
67
+ return chat_completion.choices[0].message.content
68
+
69
+ def main():
70
+ st.title("Resume Upgrader with ATS, Job Description Matching, and Chat Capabilities")
71
+
72
+ # Upload resume files
73
+ uploaded_resumes = st.file_uploader("Upload your resume (PDF)", type=["pdf"], accept_multiple_files=True)
74
+
75
+ # Initialize job_description_text to avoid UnboundLocalError
76
+ job_description_text = None
77
+
78
+ # Upload or input job description
79
+ job_description_option = st.radio("How would you like to provide the job description?", ("Upload PDF", "Enter Text"))
80
+
81
+ if job_description_option == "Upload PDF":
82
+ job_description_file = st.file_uploader("Upload job description (PDF)", type=["pdf"])
83
+ if job_description_file:
84
+ job_description_text = extract_text_from_pdf(job_description_file)
85
+ else:
86
+ job_description_text = st.text_area("Enter job description")
87
+
88
+ if uploaded_resumes and job_description_text:
89
+ st.write("Uploaded Resumes:")
90
+ for uploaded_file in uploaded_resumes:
91
+ st.write(uploaded_file.name)
92
+
93
+ if job_description_option == "Upload PDF":
94
+ st.write("Uploaded Job Description:")
95
+ st.write(job_description_file.name)
96
+ else:
97
+ st.write("Entered Job Description:")
98
+
99
+ # Extract text from all uploaded resumes
100
+ combined_resume_text = ""
101
+ for uploaded_file in uploaded_resumes:
102
+ combined_resume_text += extract_text_from_pdf(uploaded_file) + "\n\n"
103
+
104
+ st.write("All documents uploaded and text extracted successfully!")
105
+
106
+ # Analyze the job description
107
+ job_requirements = analyze_job_description(job_description_text)
108
+ st.write("Extracted Job Requirements and Skills:")
109
+ st.write(job_requirements)
110
+
111
+ # Initialize session state for resume feedback history
112
+ if "resume_feedback" not in st.session_state:
113
+ st.session_state.resume_feedback = []
114
+
115
+ # Provide options for the user
116
+ option = st.selectbox("What would you like to do?", ("Get Feedback and ATS Check", "Get Score", "Chat"))
117
+
118
+ if option == "Get Feedback and ATS Check":
119
+ if st.button("Get Feedback"):
120
+ feedback = get_resume_feedback(combined_resume_text, job_requirements)
121
+ st.session_state.resume_feedback.append((feedback, None, None))
122
+
123
+ elif option == "Get Score":
124
+ if st.button("Get Score"):
125
+ score = score_resume_against_job_description(combined_resume_text, job_description_text)
126
+ st.session_state.resume_feedback.append((None, None, score))
127
+
128
+ elif option == "Chat":
129
+ if "chat_history" not in st.session_state:
130
+ st.session_state.chat_history = []
131
+
132
+ user_question = st.text_input("Enter your question:")
133
+
134
+ if st.button("Ask"):
135
+ if user_question:
136
+ response = chat_with_llm(combined_resume_text, job_description_text, user_question)
137
+ st.session_state.chat_history.append((user_question, response))
138
+ user_question = "" # Clear input field
139
+
140
+ if st.session_state.chat_history:
141
+ st.subheader("Chat History")
142
+ for i, (q, a) in enumerate(st.session_state.chat_history):
143
+ st.write(f"**Q{i+1}:** {q}")
144
+ st.write(f"**A{i+1}:** {a}")
145
+
146
+ # Display feedback history
147
+ if st.session_state.resume_feedback:
148
+ st.subheader("Resume Improvement Suggestions and Scores")
149
+ for i, (feedback, ats_feedback, score) in enumerate(st.session_state.resume_feedback):
150
+ if feedback:
151
+ st.write(f"**Feedback for Resume {i+1}:**")
152
+ st.write(feedback)
153
+ if score is not None:
154
+ st.write(f"**Match Score for Resume {i+1}:** {score:.2f}%")
155
+
156
+ if __name__ == "__main__":
157
+ main()