|
import gradio as gr |
|
import requests |
|
import os |
|
|
|
|
|
proxycurl_api_key = os.getenv("PROXYCURL_API_KEY") |
|
groq_api_key = os.getenv("GROQ_CLOUD_API_KEY") |
|
|
|
|
|
def get_linkedin_profile_via_proxycurl(linkedin_profile_url): |
|
headers = { |
|
"Authorization": f"Bearer {proxycurl_api_key}", |
|
} |
|
url = f"https://nubela.co/proxycurl/api/v2/linkedin?url={linkedin_profile_url}" |
|
|
|
response = requests.get(url, headers=headers) |
|
|
|
if response.status_code == 200: |
|
data = response.json() |
|
bio = data.get("summary", "No bio available") |
|
return bio |
|
else: |
|
return "Error: Unable to fetch LinkedIn profile" |
|
|
|
|
|
def get_company_info(company_name): |
|
headers = { |
|
"Authorization": f"Bearer {proxycurl_api_key}", |
|
} |
|
url = f"https://nubela.co/proxycurl/api/v2/linkedin/company?company_name={company_name}" |
|
|
|
response = requests.get(url, headers=headers) |
|
|
|
if response.status_code == 200: |
|
data = response.json() |
|
company_info = data.get("description", "No detailed company info available.") |
|
return company_info |
|
else: |
|
return "Error: Unable to fetch company information." |
|
|
|
|
|
def get_role_description(role_name, company_name): |
|
return f"The role of {role_name} at {company_name} involves..." |
|
|
|
|
|
def generate_and_correct_email(bio, company_name, role, company_info, role_description): |
|
url = "https://api.groq.com/openai/v1/chat/completions" |
|
headers = { |
|
"Authorization": f"Bearer {groq_api_key}", |
|
"Content-Type": "application/json", |
|
} |
|
|
|
|
|
prompt = f""" |
|
Write a professional and tailored email applying for the {role} position at {company_name}. |
|
The candidate’s bio is: {bio}. |
|
|
|
The email should: |
|
- Be professional, engaging, and customized to the company's culture and the role’s requirements. |
|
- Include relevant company details: {company_info}. |
|
- Highlight the candidate’s skills and experience, mapping them directly to the job requirements. The role description is: {role_description}. |
|
- Emphasize how the candidate’s background aligns with the company’s values and mission. |
|
- 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. |
|
- Use a tone that is persuasive but not overly promotional. |
|
- End with a strong call to action, encouraging the company to schedule an interview to discuss how the candidate can contribute to their success. |
|
|
|
Structure the email as follows: |
|
1. **Introduction**: Briefly introduce the candidate and state the role they are applying for. |
|
2. **Skills & Experience**: Creatively map the candidate’s skills and experience to the job's key requirements and how these will benefit the company. |
|
3. **Alignment with the Company**: Emphasize how the candidate’s background fits with the company's mission, values, and goals. |
|
4. **Call to Action**: Encourage the company to schedule an interview to further discuss the candidate’s fit for the role. |
|
|
|
The writing style should be professional, concise, and leave a strong, memorable impression on the company. |
|
""" |
|
|
|
|
|
data = { |
|
"messages": [ |
|
{ |
|
"role": "user", |
|
"content": prompt |
|
} |
|
], |
|
"model": "llama3-8b-8192" |
|
} |
|
|
|
response = requests.post(url, headers=headers, json=data) |
|
|
|
if response.status_code == 200: |
|
return response.json()["choices"][0]["message"]["content"].strip() |
|
else: |
|
print(f"Error: {response.status_code}, {response.text}") |
|
return "Error generating email. Please check your API key or try again later." |
|
|
|
|
|
def create_email(name, company_name, role, email, phone, linkedin_profile_url): |
|
|
|
if linkedin_profile_url: |
|
bio = get_linkedin_profile_via_proxycurl(linkedin_profile_url) |
|
else: |
|
bio = f"{name} is a professional." |
|
|
|
|
|
company_info = get_company_info(company_name) |
|
role_description = get_role_description(role, company_name) |
|
|
|
|
|
generated_email = generate_and_correct_email(bio, company_name, role, company_info, role_description) |
|
|
|
|
|
signature = f"\n\nBest regards,\n{name}\nEmail: {email}\nPhone: {phone}\nLinkedIn: {linkedin_profile_url if linkedin_profile_url else 'Not provided'}" |
|
|
|
|
|
if "Best regards" in generated_email: |
|
generated_email = generated_email.split("Best regards")[0].strip() |
|
|
|
|
|
return generated_email + signature |
|
|
|
|
|
def gradio_ui(): |
|
|
|
name_input = gr.Textbox(label="Name", placeholder="Enter your name") |
|
|
|
company_name_input = gr.Textbox(label="Company Name", placeholder="Enter the name of the company you are applying to") |
|
role_input = gr.Textbox(label="Role", placeholder="Enter the role you are applying for") |
|
|
|
email_input = gr.Textbox(label="Email Address", placeholder="Enter your email address") |
|
phone_input = gr.Textbox(label="Phone Number", placeholder="Enter your phone number") |
|
linkedin_input = gr.Textbox(label="LinkedIn URL", placeholder="Enter your LinkedIn profile URL") |
|
|
|
|
|
email_output = gr.Textbox(label="Generated Email", placeholder="Your generated email will appear here", lines=10) |
|
|
|
|
|
demo = gr.Interface( |
|
fn=create_email, |
|
inputs=[name_input, company_name_input, role_input, email_input, phone_input, linkedin_input], |
|
outputs=[email_output], |
|
title="Email Writing AI Agent", |
|
description="Generate a professional email for a job application by providing your basic info.", |
|
allow_flagging="never" |
|
) |
|
|
|
|
|
demo.launch() |
|
|
|
|
|
if __name__ == "__main__": |
|
gradio_ui() |
|
|