AdithyaSNair commited on
Commit
feca185
·
verified ·
1 Parent(s): f35eb74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -25
app.py CHANGED
@@ -1,11 +1,16 @@
1
  import streamlit as st
 
 
2
  import fitz # PyMuPDF
3
  import requests
4
  from bs4 import BeautifulSoup
5
- import openai
6
 
7
- # Set your OpenAI API key
8
- openai.api_key = 'YOUR_OPENAI_API_KEY' # Replace with your OpenAI API key
 
 
 
 
9
 
10
  # Function to extract text from a PDF file
11
  def extract_text_from_pdf(pdf_file):
@@ -21,45 +26,59 @@ def extract_job_description(job_link):
21
  response = requests.get(job_link)
22
  response.raise_for_status()
23
  soup = BeautifulSoup(response.text, 'html.parser')
24
- # You might need to adjust this depending on the website's structure
25
- job_description = soup.get_text(separator=' ')
26
  return job_description.strip()
27
  except Exception as e:
28
  st.error(f"Error fetching job description: {e}")
29
  return ""
30
 
31
- # Function to generate an email using OpenAI's GPT
32
- def generate_email(job_description, resume_text):
33
- prompt = f"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  You are Mohan, a business development executive at AtliQ, an AI & Software Consulting company dedicated to facilitating the seamless integration of business processes through automated tools. AtliQ has empowered numerous enterprises with tailored solutions, fostering scalability, process optimization, cost reduction, and heightened overall efficiency.
35
 
36
  Given the following job description:
37
 
38
  {job_description}
39
 
 
 
 
 
40
  And the following resume text:
41
 
42
  {resume_text}
43
 
44
- Write a cold email to the client regarding the job mentioned above, describing the capability of AtliQ in fulfilling their needs. Remember you are Mohan, BDE at AtliQ. Do not provide a preamble.
45
 
46
  Email:
47
  """
48
- try:
49
- response = openai.Completion.create(
50
- engine="text-davinci-003", # You can use "gpt-3.5-turbo" if available
51
- prompt=prompt,
52
- max_tokens=500,
53
- temperature=0.7,
54
- top_p=1.0,
55
- n=1,
56
- stop=None
57
- )
58
- email_text = response.choices[0].text.strip()
59
- return email_text
60
- except Exception as e:
61
- st.error(f"Error generating email: {e}")
62
- return ""
63
 
64
  # Streamlit App
65
  def main():
@@ -88,6 +107,12 @@ def main():
88
  st.error("Failed to extract job description.")
89
  return
90
 
 
 
 
 
 
 
91
  # Extract resume text
92
  resume_text = extract_text_from_pdf(uploaded_file)
93
  if not resume_text:
@@ -95,7 +120,7 @@ def main():
95
  return
96
 
97
  # Generate email
98
- email_text = generate_email(job_description, resume_text)
99
  if email_text:
100
  st.subheader("Generated Email:")
101
  st.write(email_text)
 
1
  import streamlit as st
2
+ from langchain_groq import ChatGroq
3
+ from langchain_core.prompts import PromptTemplate
4
  import fitz # PyMuPDF
5
  import requests
6
  from bs4 import BeautifulSoup
 
7
 
8
+ # Initialize the LLM with your Groq API key
9
+ llm = ChatGroq(
10
+ temperature=0,
11
+ groq_api_key='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', # Replace with your Groq API key
12
+ model_name="llama-3.1-70b-versatile"
13
+ )
14
 
15
  # Function to extract text from a PDF file
16
  def extract_text_from_pdf(pdf_file):
 
26
  response = requests.get(job_link)
27
  response.raise_for_status()
28
  soup = BeautifulSoup(response.text, 'html.parser')
29
+ job_description = soup.get_text(separator='\n')
 
30
  return job_description.strip()
31
  except Exception as e:
32
  st.error(f"Error fetching job description: {e}")
33
  return ""
34
 
35
+ # Function to extract requirements from the job description using ChatGroq
36
+ def extract_requirements(job_description):
37
+ prompt_text = f"""
38
+ The following is a job description:
39
+
40
+ {job_description}
41
+
42
+ Extract the list of job requirements, qualifications, and skills from the job description. Provide them as a numbered list.
43
+
44
+ Requirements:
45
+ """
46
+
47
+ prompt = PromptTemplate.from_template(prompt_text)
48
+ chain = prompt | llm
49
+ response = chain.invoke({})
50
+
51
+ requirements = response.content.strip()
52
+ return requirements
53
+
54
+ # Function to generate an email using ChatGroq
55
+ def generate_email(job_description, requirements, resume_text):
56
+ prompt_text = f"""
57
  You are Mohan, a business development executive at AtliQ, an AI & Software Consulting company dedicated to facilitating the seamless integration of business processes through automated tools. AtliQ has empowered numerous enterprises with tailored solutions, fostering scalability, process optimization, cost reduction, and heightened overall efficiency.
58
 
59
  Given the following job description:
60
 
61
  {job_description}
62
 
63
+ And the following extracted requirements:
64
+
65
+ {requirements}
66
+
67
  And the following resume text:
68
 
69
  {resume_text}
70
 
71
+ Write a cold email to the client regarding the job mentioned above, describing the capability of AtliQ in fulfilling their needs, and how your skills align with their requirements. Remember you are Mohan, BDE at AtliQ. Do not provide a preamble.
72
 
73
  Email:
74
  """
75
+
76
+ prompt = PromptTemplate.from_template(prompt_text)
77
+ chain = prompt | llm
78
+ response = chain.invoke({})
79
+
80
+ email_text = response.content.strip()
81
+ return email_text
 
 
 
 
 
 
 
 
82
 
83
  # Streamlit App
84
  def main():
 
107
  st.error("Failed to extract job description.")
108
  return
109
 
110
+ # Extract requirements
111
+ requirements = extract_requirements(job_description)
112
+ if not requirements:
113
+ st.error("Failed to extract requirements.")
114
+ return
115
+
116
  # Extract resume text
117
  resume_text = extract_text_from_pdf(uploaded_file)
118
  if not resume_text:
 
120
  return
121
 
122
  # Generate email
123
+ email_text = generate_email(job_description, requirements, resume_text)
124
  if email_text:
125
  st.subheader("Generated Email:")
126
  st.write(email_text)