AdithyaSNair commited on
Commit
3019fd8
·
verified ·
1 Parent(s): 56d08a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +103 -16
app.py CHANGED
@@ -1,38 +1,42 @@
1
  import streamlit as st
 
2
  from langchain_groq import ChatGroq
3
  from langchain_core.prompts import PromptTemplate
4
- import fitz # PyMuPDF
5
  import requests
6
  from bs4 import BeautifulSoup
 
7
 
8
- # Initialize the LLM with your Groq API key
9
  llm = ChatGroq(
10
  temperature=0,
11
  groq_api_key='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', # Replace with your Groq API key
12
  model_name="llama-3.1-70b-versatile"
13
  )
14
 
15
- # Function to extract text from a PDF file
16
  def extract_text_from_pdf(pdf_file):
17
  text = ""
18
- with fitz.open(stream=pdf_file.read(), filetype="pdf") as doc:
19
- for page in doc:
20
- text += page.get_text()
21
- return text
 
 
 
 
22
 
23
- # Function to extract the job description from a given URL
24
  def extract_job_description(job_link):
25
  try:
26
  response = requests.get(job_link)
27
  response.raise_for_status()
28
  soup = BeautifulSoup(response.text, 'html.parser')
 
29
  job_description = soup.get_text(separator='\n')
30
  return job_description.strip()
31
  except Exception as e:
32
  st.error(f"Error fetching job description: {e}")
33
  return ""
34
 
35
- # Function to extract requirements from the job description using ChatGroq
36
  def extract_requirements(job_description):
37
  prompt_text = f"""
38
  The following is a job description:
@@ -51,7 +55,6 @@ def extract_requirements(job_description):
51
  requirements = response.content.strip()
52
  return requirements
53
 
54
- # Function to generate an email using ChatGroq
55
  def generate_email(job_description, requirements, resume_text):
56
  prompt_text = f"""
57
  Given the following job description:
@@ -63,10 +66,12 @@ And the following extracted requirements:
63
  And the following resume text:
64
  {resume_text}
65
 
66
- Write a cold email as Adithya S Nair, a recent graduate in Computer Science with a focus on Artificial Intelligence and Machine Learning. Highlight your relevant skills and experiences from the resume, emphasizing how you, as a fresher, can bring value to the client’s company. Mention key projects, internships, and any leadership experiences that align with the job description and requirements. Ensure the email is concise and professional.
67
-
68
- Email:
 
69
 
 
70
  """
71
 
72
  prompt = PromptTemplate.from_template(prompt_text)
@@ -76,9 +81,12 @@ Email:
76
  email_text = response.content.strip()
77
  return email_text
78
 
79
- # Streamlit App
80
- def main():
81
- st.title("Automated Email Generator")
 
 
 
82
 
83
  st.write("""
84
  This application generates a personalized email based on a job posting and your resume.
@@ -123,5 +131,84 @@ def main():
123
  else:
124
  st.error("Failed to generate email.")
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  if __name__ == "__main__":
127
  main()
 
1
  import streamlit as st
2
+ from streamlit_option_menu import option_menu
3
  from langchain_groq import ChatGroq
4
  from langchain_core.prompts import PromptTemplate
5
+ import fitz
6
  import requests
7
  from bs4 import BeautifulSoup
8
+ import uuid
9
 
 
10
  llm = ChatGroq(
11
  temperature=0,
12
  groq_api_key='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', # Replace with your Groq API key
13
  model_name="llama-3.1-70b-versatile"
14
  )
15
 
16
+
17
  def extract_text_from_pdf(pdf_file):
18
  text = ""
19
+ try:
20
+ with fitz.open(stream=pdf_file.read(), filetype="pdf") as doc:
21
+ for page in doc:
22
+ text += page.get_text()
23
+ return text
24
+ except Exception as e:
25
+ st.error(f"Error extracting text from resume: {e}")
26
+ return ""
27
 
 
28
  def extract_job_description(job_link):
29
  try:
30
  response = requests.get(job_link)
31
  response.raise_for_status()
32
  soup = BeautifulSoup(response.text, 'html.parser')
33
+ # You might need to adjust the selectors based on the website's structure
34
  job_description = soup.get_text(separator='\n')
35
  return job_description.strip()
36
  except Exception as e:
37
  st.error(f"Error fetching job description: {e}")
38
  return ""
39
 
 
40
  def extract_requirements(job_description):
41
  prompt_text = f"""
42
  The following is a job description:
 
55
  requirements = response.content.strip()
56
  return requirements
57
 
 
58
  def generate_email(job_description, requirements, resume_text):
59
  prompt_text = f"""
