Update app.py
Browse files
app.py
CHANGED
@@ -17,10 +17,13 @@ def get_linkedin_profile_via_proxycurl(linkedin_profile_url):
|
|
17 |
|
18 |
if response.status_code == 200:
|
19 |
data = response.json()
|
|
|
20 |
bio = data.get("summary", "No bio available")
|
21 |
-
|
|
|
|
|
22 |
else:
|
23 |
-
return "Error: Unable to fetch LinkedIn profile"
|
24 |
|
25 |
# Function to get company information via Proxycurl Company API
|
26 |
def get_company_info(company_name):
|
@@ -43,22 +46,26 @@ def get_role_description(role_name, company_name):
|
|
43 |
return f"The role of {role_name} at {company_name} involves..."
|
44 |
|
45 |
# Helper function to call Groq Cloud LLM API to generate and correct the email
|
46 |
-
def generate_and_correct_email(bio, company_name, role, company_info, role_description):
|
47 |
url = "https://api.groq.com/openai/v1/chat/completions"
|
48 |
headers = {
|
49 |
"Authorization": f"Bearer {groq_api_key}",
|
50 |
"Content-Type": "application/json",
|
51 |
}
|
52 |
|
53 |
-
# New, detailed prompt
|
54 |
prompt = f"""
|
55 |
-
Write a professional
|
|
|
56 |
The candidate’s bio is: {bio}.
|
57 |
|
|
|
|
|
|
|
58 |
The email should:
|
59 |
- Be professional, engaging, and customized to the company's culture and the role’s requirements.
|
60 |
-
- Include relevant company details: {company_info}.
|
61 |
-
- Highlight the candidate’s skills and
|
62 |
- Emphasize how the candidate’s background aligns with the company’s values and mission.
|
63 |
- Attract the company's attention by focusing on how the candidate's background can bring value to the role and the company's future goals.
|
64 |
- Use a tone that is persuasive but not overly promotional.
|
@@ -66,11 +73,11 @@ def generate_and_correct_email(bio, company_name, role, company_info, role_descr
|
|
66 |
|
67 |
Structure the email as follows:
|
68 |
1. **Introduction**: Briefly introduce the candidate and state the role they are applying for.
|
69 |
-
2. **Skills & Experience**:
|
70 |
3. **Alignment with the Company**: Emphasize how the candidate’s background fits with the company's mission, values, and goals.
|
71 |
4. **Call to Action**: Encourage the company to schedule an interview to further discuss the candidate’s fit for the role.
|
72 |
|
73 |
-
|
74 |
"""
|
75 |
|
76 |
# Construct the data payload for the API request
|
@@ -96,23 +103,25 @@ def generate_and_correct_email(bio, company_name, role, company_info, role_descr
|
|
96 |
def create_email(name, company_name, role, email, phone, linkedin_profile_url):
|
97 |
# Step 1: Fetch LinkedIn profile using Proxycurl API if LinkedIn URL is provided
|
98 |
if linkedin_profile_url:
|
99 |
-
bio = get_linkedin_profile_via_proxycurl(linkedin_profile_url)
|
100 |
else:
|
101 |
bio = f"{name} is a professional." # Default bio if no LinkedIn URL is provided
|
|
|
102 |
|
103 |
# Step 2: Fetch company information and role description
|
104 |
company_info = get_company_info(company_name)
|
105 |
role_description = get_role_description(role, company_name)
|
106 |
|
107 |
# Step 3: Generate the email using Groq Cloud LLM
|
108 |
-
generated_email = generate_and_correct_email(bio, company_name, role, company_info, role_description)
|
109 |
|
110 |
# Step 4: Add the user's email, phone number, and LinkedIn profile to the signature
|
111 |
signature = f"\n\nBest regards,\n{name}\nEmail: {email}\nPhone: {phone}\nLinkedIn: {linkedin_profile_url if linkedin_profile_url else 'Not provided'}"
|
112 |
|
113 |
-
# Ensure the body doesn't include any redundant 'Best regards' and just append our signature
|
114 |
-
|
115 |
-
|
|
|
116 |
|
117 |
# Return the final polished email with the signature
|
118 |
return generated_email + signature
|
|
|
17 |
|
18 |
if response.status_code == 200:
|
19 |
data = response.json()
|
20 |
+
# Extract relevant skills and experiences from LinkedIn profile
|
21 |
bio = data.get("summary", "No bio available")
|
22 |
+
skills = data.get("skills", []) # List of skills from the LinkedIn profile
|
23 |
+
experiences = data.get("experiences", []) # List of experiences from the LinkedIn profile
|
24 |
+
return bio, skills, experiences
|
25 |
else:
|
26 |
+
return "Error: Unable to fetch LinkedIn profile", [], []
|
27 |
|
28 |
# Function to get company information via Proxycurl Company API
|
29 |
def get_company_info(company_name):
|
|
|
46 |
return f"The role of {role_name} at {company_name} involves..."
|
47 |
|
48 |
# Helper function to call Groq Cloud LLM API to generate and correct the email
|
49 |
+
def generate_and_correct_email(bio, company_name, role, company_info, role_description, skills, experiences):
|
50 |
url = "https://api.groq.com/openai/v1/chat/completions"
|
51 |
headers = {
|
52 |
"Authorization": f"Bearer {groq_api_key}",
|
53 |
"Content-Type": "application/json",
|
54 |
}
|
55 |
|
56 |
+
# New, detailed prompt with emphasis on correlating LinkedIn skills and experience to the job role
|
57 |
prompt = f"""
|
58 |
+
Write a professional email applying for the {role} position at {company_name}.
|
59 |
+
|
60 |
The candidate’s bio is: {bio}.
|
61 |
|
62 |
+
The candidate's LinkedIn profile highlights the following skills: {', '.join(skills)}.
|
63 |
+
The candidate has the following experiences relevant to the job: {', '.join([exp['title'] for exp in experiences])}.
|
64 |
+
|
65 |
The email should:
|
66 |
- Be professional, engaging, and customized to the company's culture and the role’s requirements.
|
67 |
+
- Include relevant company details: {company_info}.
|
68 |
+
- Highlight the candidate’s skills and experiences from LinkedIn, mapping them directly to the job's requirements. The role description is: {role_description}.
|
69 |
- Emphasize how the candidate’s background aligns with the company’s values and mission.
|
70 |
- Attract the company's attention by focusing on how the candidate's background can bring value to the role and the company's future goals.
|
71 |
- Use a tone that is persuasive but not overly promotional.
|
|
|
73 |
|
74 |
Structure the email as follows:
|
75 |
1. **Introduction**: Briefly introduce the candidate and state the role they are applying for.
|
76 |
+
2. **Skills & Experience**: Map the candidate’s skills and experience from LinkedIn to the job's key requirements.
|
77 |
3. **Alignment with the Company**: Emphasize how the candidate’s background fits with the company's mission, values, and goals.
|
78 |
4. **Call to Action**: Encourage the company to schedule an interview to further discuss the candidate’s fit for the role.
|
79 |
|
80 |
+
Ensure that redundant sign-offs like 'Best regards' or 'Sincerely' are not included.
|
81 |
"""
|
82 |
|
83 |
# Construct the data payload for the API request
|
|
|
103 |
def create_email(name, company_name, role, email, phone, linkedin_profile_url):
|
104 |
# Step 1: Fetch LinkedIn profile using Proxycurl API if LinkedIn URL is provided
|
105 |
if linkedin_profile_url:
|
106 |
+
bio, skills, experiences = get_linkedin_profile_via_proxycurl(linkedin_profile_url)
|
107 |
else:
|
108 |
bio = f"{name} is a professional." # Default bio if no LinkedIn URL is provided
|
109 |
+
skills, experiences = [], []
|
110 |
|
111 |
# Step 2: Fetch company information and role description
|
112 |
company_info = get_company_info(company_name)
|
113 |
role_description = get_role_description(role, company_name)
|
114 |
|
115 |
# Step 3: Generate the email using Groq Cloud LLM
|
116 |
+
generated_email = generate_and_correct_email(bio, company_name, role, company_info, role_description, skills, experiences)
|
117 |
|
118 |
# Step 4: Add the user's email, phone number, and LinkedIn profile to the signature
|
119 |
signature = f"\n\nBest regards,\n{name}\nEmail: {email}\nPhone: {phone}\nLinkedIn: {linkedin_profile_url if linkedin_profile_url else 'Not provided'}"
|
120 |
|
121 |
+
# Ensure the body doesn't include any redundant 'Best regards' or 'Sincerely' and just append our signature
|
122 |
+
for phrase in ["Best regards", "Sincerely"]:
|
123 |
+
if phrase in generated_email:
|
124 |
+
generated_email = generated_email.split(phrase)[0].strip()
|
125 |
|
126 |
# Return the final polished email with the signature
|
127 |
return generated_email + signature
|