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()