Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import uuid
|
| 4 |
+
import chromadb
|
| 5 |
+
from langchain_groq import ChatGroq
|
| 6 |
+
from langchain_community.document_loaders import WebBaseLoader
|
| 7 |
+
from langchain_core.prompts import PromptTemplate
|
| 8 |
+
from langchain_core.output_parsers import JsonOutputParser
|
| 9 |
+
from dotenv import load_dotenv
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
# Load environment variables from .env file // # Create .env file outside the (.venv) i.e in create in main files
|
| 13 |
+
load_dotenv()
|
| 14 |
+
|
| 15 |
+
# Initialize LLM
|
| 16 |
+
llm = ChatGroq(
|
| 17 |
+
temperature=0,
|
| 18 |
+
api_key = os.getenv("API_KEY"),
|
| 19 |
+
#api_key="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",
|
| 20 |
+
model_name="llama-3.1-70b-versatile"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Streamlit App
|
| 24 |
+
st.title("Cold Email Generator with LangChain")
|
| 25 |
+
|
| 26 |
+
# Load CSV
|
| 27 |
+
uploaded_file = st.file_uploader("Upload your portfolio CSV file", type=["csv"])
|
| 28 |
+
if uploaded_file:
|
| 29 |
+
df = pd.read_csv(uploaded_file)
|
| 30 |
+
st.write("Portfolio Data:")
|
| 31 |
+
st.dataframe(df)
|
| 32 |
+
|
| 33 |
+
# Initialize ChromaDB
|
| 34 |
+
client = chromadb.PersistentClient('vectorstore')
|
| 35 |
+
collection = client.get_or_create_collection(name="my_portfolio.csv")
|
| 36 |
+
|
| 37 |
+
if not collection.count():
|
| 38 |
+
for _, row in df.iterrows():
|
| 39 |
+
collection.add(documents=row["Techstack"],
|
| 40 |
+
metadatas={"links": row["Links"]},
|
| 41 |
+
ids=[str(uuid.uuid4())])
|
| 42 |
+
st.success("Portfolio data added to the vectorstore!")
|
| 43 |
+
|
| 44 |
+
# Scrape Job Description
|
| 45 |
+
url = st.text_input("Enter the job posting URL:")
|
| 46 |
+
if url:
|
| 47 |
+
loader = WebBaseLoader(url)
|
| 48 |
+
page_data = loader.load().pop().page_content
|
| 49 |
+
st.write("Scraped Job Data:")
|
| 50 |
+
st.text(page_data)
|
| 51 |
+
|
| 52 |
+
# Extract Job Details
|
| 53 |
+
prompt_extract = PromptTemplate.from_template(
|
| 54 |
+
"""
|
| 55 |
+
### SCRAPED TEXT FROM WEBSITE:
|
| 56 |
+
{page_data}
|
| 57 |
+
### INSTRUCTION:
|
| 58 |
+
The scraped text is from the career's page of a website.
|
| 59 |
+
Your job is to extract the job postings and return them in JSON format containing the
|
| 60 |
+
following keys: `role`, `experience`, `skills` and `description`.
|
| 61 |
+
Only return the valid JSON.
|
| 62 |
+
### VALID JSON (NO PREAMBLE):
|
| 63 |
+
"""
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
chain_extract = prompt_extract | llm
|
| 67 |
+
res = chain_extract.invoke(input={'page_data': page_data})
|
| 68 |
+
json_parser = JsonOutputParser()
|
| 69 |
+
job = json_parser.parse(res.content)
|
| 70 |
+
st.write("Extracted Job Details:")
|
| 71 |
+
st.json(job)
|
| 72 |
+
|
| 73 |
+
# Query Portfolio Links
|
| 74 |
+
links = collection.query(query_texts=job['skills'], n_results=2).get('metadatas', [])
|
| 75 |
+
st.write("Relevant Portfolio Links:")
|
| 76 |
+
st.write(links)
|
| 77 |
+
|
| 78 |
+
# Generate Cold Email
|
| 79 |
+
prompt_email = PromptTemplate.from_template(
|
| 80 |
+
"""
|
| 81 |
+
### JOB DESCRIPTION:
|
| 82 |
+
{job_description}
|
| 83 |
+
|
| 84 |
+
### INSTRUCTION:
|
| 85 |
+
You are Mohan, a business development executive at AtliQ. AtliQ is an AI & Software Consulting company dedicated to facilitating
|
| 86 |
+
the seamless integration of business processes through automated tools.
|
| 87 |
+
Over our experience, we have empowered numerous enterprises with tailored solutions, fostering scalability,
|
| 88 |
+
process optimization, cost reduction, and heightened overall efficiency.
|
| 89 |
+
Your job is to write a cold email to the client regarding the job mentioned above describing the capability of AtliQ
|
| 90 |
+
in fulfilling their needs.
|
| 91 |
+
Also add the most relevant ones from the following links to showcase Atliq's portfolio: {link_list}
|
| 92 |
+
Remember you are Mohan, BDE at AtliQ.
|
| 93 |
+
Do not provide a preamble.
|
| 94 |
+
### EMAIL (NO PREAMBLE):
|
| 95 |
+
|
| 96 |
+
"""
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
chain_email = prompt_email | llm
|
| 100 |
+
email_res = chain_email.invoke({"job_description": str(job), "link_list": links})
|
| 101 |
+
st.write("Generated Cold Email:")
|
| 102 |
+
st.text(email_res.content)
|