60
  Given the following job description:
 
66
  And the following resume text:
67
  {resume_text}
68
 
69
+ Write a cold email as Adithya S Nair, a recent graduate in Computer Science with a focus on Artificial Intelligence and Machine Learning.
70
+ Highlight your relevant skills and experiences from the resume, emphasizing how you, as a fresher, can bring value to the client’s company.
71
+ Mention key projects, internships, and any leadership experiences that align with the job description and requirements.
72
+ Ensure the email is concise and professional.
73
 
74
+ Email:
75
  """
76
 
77
  prompt = PromptTemplate.from_template(prompt_text)
 
81
  email_text = response.content.strip()
82
  return email_text
83
 
84
+ # -------------------------------
85
+ # Page Functions
86
+ # -------------------------------
87
+
88
+ def email_generator_page():
89
+ st.header("Automated Email Generator")
90
 
91
  st.write("""
92
  This application generates a personalized email based on a job posting and your resume.
 
131
  else:
132
  st.error("Failed to generate email.")
133
 
134
+ def resume_analysis_page():
135
+ st.header("Resume Analysis and Optimization")
136
+
137
+ uploaded_file = st.file_uploader("Upload your resume (PDF format):", type="pdf")
138
+
139
+ if uploaded_file:
140
+ resume_text = extract_text_from_pdf(uploaded_file)
141
+ if resume_text:
142
+ st.success("Resume uploaded successfully!")
143
+ # Perform analysis
144
+ st.subheader("Extracted Information")
145
+ # Example: Extracted skills
146
+ skills = extract_skills(resume_text)
147
+ st.write("**Skills:**", ', '.join(skills))
148
+ # Provide optimization suggestions
149
+ st.subheader("Optimization Suggestions")
150
+ st.write("- **Keyword Optimization:** Consider adding more industry-specific keywords relevant to your desired roles.")
151
+ st.write("- **Formatting:** Ensure consistent formatting for headings and bullet points to enhance readability.")
152
+ st.write("- **Experience Details:** Provide specific achievements and quantify your accomplishments where possible.")
153
+ else:
154
+ st.error("Failed to extract text from resume.")
155
+
156
+ def job_recommendations_page():
157
+ st.header("Job Recommendations")
158
+
159
+ uploaded_file = st.file_uploader("Upload your resume (PDF format):", type="pdf")
160
+
161
+ if uploaded_file:
162
+ resume_text = extract_text_from_pdf(uploaded_file)
163
+ if resume_text:
164
+ st.success("Resume uploaded successfully!")
165
+ # Fetch job recommendations
166
+ st.subheader("Recommended Jobs")
167
+ jobs = get_job_recommendations(resume_text)
168
+ for job in jobs:
169
+ st.write(f"**{job['title']}** at {job['company']}")
170
+ st.markdown(f"[Apply Here]({job['link']})")
171
+ else:
172
+ st.error("Failed to extract text from resume.")
173
+
174
+ # Placeholder for job recommendations - Replace with actual implementation
175
+ def get_job_recommendations(resume_text):
176
+ # Implement job fetching logic, possibly integrating with job APIs
177
+ # This is a placeholder example
178
+ return [
179
+ {"title": "Data Scientist", "company": "TechCorp", "link": "https://example.com/job1"},
180
+ {"title": "Machine Learning Engineer", "company": "InnovateX", "link": "https://example.com/job2"},
181
+ ]
182
+
183
+ def extract_skills(text):
184
+ # Implement advanced skill extraction logic
185
+ # For demonstration, using a predefined skill list
186
+ skills_list = ["Python", "Machine Learning", "Data Analysis", "SQL", "Communication", "Leadership"]
187
+ extracted_skills = [skill for skill in skills_list if skill.lower() in text.lower()]
188
+ return extracted_skills
189
+
190
+ # -------------------------------
191
+ # Main App with Sidebar Navigation
192
+ # -------------------------------
193
+
194
+ def main():
195
+ st.set_page_config(page_title="Job Application Assistant", layout="wide")
196
+
197
+ with st.sidebar:
198
+ selected = option_menu(
199
+ "Main Menu",
200
+ ["Email Generator", "Resume Analysis", "Job Recommendations"],
201
+ icons=["envelope", "file-person", "briefcase"],
202
+ menu_icon="cast",
203
+ default_index=0,
204
+ )
205
+
206
+ if selected == "Email Generator":
207
+ email_generator_page()
208
+ elif selected == "Resume Analysis":
209
+ resume_analysis_page()
210
+ elif selected == "Job Recommendations":
211
+ job_recommendations_page()
212
+
213
  if __name__ == "__main__":
214
  main()