Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
from groq import Groq
|
| 4 |
+
|
| 5 |
+
# Function to scrape LinkedIn profile using Firecrawl API
|
| 6 |
+
def scrape_linkedin_profile(linkedin_url):
|
| 7 |
+
api_url = "https://api.firecrawl.dev/v1/scrape" # Endpoint for scraping
|
| 8 |
+
headers = {"Authorization": "Bearer YOUR_FIRECRAWL_API_KEY"} # Replace with your actual API key
|
| 9 |
+
response = requests.post(api_url, json={"url": linkedin_url}, headers=headers)
|
| 10 |
+
|
| 11 |
+
if response.status_code == 200:
|
| 12 |
+
return response.json()['data'] # Adjust based on actual response structure
|
| 13 |
+
else:
|
| 14 |
+
return "Error scraping LinkedIn profile."
|
| 15 |
+
|
| 16 |
+
# Function to generate email using Llama 3.2 from Groq with ReAct methodology
|
| 17 |
+
def generate_email(name, email, phone, role, tokens, linkedin_url):
|
| 18 |
+
reasoning_trace = []
|
| 19 |
+
|
| 20 |
+
# Reasoning step: Initiate profile scrape
|
| 21 |
+
reasoning_trace.append(f"Initiating profile scrape for {name}.")
|
| 22 |
+
profile_data = scrape_linkedin_profile(linkedin_url)
|
| 23 |
+
|
| 24 |
+
if isinstance(profile_data, str) and "Error" in profile_data:
|
| 25 |
+
return profile_data # Return error message if scraping fails
|
| 26 |
+
|
| 27 |
+
# Reasoning step: Profile data obtained
|
| 28 |
+
reasoning_trace.append(f"Obtained profile data: {profile_data}.")
|
| 29 |
+
|
| 30 |
+
# Initialize Groq client
|
| 31 |
+
client = Groq(api_key='YOUR_GROQ_API_KEY') # Replace with your actual API key
|
| 32 |
+
|
| 33 |
+
# Prepare messages for Llama model
|
| 34 |
+
messages = [
|
| 35 |
+
{
|
| 36 |
+
"role": "user",
|
| 37 |
+
"content": [
|
| 38 |
+
{"type": "text", "text": f"Generate an email for {name} applying for {role}."},
|
| 39 |
+
{"type": "text", "text": f"Email: {email}, Phone: {phone}, Profile Data: {profile_data}"}
|
| 40 |
+
]
|
| 41 |
+
}
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
# Call to Llama model
|
| 45 |
+
completion = client.chat.completions.create(
|
| 46 |
+
model="llama-3.2-90b-vision-preview",
|
| 47 |
+
messages=messages,
|
| 48 |
+
max_tokens=tokens,
|
| 49 |
+
temperature=1,
|
| 50 |
+
top_p=1,
|
| 51 |
+
stream=False,
|
| 52 |
+
stop=None
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
# Reasoning step: Email generated
|
| 56 |
+
reasoning_trace.append("Email content generated.")
|
| 57 |
+
|
| 58 |
+
email_body = completion['choices'][0]['message']['content']
|
| 59 |
+
|
| 60 |
+
# Combine email content with reasoning trace
|
| 61 |
+
return f"Email Content:\n{email_body}\n\nReasoning Trace: {'; '.join(reasoning_trace)}"
|
| 62 |
+
|
| 63 |
+
# Streamlit app layout
|
| 64 |
+
def main():
|
| 65 |
+
st.title("LinkedIn Profile Scraper and Email Generator")
|
| 66 |
+
|
| 67 |
+
# Input fields for user data
|
| 68 |
+
name = st.text_input("Name of the Sender")
|
| 69 |
+
email = st.text_input("Email Address of the Sender")
|
| 70 |
+
phone = st.text_input("Phone Number of the Sender")
|
| 71 |
+
linkedin_url = st.text_input("LinkedIn Profile URL")
|
| 72 |
+
role = st.text_input("Role Applying For")
|
| 73 |
+
tokens = st.number_input("Number of Tokens", min_value=1, max_value=500, value=50)
|
| 74 |
+
|
| 75 |
+
# Button to scrape LinkedIn profile and generate email
|
| 76 |
+
if st.button("Scrape Profile and Generate Email"):
|
| 77 |
+
if name and email and phone and linkedin_url and role and tokens:
|
| 78 |
+
email_content = generate_email(name, email, phone, role, tokens, linkedin_url)
|
| 79 |
+
st.subheader("Generated Email:")
|
| 80 |
+
st.write(email_content)
|
| 81 |
+
else:
|
| 82 |
+
st.error("Please fill in all fields.")
|
| 83 |
+
|
| 84 |
+
# Run the app
|
| 85 |
+
if __name__ == '__main__':
|
| 86 |
+
main()
|