siddhartharya commited on
Commit
bc5de14
·
verified ·
1 Parent(s): 0724750

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -35
app.py CHANGED
@@ -5,7 +5,6 @@ import os
5
  # Load API keys securely from environment variables
6
  proxycurl_api_key = os.getenv("PROXYCURL_API_KEY") # Add your Proxycurl API key to your environment variables
7
  groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
8
- serpapi_key = os.getenv("SERPAPI_API_KEY") # Add your SerpAPI key to your environment variables
9
 
10
  # Function to use Proxycurl API to get the LinkedIn profile data
11
  def get_linkedin_profile_via_proxycurl(linkedin_profile_url):
@@ -23,52 +22,55 @@ def get_linkedin_profile_via_proxycurl(linkedin_profile_url):
23
  else:
24
  return "Error: Unable to fetch LinkedIn profile"
25
 
26
- # Function to use SerpAPI to fetch company and role information
27
- def get_company_and_role_info(company_name, role):
28
- query = f"{company_name} {role} job description"
29
- url = f"https://serpapi.com/search.json?engine=google&q={query}&api_key={serpapi_key}"
 
 
30
 
31
- response = requests.get(url)
32
 
33
  if response.status_code == 200:
34
- results = response.json()
35
- # Extract information about the company and role from the search results
36
- company_info = []
37
- for result in results.get("organic_results", []):
38
- if "linkedin.com" not in result.get("link", ""):
39
- company_info.append(result.get("snippet", ""))
40
- return "\n".join(company_info[:2]) # Limit to 2 top results
41
  else:
42
- return "Error fetching company and role information."
 
 
 
 
43
 
44
  # Helper function to call Groq Cloud LLM API to generate and correct the email
45
- def generate_and_correct_email(bio, company_name, role, company_info):
46
  url = "https://api.groq.com/openai/v1/chat/completions"
47
  headers = {
48
  "Authorization": f"Bearer {groq_api_key}",
49
  "Content-Type": "application/json",
50
  }
51
 
52
- # Updated prompt with a focus on professionalism, relevance, and creativity
53
  prompt = f"""
54
- Write a professional, concise, and compelling email applying for the {role} position at {company_name}.
55
- Use this bio to highlight the candidate's skills and experience: {bio}.
56
-
57
- Additionally, here is some information about the company and the role:
58
- {company_info}
59
 
60
  The email should:
61
- - Be professional, creative, and tailored to the company and role.
62
- - Creatively emphasize the candidate’s key skills and experience, aligning them with the job's requirements.
63
- - Attract the company's attention by focusing on how the candidate's background can bring value to the role and company.
64
- - Be concise but engaging, leaving a strong impression on the recruiter.
65
- - Include a clear call to action, encouraging the company to interview the candidate.
66
-
 
 
67
  Structure the email as follows:
68
- 1. **Introduction**: Briefly introduce the candidate and the role they are applying for.
69
- 2. **Skills & Experience**: Creatively map the candidate’s skills and experience to the job's key requirements, focusing on relevance.
70
- 3. **Value Proposition**: Highlight how the candidate’s experience will contribute to the company's success.
71
- 4. **Call to Action**: Encourage the company to set up an interview to explore how the candidate can add value.
 
 
72
  """
73
 
74
  # Construct the data payload for the API request
@@ -96,13 +98,14 @@ def create_email(name, company_name, role, email, phone, linkedin_profile_url):
96
  if linkedin_profile_url:
97
  bio = get_linkedin_profile_via_proxycurl(linkedin_profile_url)
98
  else:
99
- bio = f"{name} is a professional."
100
 
101
- # Step 2: Fetch company and role information using SerpAPI
102
- company_info = get_company_and_role_info(company_name, role)
 
103
 
104
  # Step 3: Generate the email using Groq Cloud LLM
105
- generated_email = generate_and_correct_email(bio, company_name, role, company_info)
106
 
107
  # Step 4: Add the user's email, phone number, and LinkedIn profile to the signature
108
  signature = f"\n\nBest regards,\n{name}\nEmail: {email}\nPhone: {phone}\nLinkedIn: {linkedin_profile_url if linkedin_profile_url else 'Not provided'}"
 
5
  # Load API keys securely from environment variables
6
  proxycurl_api_key = os.getenv("PROXYCURL_API_KEY") # Add your Proxycurl API key to your environment variables
7
  groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
 
8
 
9
  # Function to use Proxycurl API to get the LinkedIn profile data
10
  def get_linkedin_profile_via_proxycurl(linkedin_profile_url):
 
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):
27
+ headers = {
28
+ "Authorization": f"Bearer {proxycurl_api_key}",
29
+ }
30
+ url = f"https://nubela.co/proxycurl/api/v2/linkedin/company?company_name={company_name}"
31
 
32
+ response = requests.get(url, headers=headers)
33
 
34
  if response.status_code == 200:
35
+ data = response.json()
36
+ company_info = data.get("description", "No detailed company info available.")
37
+ return company_info
 
 
 
 
38
  else:
39
+ return "Error: Unable to fetch company information."
40
+
41
+ # Placeholder for role description; could be enhanced to scrape or fetch real role data
42
+ 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 to gather information about the company and role, and generate a compelling email
54
  prompt = f"""
55
+ Write a professional and tailored email applying for the {role} position at {company_name}.
56
+ The candidates 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 experience, mapping them directly to the job requirements. The role description is: {role_description}.
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.
65
+ - End with a strong call to action, encouraging the company to schedule an interview to discuss how the candidate can contribute to their success.
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**: Creatively map the candidate’s skills and experience to the job's key requirements and how these will benefit the company.
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
+ The writing style should be professional, concise, and leave a strong, memorable impression on the company.
74
  """
75
 
76
  # Construct the data payload for the API request
 
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'}"