File size: 3,460 Bytes
84ae9d3
 
 
 
ff7d3c0
84ae9d3
ff7d3c0
c7fd502
ff7d3c0
310204e
ff7d3c0
 
 
 
 
 
725b4fe
ff7d3c0
84ae9d3
 
ff7d3c0
84ae9d3
725b4fe
84ae9d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
725b4fe
84ae9d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests
from groq import Groq

# Function to scrape LinkedIn profile using Proxycurl API
def scrape_linkedin_profile(linkedin_url):
    api_url = "https://nubela.co/proxycurl/api/v2/linkedin"  # Endpoint for Proxycurl API
    api_key = "Y5xigulf0B1C_wr20seh8g"  # Replace with your actual Proxycurl API key
    headers = {
        "Authorization": f"Bearer {api_key}"  # Correctly formatted Authorization header
    }
    
    params = {
        "url": linkedin_url,
        "use_cache": "if-present"
    }
    
    response = requests.get(api_url, headers=headers, params=params)
    
    if response.status_code == 200:
        return response.json()  # Return the JSON response containing profile data
    else:
        return f"Error scraping LinkedIn profile: {response.text}"  # Improved error message

# Function to generate email using Llama 3.2 from Groq with ReAct methodology
def generate_email(name, email, phone, role, tokens, linkedin_url):
    reasoning_trace = []
    
    # Reasoning step: Initiate profile scrape
    reasoning_trace.append(f"Initiating profile scrape for {name}.")
    profile_data = scrape_linkedin_profile(linkedin_url)
    
    if isinstance(profile_data, str) and "Error" in profile_data:
        return profile_data  # Return error message if scraping fails
    
    # Reasoning step: Profile data obtained
    reasoning_trace.append(f"Obtained profile data: {profile_data}.")

    # Initialize Groq client
    client = Groq(api_key='YOUR_GROQ_API_KEY')  # Replace with your actual Groq API key
    
    # Prepare messages for Llama model
    messages = [
        {
            "role": "user",
            "content": [
                {"type": "text", "text": f"Generate an email for {name} applying for {role}."},
                {"type": "text", "text": f"Email: {email}, Phone: {phone}, Profile Data: {profile_data}"}
            ]
        }
    ]
    
    # Call to Llama model
    completion = client.chat.completions.create(
        model="llama-3.2-90b-vision-preview",
        messages=messages,
        max_tokens=tokens,
        temperature=1,
        top_p=1,
        stream=False,
        stop=None
    )
    
    # Reasoning step: Email generated
    reasoning_trace.append("Email content generated.")
    
    email_body = completion['choices'][0]['message']['content']
    
    # Combine email content with reasoning trace
    return f"Email Content:\n{email_body}\n\nReasoning Trace: {'; '.join(reasoning_trace)}"

# Streamlit app layout
def main():
    st.title("LinkedIn Profile Scraper and Email Generator")

    # Input fields for user data
    name = st.text_input("Name of the Sender")
    email = st.text_input("Email Address of the Sender")
    phone = st.text_input("Phone Number of the Sender")
    linkedin_url = st.text_input("LinkedIn Profile URL")
    role = st.text_input("Role Applying For")
    tokens = st.number_input("Number of Tokens", min_value=1, max_value=500, value=50)

    # Button to scrape LinkedIn profile and generate email
    if st.button("Scrape Profile and Generate Email"):
        if name and email and phone and linkedin_url and role and tokens:
            email_content = generate_email(name, email, phone, role, tokens, linkedin_url)
            st.subheader("Generated Email:")
            st.write(email_content)
        else:
            st.error("Please fill in all fields.")

# Run the app
if __name__ == '__main__':
    main()