File size: 7,579 Bytes
19a9439
3019fd8
feca185
 
3019fd8
19a9439
 
3019fd8
19a9439
feca185
 
 
 
 
19a9439
3019fd8
19a9439
 
3019fd8
 
 
 
 
 
 
 
19a9439
 
 
 
 
 
3019fd8
feca185
19a9439
 
 
 
 
feca185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19a9439
a1320e5
19a9439
a1320e5
 
feca185
a1320e5
 
19a9439
3019fd8
 
 
 
19a9439
3019fd8
19a9439
feca185
 
 
 
 
 
 
19a9439
3019fd8
 
 
 
 
 
19a9439
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
feca185
 
 
 
 
 
19a9439
 
 
 
 
 
 
feca185
19a9439
 
 
 
 
 
3019fd8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19a9439
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import streamlit as st
from streamlit_option_menu import option_menu
from langchain_groq import ChatGroq
from langchain_core.prompts import PromptTemplate
import fitz 
import requests
from bs4 import BeautifulSoup
import uuid

llm = ChatGroq(
    temperature=0,
    groq_api_key='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',  # Replace with your Groq API key
    model_name="llama-3.1-70b-versatile"
)


def extract_text_from_pdf(pdf_file):
    text = ""
    try:
        with fitz.open(stream=pdf_file.read(), filetype="pdf") as doc:
            for page in doc:
                text += page.get_text()
        return text
    except Exception as e:
        st.error(f"Error extracting text from resume: {e}")
        return ""

def extract_job_description(job_link):
    try:
        response = requests.get(job_link)
        response.raise_for_status()
        soup = BeautifulSoup(response.text, 'html.parser')
        # You might need to adjust the selectors based on the website's structure
        job_description = soup.get_text(separator='\n')
        return job_description.strip()
    except Exception as e:
        st.error(f"Error fetching job description: {e}")
        return ""

def extract_requirements(job_description):
    prompt_text = f"""
    The following is a job description:

    {job_description}

    Extract the list of job requirements, qualifications, and skills from the job description. Provide them as a numbered list.

    Requirements:
    """

    prompt = PromptTemplate.from_template(prompt_text)
    chain = prompt | llm
    response = chain.invoke({})

    requirements = response.content.strip()
    return requirements

def generate_email(job_description, requirements, resume_text):
    prompt_text = f"""
    Given the following job description:
{job_description}

And the following extracted requirements:
{requirements}

And the following resume text:
{resume_text}

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.

    Email:
    """

    prompt = PromptTemplate.from_template(prompt_text)
    chain = prompt | llm
    response = chain.invoke({})

    email_text = response.content.strip()
    return email_text

# -------------------------------
# Page Functions
# -------------------------------

def email_generator_page():
    st.header("Automated Email Generator")

    st.write("""
    This application generates a personalized email based on a job posting and your resume.
    """)

    # Input fields
    job_link = st.text_input("Enter the job link:")
    uploaded_file = st.file_uploader("Upload your resume (PDF format):", type="pdf")

    if st.button("Generate Email"):
        if not job_link:
            st.error("Please enter a job link.")
            return
        if not uploaded_file:
            st.error("Please upload your resume.")
            return

        with st.spinner("Processing..."):
            # Extract job description
            job_description = extract_job_description(job_link)
            if not job_description:
                st.error("Failed to extract job description.")
                return

            # Extract requirements
            requirements = extract_requirements(job_description)
            if not requirements:
                st.error("Failed to extract requirements.")
                return

            # Extract resume text
            resume_text = extract_text_from_pdf(uploaded_file)
            if not resume_text:
                st.error("Failed to extract text from resume.")
                return

            # Generate email
            email_text = generate_email(job_description, requirements, resume_text)
            if email_text:
                st.subheader("Generated Email:")
                st.write(email_text)
            else:
                st.error("Failed to generate email.")

def resume_analysis_page():
    st.header("Resume Analysis and Optimization")

    uploaded_file = st.file_uploader("Upload your resume (PDF format):", type="pdf")

    if uploaded_file:
        resume_text = extract_text_from_pdf(uploaded_file)
        if resume_text:
            st.success("Resume uploaded successfully!")
            # Perform analysis
            st.subheader("Extracted Information")
            # Example: Extracted skills
            skills = extract_skills(resume_text)
            st.write("**Skills:**", ', '.join(skills))
            # Provide optimization suggestions
            st.subheader("Optimization Suggestions")
            st.write("- **Keyword Optimization:** Consider adding more industry-specific keywords relevant to your desired roles.")
            st.write("- **Formatting:** Ensure consistent formatting for headings and bullet points to enhance readability.")
            st.write("- **Experience Details:** Provide specific achievements and quantify your accomplishments where possible.")
        else:
            st.error("Failed to extract text from resume.")

def job_recommendations_page():
    st.header("Job Recommendations")

    uploaded_file = st.file_uploader("Upload your resume (PDF format):", type="pdf")

    if uploaded_file:
        resume_text = extract_text_from_pdf(uploaded_file)
        if resume_text:
            st.success("Resume uploaded successfully!")
            # Fetch job recommendations
            st.subheader("Recommended Jobs")
            jobs = get_job_recommendations(resume_text)
            for job in jobs:
                st.write(f"**{job['title']}** at {job['company']}")
                st.markdown(f"[Apply Here]({job['link']})")
        else:
            st.error("Failed to extract text from resume.")

# Placeholder for job recommendations - Replace with actual implementation
def get_job_recommendations(resume_text):
    # Implement job fetching logic, possibly integrating with job APIs
    # This is a placeholder example
    return [
        {"title": "Data Scientist", "company": "TechCorp", "link": "https://example.com/job1"},
        {"title": "Machine Learning Engineer", "company": "InnovateX", "link": "https://example.com/job2"},
    ]

def extract_skills(text):
    # Implement advanced skill extraction logic
    # For demonstration, using a predefined skill list
    skills_list = ["Python", "Machine Learning", "Data Analysis", "SQL", "Communication", "Leadership"]
    extracted_skills = [skill for skill in skills_list if skill.lower() in text.lower()]
    return extracted_skills

# -------------------------------
# Main App with Sidebar Navigation
# -------------------------------

def main():
    st.set_page_config(page_title="Job Application Assistant", layout="wide")

    with st.sidebar:
        selected = option_menu(
            "Main Menu",
            ["Email Generator", "Resume Analysis", "Job Recommendations"],
            icons=["envelope", "file-person", "briefcase"],
            menu_icon="cast",
            default_index=0,
        )

    if selected == "Email Generator":
        email_generator_page()
    elif selected == "Resume Analysis":
        resume_analysis_page()
    elif selected == "Job Recommendations":
        job_recommendations_page()

if __name__ == "__main__":
    main()