Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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):
|
12 |
+
text = ""
|
13 |
+
with fitz.open(stream=pdf_file.read(), filetype="pdf") as doc:
|
14 |
+
for page in doc:
|
15 |
+
text += page.get_text()
|
16 |
+
return text
|
17 |
+
|
18 |
+
# Function to extract the job description from a given URL
|
19 |
+
def extract_job_description(job_link):
|
20 |
+
try:
|
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():
|
66 |
+
st.title("Automated Email Generator")
|
67 |
+
|
68 |
+
st.write("""
|
69 |
+
This application generates a personalized email based on a job posting and your resume.
|
70 |
+
""")
|
71 |
+
|
72 |
+
# Input fields
|
73 |
+
job_link = st.text_input("Enter the job link:")
|
74 |
+
uploaded_file = st.file_uploader("Upload your resume (PDF format):", type="pdf")
|
75 |
+
|
76 |
+
if st.button("Generate Email"):
|
77 |
+
if not job_link:
|
78 |
+
st.error("Please enter a job link.")
|
79 |
+
return
|
80 |
+
if not uploaded_file:
|
81 |
+
st.error("Please upload your resume.")
|
82 |
+
return
|
83 |
+
|
84 |
+
with st.spinner("Processing..."):
|
85 |
+
# Extract job description
|
86 |
+
job_description = extract_job_description(job_link)
|
87 |
+
if not job_description:
|
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:
|
94 |
+
st.error("Failed to extract text from resume.")
|
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)
|
102 |
+
else:
|
103 |
+
st.error("Failed to generate email.")
|
104 |
+
|
105 |
+
if __name__ == "__main__":
|
106 |
+
main()
|