Manikanta3776 commited on
Commit
4cb2665
·
verified ·
1 Parent(s): 8847fb7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -61
app.py CHANGED
@@ -1,71 +1,60 @@
1
- import os
2
- from langchain_groq import ChatGroq
3
- from langchain_core.prompts import PromptTemplate
4
- from langchain_core.output_parsers import JsonOutputParser
5
- from langchain_core.exceptions import OutputParserException
6
- from dotenv import load_dotenv
7
 
8
- load_dotenv()
 
 
9
 
10
- class Chain:
11
- def __init__(self):
12
- self.llm = ChatGroq(
13
- temperature=0,
14
- groq_api_key=os.getenv("GROQ_API_KEY"),
15
- model_name="llama-3.3-70b-versatile"
16
- )
17
 
18
- def extract_jobs(self, cleaned_text):
19
- prompt_extract = PromptTemplate.from_template(
20
- """
21
- ### SCRAPED TEXT FROM WEBSITE:
22
- {page_data}
23
- ### INSTRUCTION:
24
- The scraped text is from the career's page of a website.
25
- Your job is to extract the job postings and return them in JSON format containing the following keys: `role`, `experience`, `skills`, and `description`.
26
- Only return the valid JSON.
27
- ### VALID JSON (NO PREAMBLE):
28
- """
29
- )
30
- chain_extract = prompt_extract | self.llm
31
- res = chain_extract.invoke(input={"page_data": cleaned_text})
32
-
33
  try:
34
- json_parser = JsonOutputParser()
35
- res = json_parser.parse(res.content)
36
- except OutputParserException:
37
- raise OutputParserException("Context too big. Unable to parse jobs.")
38
-
39
- return res if isinstance(res, list) else [res]
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- def write_mail(self, job, links, username="Computer Engineering Student", client_name="Hiring Manager"):
42
- prompt_email = PromptTemplate.from_template(
43
- """
44
- ### JOB DESCRIPTION:
45
- {job_description}
 
46
 
47
- ### INSTRUCTION:
48
- You are {username}, a dedicated third-year Computer Engineering student.
49
- You actively engage in projects that enhance your technical skills and have good communication skills.
50
- Your task is to write a cold email to {client_name} regarding the job mentioned above, showcasing your capabilities and how your academic pursuits align with their needs.
51
- Highlight your interests in innovative solutions and user engagement, as well as your commitment to creating impactful projects.
52
- Also, add the most relevant ones from the following links to showcase your portfolio: {link_list}
53
- Maintain a professional tone and avoid providing a preamble.
54
- ### EMAIL (NO PREAMBLE):
55
- """
56
- )
57
 
58
- chain_email = prompt_email | self.llm
59
-
60
- # ✅ Ensure `username` and `client_name` are correctly passed
61
- res = chain_email.invoke({
62
- "job_description": str(job),
63
- "link_list": links,
64
- "username": username,
65
- "client_name": client_name
66
- })
67
 
68
- return res.content
69
 
70
  if __name__ == "__main__":
71
- print(os.getenv("GROQ_API_KEY"))
 
1
+ import streamlit as st
2
+ from langchain_community.document_loaders import WebBaseLoader
3
+ from chains import Chain
4
+ from portfolio import Portfolio
5
+ from utils import clean_text
 
6
 
7
+ # Initialize backend services
8
+ chain = Chain()
9
+ portfolio = Portfolio()
10
 
11
+ def create_streamlit_app():
12
+ st.set_page_config(layout="wide", page_title="Cold Email Generator", page_icon="📧")
13
+ st.title("📧 Cold Email Generator")
 
 
 
 
14
 
15
+ # Input fields
16
+ url_input = st.text_input("Enter a Job URL:", value="https://jobs.nike.com/job/R-33460")
17
+ username = st.text_input("Your Name (Default: Computer Engineering Student)", value="Computer Engineering Student")
18
+ client_name = st.text_input("Recipient's Name (Default: Hiring Manager)", value="Hiring Manager")
19
+
20
+ submit_button = st.button("Extract Job Details")
21
+
22
+ if submit_button:
 
 
 
 
 
 
 
23
  try:
24
+ # Load and clean job description
25
+ loader = WebBaseLoader([url_input])
26
+ page_content = loader.load().pop().page_content
27
+ cleaned_data = clean_text(page_content)
28
+
29
+ # Extract job details
30
+ jobs = chain.extract_jobs(cleaned_data)
31
+
32
+ if not jobs:
33
+ st.warning("⚠️ No jobs found on the page. Please check the URL.")
34
+ return
35
+
36
+ # Display extracted job details
37
+ for idx, job in enumerate(jobs, start=1):
38
+ st.subheader(f"Job {idx}: {job.get('role', 'Unknown Role')}")
39
+ st.write(f"**Experience Required:** {job.get('experience', 'Not Specified')}")
40
+ st.write(f"**Skills:** {', '.join(job.get('skills', [])) if job.get('skills') else 'Not Specified'}")
41
+ st.write(f"**Description:** {job.get('description', 'No description available')}")
42
+ st.divider()
43
 
44
+ # Email generation button
45
+ if st.button("Generate Cold Email"):
46
+ for job in jobs:
47
+ # Get relevant portfolio links based on job skills
48
+ skills = job.get("skills", [])
49
+ links = portfolio.query_links(skills)
50
 
51
+ # Generate cold email
52
+ email = chain.write_mail(job, links, username, client_name)
53
+ st.code(email, language="markdown")
 
 
 
 
 
 
 
54
 
55
+ except Exception as e:
56
+ st.error(f"❌ An Error Occurred: {str(e)}")
 
 
 
 
 
 
 
57
 
 
58
 
59
  if __name__ == "__main__":
60
+ create_streamlit_app()