Spaces:
Sleeping
Sleeping
Upload 6 files
Browse filesFiles changed (6)
- app/.envAdded+1
- app/chains.pyAdded+60
- app/main.pyAdded+35
- app/portfolio.pyAdded+21
- app/resource/my_portfolio.csvAdded+21
- app/utils.pyAdded+16
1GROQ_API_KEY=gsk_Y0BiyZetfhMS1ja15vBIWGdyb3FYb5YyITd8fVZfkxofb39kC1V7123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import osfrom langchain_groq import ChatGroqfrom langchain_core.prompts import PromptTemplatefrom langchain_core.output_parsers import JsonOutputParserfrom langchain_core.exceptions import OutputParserExceptionfrom dotenv import load_dotenv
load_dotenv()
class Chain: def __init__(self): self.llm = ChatGroq(temperature=0, groq_api_key=os.getenv("GROQ_API_KEY"), model_name="llama-3.1-70b-versatile")
def extract_jobs(self, cleaned_text): prompt_extract = PromptTemplate.from_template( """ ### SCRAPED TEXT FROM WEBSITE: {page_data} ### INSTRUCTION: The scraped text is from the career's page of a website. Your job is to extract the job postings and return them in JSON format containing the following keys: `role`, `experience`, `skills` and `description`. Only return the valid JSON. ### VALID JSON (NO PREAMBLE): """ ) chain_extract = prompt_extract | self.llm res = chain_extract.invoke(input={"page_data": cleaned_text}) try: json_parser = JsonOutputParser() res = json_parser.parse(res.content) except OutputParserException: raise OutputParserException("Context too big. Unable to parse jobs.") return res if isinstance(res, list) else [res]
def write_mail(self, job, links): prompt_email = PromptTemplate.from_template( """ ### JOB DESCRIPTION: {job_description}
### INSTRUCTION: You are Mohan, a business development executive at AtliQ. AtliQ is an AI & Software Consulting company dedicated to facilitating the seamless integration of business processes through automated tools. Over our experience, we have empowered numerous enterprises with tailored solutions, fostering scalability, process optimization, cost reduction, and heightened overall efficiency. Your job is to write a cold email to the client regarding the job mentioned above describing the capability of AtliQ in fulfilling their needs. Also add the most relevant ones from the following links to showcase Atliq's portfolio: {link_list} Remember you are Mohan, BDE at AtliQ. Do not provide a preamble. ### EMAIL (NO PREAMBLE):
""" ) chain_email = prompt_email | self.llm res = chain_email.invoke({"job_description": str(job), "link_list": links}) return res.content
if __name__ == "__main__": print(os.getenv("GROQ_API_KEY"))1234567891011121314151617181920212223242526272829303132333435import streamlit as stfrom langchain_community.document_loaders import WebBaseLoader
from chains import Chainfrom portfolio import Portfoliofrom utils import clean_text
def create_streamlit_app(llm, portfolio, clean_text): st.title("📧 Cold Mail Generator") url_input = st.text_input("Enter a URL:", value="https://jobs.nike.com/job/R-33460") submit_button = st.button("Submit")
if submit_button: try: loader = WebBaseLoader([url_input]) data = clean_text(loader.load().pop().page_content) portfolio.load_portfolio() jobs = llm.extract_jobs(data) for job in jobs: skills = job.get('skills', []) links = portfolio.query_links(skills) email = llm.write_mail(job, links) st.code(email, language='markdown') except Exception as e: st.error(f"An Error Occurred: {e}")
if __name__ == "__main__": chain = Chain() portfolio = Portfolio() st.set_page_config(layout="wide", page_title="Cold Email Generator", page_icon="📧") create_streamlit_app(chain, portfolio, clean_text)
123456789101112131415161718192021import pandas as pdimport chromadbimport uuid
class Portfolio: def __init__(self, file_path="app/resource/my_portfolio.csv"): self.file_path = file_path self.data = pd.read_csv(file_path) self.chroma_client = chromadb.PersistentClient('vectorstore') self.collection = self.chroma_client.get_or_create_collection(name="portfolio")
def load_portfolio(self): if not self.collection.count(): for _, row in self.data.iterrows(): self.collection.add(documents=row["Techstack"], metadatas={"links": row["Links"]}, ids=[str(uuid.uuid4())])
def query_links(self, skills): return self.collection.query(query_texts=skills, n_results=2).get('metadatas', [])123456789101112131415161718192021"Techstack","Links""React, Node.js, MongoDB","https://example.com/react-portfolio""Angular,.NET, SQL Server","https://example.com/angular-portfolio""Vue.js, Ruby on Rails, PostgreSQL","https://example.com/vue-portfolio""Python, Django, MySQL","https://example.com/python-portfolio""Java, Spring Boot, Oracle","https://example.com/java-portfolio""Flutter, Firebase, GraphQL","https://example.com/flutter-portfolio""WordPress, PHP, MySQL","https://example.com/wordpress-portfolio""Magento, PHP, MySQL","https://example.com/magento-portfolio""React Native, Node.js, MongoDB","https://example.com/react-native-portfolio""iOS, Swift, Core Data","https://example.com/ios-portfolio""Android, Java, Room Persistence","https://example.com/android-portfolio""Kotlin, Android, Firebase","https://example.com/kotlin-android-portfolio""Android TV, Kotlin, Android NDK","https://example.com/android-tv-portfolio""iOS, Swift, ARKit","https://example.com/ios-ar-portfolio""Cross-platform, Xamarin, Azure","https://example.com/xamarin-portfolio""Backend, Kotlin, Spring Boot","https://example.com/kotlin-backend-portfolio""Frontend, TypeScript, Angular","https://example.com/typescript-frontend-portfolio""Full-stack, JavaScript, Express.js","https://example.com/full-stack-js-portfolio""Machine Learning, Python, TensorFlow","https://example.com/ml-python-portfolio""DevOps, Jenkins, Docker","https://example.com/devops-portfolio"12345678910111213141516import re
def clean_text(text): # Remove HTML tags text = re.sub(r'<[^>]*?>', '', text) # Remove URLs text = re.sub(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', '', text) # Remove special characters text = re.sub(r'[^a-zA-Z0-9 ]', '', text) # Replace multiple spaces with a single space text = re.sub(r'\s{2,}', ' ', text) # Trim leading and trailing whitespace text = text.strip() # Remove extra whitespace text = ' '.join(text.split()) return textapp/.envAdded+1
app/chains.pyAdded+60
app/main.pyAdded+35
app/portfolio.pyAdded+21
app/resource/my_portfolio.csvAdded+21
app/utils.pyAdded+16