Update app.py
Browse files
app.py
CHANGED
|
@@ -4,24 +4,24 @@ import os
|
|
| 4 |
from datetime import datetime # Import datetime for date validation
|
| 5 |
|
| 6 |
# Load API keys securely from environment variables
|
| 7 |
-
|
| 8 |
groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
|
| 9 |
|
| 10 |
-
# Function to use
|
| 11 |
-
def
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
response = requests.get(url)
|
| 16 |
if response.status_code == 200:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
if "linkedin.com" in result.get("link", ""):
|
| 21 |
-
return result["link"]
|
| 22 |
-
return "LinkedIn profile not found"
|
| 23 |
else:
|
| 24 |
-
return "Error: Unable to fetch
|
| 25 |
|
| 26 |
# Helper function to call Groq Cloud LLM API to generate and correct the email
|
| 27 |
def generate_and_correct_email(bio, company_name, role):
|
|
@@ -70,22 +70,22 @@ def validate_dob(dob):
|
|
| 70 |
return False
|
| 71 |
|
| 72 |
# Main function to create the email and allow for saving, editing, or copying
|
| 73 |
-
def create_email(name, dob, city, company_name, role, email, phone):
|
| 74 |
# Validate the DOB format (DD-MM-YYYY)
|
| 75 |
if not validate_dob(dob):
|
| 76 |
return "Invalid Date of Birth format. Please use DD-MM-YYYY."
|
| 77 |
|
| 78 |
-
# Step 1: Fetch LinkedIn profile using
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
|
| 84 |
# Step 2: Generate the email using Groq Cloud LLM
|
| 85 |
generated_email = generate_and_correct_email(bio, company_name, role)
|
| 86 |
|
| 87 |
# Step 3: Add the user's email, phone number, and LinkedIn profile to the signature
|
| 88 |
-
signature = f"\n\nBest regards,\n{name}\nEmail: {email}\nPhone: {phone}\nLinkedIn: {
|
| 89 |
|
| 90 |
# Return the final polished email with the signature
|
| 91 |
return generated_email + signature
|
|
@@ -102,6 +102,7 @@ def gradio_ui():
|
|
| 102 |
|
| 103 |
email_input = gr.Textbox(label="Email Address", placeholder="Enter your email address")
|
| 104 |
phone_input = gr.Textbox(label="Phone Number", placeholder="Enter your phone number")
|
|
|
|
| 105 |
|
| 106 |
# Define output for the generated email
|
| 107 |
email_output = gr.Textbox(label="Generated Email", placeholder="Your generated email will appear here", lines=10)
|
|
@@ -109,7 +110,7 @@ def gradio_ui():
|
|
| 109 |
# Create the Gradio interface
|
| 110 |
demo = gr.Interface(
|
| 111 |
fn=create_email, # Function to call when the user submits
|
| 112 |
-
inputs=[name_input, dob_input, city_input, company_name_input, role_input, email_input, phone_input],
|
| 113 |
outputs=[email_output],
|
| 114 |
title="Email Writing AI Agent",
|
| 115 |
description="Generate a professional email for a job application by providing your basic info.",
|
|
|
|
| 4 |
from datetime import datetime # Import datetime for date validation
|
| 5 |
|
| 6 |
# Load API keys securely from environment variables
|
| 7 |
+
proxycurl_api_key = os.getenv("PROXYCURL_API_KEY") # Add your Proxycurl API key to your environment variables
|
| 8 |
groq_api_key = os.getenv("GROQ_CLOUD_API_KEY")
|
| 9 |
|
| 10 |
+
# Function to use Proxycurl API to get the LinkedIn profile data
|
| 11 |
+
def get_linkedin_profile_via_proxycurl(linkedin_profile_url):
|
| 12 |
+
headers = {
|
| 13 |
+
"Authorization": f"Bearer {proxycurl_api_key}",
|
| 14 |
+
}
|
| 15 |
+
url = f"https://nubela.co/proxycurl/api/v2/linkedin?url={linkedin_profile_url}"
|
| 16 |
+
|
| 17 |
+
response = requests.get(url, headers=headers)
|
| 18 |
|
|
|
|
| 19 |
if response.status_code == 200:
|
| 20 |
+
data = response.json()
|
| 21 |
+
bio = data.get("summary", "No bio available")
|
| 22 |
+
return bio
|
|
|
|
|
|
|
|
|
|
| 23 |
else:
|
| 24 |
+
return "Error: Unable to fetch LinkedIn profile"
|
| 25 |
|
| 26 |
# Helper function to call Groq Cloud LLM API to generate and correct the email
|
| 27 |
def generate_and_correct_email(bio, company_name, role):
|
|
|
|
| 70 |
return False
|
| 71 |
|
| 72 |
# Main function to create the email and allow for saving, editing, or copying
|
| 73 |
+
def create_email(name, dob, city, company_name, role, email, phone, linkedin_profile_url):
|
| 74 |
# Validate the DOB format (DD-MM-YYYY)
|
| 75 |
if not validate_dob(dob):
|
| 76 |
return "Invalid Date of Birth format. Please use DD-MM-YYYY."
|
| 77 |
|
| 78 |
+
# Step 1: Fetch LinkedIn profile using Proxycurl API if LinkedIn URL is provided
|
| 79 |
+
if linkedin_profile_url:
|
| 80 |
+
bio = get_linkedin_profile_via_proxycurl(linkedin_profile_url)
|
| 81 |
+
else:
|
| 82 |
+
bio = f"{name} is a professional in {city}." # Default bio if no LinkedIn URL is provided
|
| 83 |
|
| 84 |
# Step 2: Generate the email using Groq Cloud LLM
|
| 85 |
generated_email = generate_and_correct_email(bio, company_name, role)
|
| 86 |
|
| 87 |
# Step 3: Add the user's email, phone number, and LinkedIn profile to the signature
|
| 88 |
+
signature = f"\n\nBest regards,\n{name}\nEmail: {email}\nPhone: {phone}\nLinkedIn: {linkedin_profile_url if linkedin_profile_url else 'Not provided'}"
|
| 89 |
|
| 90 |
# Return the final polished email with the signature
|
| 91 |
return generated_email + signature
|
|
|
|
| 102 |
|
| 103 |
email_input = gr.Textbox(label="Email Address", placeholder="Enter your email address")
|
| 104 |
phone_input = gr.Textbox(label="Phone Number", placeholder="Enter your phone number")
|
| 105 |
+
linkedin_input = gr.Textbox(label="LinkedIn URL", placeholder="Enter your LinkedIn profile URL") # New field for LinkedIn URL
|
| 106 |
|
| 107 |
# Define output for the generated email
|
| 108 |
email_output = gr.Textbox(label="Generated Email", placeholder="Your generated email will appear here", lines=10)
|
|
|
|
| 110 |
# Create the Gradio interface
|
| 111 |
demo = gr.Interface(
|
| 112 |
fn=create_email, # Function to call when the user submits
|
| 113 |
+
inputs=[name_input, dob_input, city_input, company_name_input, role_input, email_input, phone_input, linkedin_input],
|
| 114 |
outputs=[email_output],
|
| 115 |
title="Email Writing AI Agent",
|
| 116 |
description="Generate a professional email for a job application by providing your basic info.",
|