Spaces:
Sleeping
Sleeping
import streamlit as st | |
import os | |
from dotenv import load_dotenv | |
from langchain_community.llms import OpenAI | |
from langchain_google_genai import ChatGoogleGenerativeAI | |
from fpdf import FPDF | |
import fitz | |
# Load environment variables | |
load_dotenv() | |
def generate_resume(details): | |
prompt = f""" | |
Create an ATS-optimized resume based on the following details: | |
Name: {details['name']} | |
Contact Information: {details['contact']} | |
LinkedIn Profile: {details['linkedin']} | |
Professional Summary: {details['summary']} | |
Work Experience: {details['experience']} | |
Education: {details['education']} | |
Skills: {details['skills']} | |
Certifications: {details['certifications']} | |
Projects: {details['projects']} | |
Provide the resume in a well-structured format. | |
""" | |
llm = OpenAI(temperature=0.7, openai_api_key=st.secrets["OPENAI_API_KEY"],max_tokens=1500) | |
resume = llm(prompt) | |
return resume | |
def create_pdf(resume_text, filename): | |
pdf = FPDF() | |
pdf.add_page() | |
pdf.set_auto_page_break(auto=True, margin=15) | |
pdf.set_font("Arial", size=12) | |
for line in resume_text.split('\n'): | |
pdf.multi_cell(0, 10, line.encode('latin-1', 'replace').decode('latin-1')) | |
pdf.output(filename) | |
def extract_text_from_pdf(pdf_file): | |
doc = fitz.open(stream=pdf_file.read(), filetype="pdf") | |
text = "" | |
for page in doc: | |
text += page.get_text() | |
return text | |
def parse_extracted_text(text): | |
details = { | |
'name': "", | |
'contact': "", | |
'linkedin': "", | |
'summary': "", | |
'experience': "", | |
'education': "", | |
'skills': "", | |
'certifications': "", | |
'projects': "" | |
} | |
# Here, you would implement parsing logic to extract details from the text. | |
# For simplicity, this example assumes the text is well-structured and uses basic keyword extraction. | |
# In a real-world scenario, you would use more sophisticated text parsing techniques. | |
lines = text.split('\n') | |
for i, line in enumerate(lines): | |
if "Name:" in line: | |
details['name'] = line.split("Name:")[1].strip() | |
elif "Contact Information:" in line: | |
details['contact'] = line.split("Contact Information:")[1].strip() | |
elif "LinkedIn Profile:" in line: | |
details['linkedin'] = line.split("LinkedIn Profile:")[1].strip() | |
elif "Professional Summary:" in line: | |
details['summary'] = line.split("Professional Summary:")[1].strip() | |
elif "Work Experience:" in line: | |
details['experience'] = " ".join(lines[i+1:i+5]).strip() | |
elif "Education:" in line: | |
details['education'] = " ".join(lines[i+1:i+3]).strip() | |
elif "Skills:" in line: | |
details['skills'] = line.split("Skills:")[1].strip() | |
elif "Certifications:" in line: | |
details['certifications'] = line.split("Certifications:")[1].strip() | |
elif "Projects:" in line: | |
details['projects'] = " ".join(lines[i+1:i+3]).strip() | |
return details | |
def app(): | |
st.title("Resume Creation") | |
uploaded_file = st.file_uploader("Upload a resume to pre-fill details", type=["pdf"]) | |
if uploaded_file: | |
if st.button("Submit"): | |
extracted_text = extract_text_from_pdf(uploaded_file) | |
details = parse_extracted_text(extracted_text) | |
st.write("Extracted Text:", extracted_text) # Debug: Show the extracted text | |
st.write("Parsed Details:", details) # Debug: Show the parsed details | |
else: | |
details = { | |
'name': "", | |
'contact': "", | |
'linkedin': "", | |
'summary': "", | |
'experience': "", | |
'education': "", | |
'skills': "", | |
'certifications': "", | |
'projects': "" | |
} | |
else: | |
details = { | |
'name': "", | |
'contact': "", | |
'linkedin': "", | |
'summary': "", | |
'experience': "", | |
'education': "", | |
'skills': "", | |
'certifications': "", | |
'projects': "" | |
} | |
with st.form("resume_form"): | |
st.header("Enter your details to generate an ATS-optimized resume") | |
name = st.text_input("Name", value=details['name']) | |
contact = st.text_area("Contact Information (phone, email, address)", value=details['contact']) | |
linkedin = st.text_input("LinkedIn Profile URL", value=details['linkedin']) | |
summary = st.text_area("Professional Summary", value=details['summary']) | |
experience = st.text_area("Work Experience (provide details of each job including company name, job title, duration, and responsibilities)", value=details['experience']) | |
education = st.text_area("Education (provide details of degrees, institutions, and graduation dates)", value=details['education']) | |
skills = st.text_area("Skills (list your skills)", value=details['skills']) | |
certifications = st.text_area("Certifications (list any relevant certifications)", value=details['certifications']) | |
projects = st.text_area("Projects (provide details of your projects)", value=details['projects']) | |
submitted = st.form_submit_button("Generate Resume") | |
if submitted: | |
if name and contact and linkedin and summary and experience and education and skills and certifications and projects: | |
details = { | |
'name': name, | |
'contact': contact, | |
'linkedin': linkedin, | |
'summary': summary, | |
'experience': experience, | |
'education': education, | |
'skills': skills, | |
'certifications': certifications, | |
'projects': projects | |
} | |
resume = generate_resume(details) | |
st.header("Generated Resume") | |
st.text(resume) | |
# Save resume as PDF and provide download link | |
pdf_filename = "resume.pdf" | |
create_pdf(resume, pdf_filename) | |
with open(pdf_filename, "rb") as pdf_file: | |
st.download_button( | |
label="Download Resume as PDF", | |
data=pdf_file, | |
file_name=pdf_filename, | |
mime="application/pdf" | |
) | |
else: | |
st.error("Please fill in all the fields to generate the resume.") | |
# st.title("Resume Creation") | |
# uploaded_file = st.file_uploader("Upload a resume to pre-fill details", type=["pdf"]) | |
# if uploaded_file: | |
# extracted_text = extract_text_from_pdf(uploaded_file) | |
# details = parse_extracted_text(extracted_text) | |
# else: | |
# details = { | |
# 'name': "", | |
# 'contact': "", | |
# 'linkedin': "", | |
# 'summary': "", | |
# 'experience': "", | |
# 'education': "", | |
# 'skills': "", | |
# 'certifications': "", | |
# 'projects': "" | |
# } | |
# with st.form("profile_form"): | |
# st.header("Enter your details to generate an ATS-optimized resume") | |
# name = st.text_input("Name") | |
# contact = st.text_area("Contact Information (phone, email, address)") | |
# linkedin = st.text_input("LinkedIn Profile URL") | |
# summary = st.text_area("Professional Summary") | |
# experience = st.text_area("Work Experience (provide details of each job including company name, job title, duration, and responsibilities)") | |
# education = st.text_area("Education (provide details of degrees, institutions, and graduation dates)") | |
# skills = st.text_area("Skills (list your skills)") | |
# certifications = st.text_area("Certifications (list any relevant certifications)") | |
# projects = st.text_area("Projects (provide details of your projects)") | |
# submitted = st.form_submit_button("Generate Resume") | |
# if submitted: | |
# if name and contact and linkedin and summary and experience and education and skills and certifications and projects: | |
# details = { | |
# 'name': name, | |
# 'contact': contact, | |
# 'linkedin': linkedin, | |
# 'summary': summary, | |
# 'experience': experience, | |
# 'education': education, | |
# 'skills': skills, | |
# 'certifications': certifications, | |
# 'projects': projects | |
# } | |
# resume = generate_resume(details) | |
# st.header("Generated Resume") | |
# st.text(resume) | |
# # Save resume as PDF and provide download link | |
# pdf_filename = "resume.pdf" | |
# create_pdf(resume, pdf_filename) | |
# with open(pdf_filename, "rb") as pdf_file: | |
# st.download_button( | |
# label="Download Resume as PDF", | |
# data=pdf_file, | |
# file_name=pdf_filename, | |
# mime="application/pdf" | |
# ) | |
# else: | |
# st.error("Please fill in all the fields to generate the resume.") | |