File size: 4,192 Bytes
19a9439
feca185
 
19a9439
 
 
 
feca185
 
 
 
 
 
19a9439
 
 
 
 
 
 
 
 
 
 
 
 
 
 
feca185
19a9439
 
 
 
 
feca185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19a9439
a1320e5
19a9439
a1320e5
 
feca185
a1320e5
 
19a9439
a1320e5
19a9439
a1320e5
19a9439
 
feca185
 
 
 
 
 
 
19a9439
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
feca185
 
 
 
 
 
19a9439
 
 
 
 
 
 
feca185
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
import streamlit as st
from langchain_groq import ChatGroq
from langchain_core.prompts import PromptTemplate
import fitz  # PyMuPDF
import requests
from bs4 import BeautifulSoup

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

# Function to extract text from a PDF file
def extract_text_from_pdf(pdf_file):
    text = ""
    with fitz.open(stream=pdf_file.read(), filetype="pdf") as doc:
        for page in doc:
            text += page.get_text()
    return text

# Function to extract the job description from a given URL
def extract_job_description(job_link):
    try:
        response = requests.get(job_link)
        response.raise_for_status()
        soup = BeautifulSoup(response.text, 'html.parser')
        job_description = soup.get_text(separator='\n')
        return job_description.strip()
    except Exception as e:
        st.error(f"Error fetching job description: {e}")
        return ""

# Function to extract requirements from the job description using ChatGroq
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

# Function to generate an email using ChatGroq
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

# Streamlit App
def main():
    st.title("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.")

if __name__ == "__main__":
    main()