OptiHire / app.py
AdithyaSNair's picture
Create app.py
19a9439 verified
raw
history blame
3.64 kB
import streamlit as st
import fitz # PyMuPDF
import requests
from bs4 import BeautifulSoup
import openai
# Set your OpenAI API key
openai.api_key = 'YOUR_OPENAI_API_KEY' # Replace with your OpenAI API key
# Function to extract text from a PDF file
def extract_text_from_pdf(pdf_file):
text = ""
with fitz.open(stream=pdf_file.read(), filetype="pdf") as doc:
for page in doc:
text += page.get_text()
return text
# Function to extract the job description from a given URL
def extract_job_description(job_link):
try:
response = requests.get(job_link)
response.raise_for_status()
soup = BeautifulSoup(response.text, 'html.parser')
# You might need to adjust this depending on the website's structure
job_description = soup.get_text(separator=' ')
return job_description.strip()
except Exception as e:
st.error(f"Error fetching job description: {e}")
return ""
# Function to generate an email using OpenAI's GPT
def generate_email(job_description, resume_text):
prompt = f"""
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.
Given the following job description:
{job_description}
And the following resume text:
{resume_text}
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.
Email:
"""
try:
response = openai.Completion.create(
engine="text-davinci-003", # You can use "gpt-3.5-turbo" if available
prompt=prompt,
max_tokens=500,
temperature=0.7,
top_p=1.0,
n=1,
stop=None
)
email_text = response.choices[0].text.strip()
return email_text
except Exception as e:
st.error(f"Error generating email: {e}")
return ""
# Streamlit App
def main():
st.title("Automated Email Generator")
st.write("""
This application generates a personalized email based on a job posting and your resume.
""")
# Input fields
job_link = st.text_input("Enter the job link:")
uploaded_file = st.file_uploader("Upload your resume (PDF format):", type="pdf")
if st.button("Generate Email"):
if not job_link:
st.error("Please enter a job link.")
return
if not uploaded_file:
st.error("Please upload your resume.")
return
with st.spinner("Processing..."):
# Extract job description
job_description = extract_job_description(job_link)
if not job_description:
st.error("Failed to extract job description.")
return
# Extract resume text
resume_text = extract_text_from_pdf(uploaded_file)
if not resume_text:
st.error("Failed to extract text from resume.")
return
# Generate email
email_text = generate_email(job_description, resume_text)
if email_text:
st.subheader("Generated Email:")
st.write(email_text)
else:
st.error("Failed to generate email.")
if __name__ == "__main__":
main()