Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,3 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from fpdf import FPDF
|
| 3 |
-
import tempfile
|
| 4 |
-
from io import BytesIO
|
| 5 |
-
from PIL import Image
|
| 6 |
-
import re
|
| 7 |
-
|
| 8 |
-
# Custom CSS for UI enhancements
|
| 9 |
-
def apply_custom_css():
|
| 10 |
-
st.markdown("""
|
| 11 |
-
<style>
|
| 12 |
-
.title {
|
| 13 |
-
font-size: 2.5rem;
|
| 14 |
-
color: #4CAF50;
|
| 15 |
-
text-align: center;
|
| 16 |
-
margin-bottom: 20px;
|
| 17 |
-
}
|
| 18 |
-
.subtitle {
|
| 19 |
-
font-size: 1.5rem;
|
| 20 |
-
color: #FF5722;
|
| 21 |
-
margin-top: 20px;
|
| 22 |
-
margin-bottom: 10px;
|
| 23 |
-
}
|
| 24 |
-
.separator {
|
| 25 |
-
border-top: 2px solid #eee;
|
| 26 |
-
margin-top: 30px;
|
| 27 |
-
margin-bottom: 30px;
|
| 28 |
-
}
|
| 29 |
-
.suggestions {
|
| 30 |
-
background-color: #f9f9f9;
|
| 31 |
-
border-left: 4px solid #2196F3;
|
| 32 |
-
padding: 10px;
|
| 33 |
-
margin: 10px 0;
|
| 34 |
-
}
|
| 35 |
-
</style>
|
| 36 |
-
""", unsafe_allow_html=True)
|
| 37 |
-
|
| 38 |
-
# Function to calculate the ATS score
|
| 39 |
-
def calculate_ats_score(resume_text, job_description):
|
| 40 |
-
resume_keywords = set(re.findall(r'\w+', resume_text.lower()))
|
| 41 |
-
job_keywords = set(re.findall(r'\w+', job_description.lower()))
|
| 42 |
-
common_keywords = resume_keywords.intersection(job_keywords)
|
| 43 |
-
|
| 44 |
-
score = (len(common_keywords) / len(job_keywords)) * 100
|
| 45 |
-
suggestions = set(job_keywords) - common_keywords
|
| 46 |
-
return score, suggestions
|
| 47 |
-
|
| 48 |
-
# Resume Builder Class using FPDF
|
| 49 |
class ResumeBuilder(FPDF):
|
| 50 |
def header(self):
|
| 51 |
self.set_font("Arial", "B", 16)
|
|
@@ -62,23 +14,22 @@ class ResumeBuilder(FPDF):
|
|
| 62 |
self.multi_cell(0, 10, content)
|
| 63 |
self.ln(5)
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
# Add the image to the PDF
|
| 79 |
-
self.image(temp_file_path, x=10, y=self.get_y(), w=30, h=30)
|
| 80 |
-
self.set_y(self.get_y() + 35)
|
| 81 |
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
def add_social_icons(self, linkedin=None, email=None, phone=None):
|
| 84 |
self.set_font("Arial", "B", 12)
|
|
@@ -99,101 +50,3 @@ class ResumeBuilder(FPDF):
|
|
| 99 |
self.set_font("Arial", "", 12)
|
| 100 |
self.multi_cell(0, 10, "\n".join(skills))
|
| 101 |
self.ln(5)
|
| 102 |
-
|
| 103 |
-
# Function to generate ATS-friendly Resume
|
| 104 |
-
def generate_resume(data, picture):
|
| 105 |
-
pdf = ResumeBuilder()
|
| 106 |
-
pdf.add_page()
|
| 107 |
-
|
| 108 |
-
if picture:
|
| 109 |
-
pdf.add_image(picture)
|
| 110 |
-
|
| 111 |
-
pdf.add_section("Name", data["name"])
|
| 112 |
-
pdf.add_section("Summary", data["summary"])
|
| 113 |
-
pdf.add_section("Experience", data["experience"])
|
| 114 |
-
pdf.add_section("Education", data["education"])
|
| 115 |
-
|
| 116 |
-
pdf.add_skills(data["skills"], "Software Skills")
|
| 117 |
-
pdf.add_skills(data["certifications"], "Certifications")
|
| 118 |
-
pdf.add_skills(data["languages"], "Languages")
|
| 119 |
-
|
| 120 |
-
pdf.add_social_icons(
|
| 121 |
-
linkedin=data["linkedin"],
|
| 122 |
-
email=data["email"],
|
| 123 |
-
phone=data["phone"],
|
| 124 |
-
)
|
| 125 |
-
|
| 126 |
-
pdf_output = BytesIO()
|
| 127 |
-
pdf.output(pdf_output)
|
| 128 |
-
pdf_output.seek(0)
|
| 129 |
-
return pdf_output
|
| 130 |
-
|
| 131 |
-
# Main App
|
| 132 |
-
def main():
|
| 133 |
-
apply_custom_css()
|
| 134 |
-
|
| 135 |
-
st.markdown("<div class='title'>ATS Resume Helper</div>", unsafe_allow_html=True)
|
| 136 |
-
|
| 137 |
-
st.sidebar.title("Features")
|
| 138 |
-
selected_feature = st.sidebar.radio(
|
| 139 |
-
"Select a feature:", ["Resume Checker", "Build ATS-Friendly Resume"]
|
| 140 |
-
)
|
| 141 |
-
|
| 142 |
-
if selected_feature == "Resume Checker":
|
| 143 |
-
st.subheader("📂 Upload your Resume")
|
| 144 |
-
uploaded_resume = st.file_uploader(
|
| 145 |
-
"Upload Resume (PDF or Word):", type=["pdf", "docx"]
|
| 146 |
-
)
|
| 147 |
-
job_description = st.text_area("📋 Paste Job Description:")
|
| 148 |
-
|
| 149 |
-
if uploaded_resume:
|
| 150 |
-
text = extract_text_from_pdf(uploaded_resume) if uploaded_resume.name.endswith(".pdf") else extract_text_from_docx(uploaded_resume)
|
| 151 |
-
score, suggestions = calculate_ats_score(text, job_description)
|
| 152 |
-
|
| 153 |
-
st.write(f"Your ATS Score: {score:.2f}/100")
|
| 154 |
-
st.write("Suggestions to improve your resume:")
|
| 155 |
-
for suggestion in suggestions:
|
| 156 |
-
st.write(f"- {suggestion}")
|
| 157 |
-
|
| 158 |
-
elif selected_feature == "Build ATS-Friendly Resume":
|
| 159 |
-
st.subheader("🛠️ Build Your Resume")
|
| 160 |
-
with st.form("resume_form"):
|
| 161 |
-
name = st.text_input("Full Name")
|
| 162 |
-
summary = st.text_area("Professional Summary")
|
| 163 |
-
experience = st.text_area("Work Experience")
|
| 164 |
-
skills = st.text_area("Software Skills (separated by lines)")
|
| 165 |
-
certifications = st.text_area("Certifications (separated by lines)")
|
| 166 |
-
languages = st.text_area("Languages (separated by lines)")
|
| 167 |
-
linkedin = st.text_input("LinkedIn URL")
|
| 168 |
-
email = st.text_input("Email Address")
|
| 169 |
-
phone = st.text_input("Phone Number")
|
| 170 |
-
|
| 171 |
-
picture = st.file_uploader("Upload Profile Picture", type=["jpg", "png"])
|
| 172 |
-
submitted = st.form_submit_button("Generate Resume")
|
| 173 |
-
|
| 174 |
-
if submitted:
|
| 175 |
-
if not all([name, summary, experience, skills, certifications, languages, email]):
|
| 176 |
-
st.error("Please fill all mandatory fields!")
|
| 177 |
-
else:
|
| 178 |
-
data = {
|
| 179 |
-
"name": name,
|
| 180 |
-
"summary": summary,
|
| 181 |
-
"experience": experience,
|
| 182 |
-
"skills": skills.splitlines(),
|
| 183 |
-
"certifications": certifications.splitlines(),
|
| 184 |
-
"languages": languages.splitlines(),
|
| 185 |
-
"linkedin": linkedin,
|
| 186 |
-
"email": email,
|
| 187 |
-
"phone": phone,
|
| 188 |
-
}
|
| 189 |
-
resume_pdf = generate_resume(data, picture)
|
| 190 |
-
st.success("Resume generated successfully!")
|
| 191 |
-
st.download_button(
|
| 192 |
-
label="Download Resume",
|
| 193 |
-
data=resume_pdf,
|
| 194 |
-
file_name=f"{name}_resume.pdf",
|
| 195 |
-
mime="application/pdf",
|
| 196 |
-
)
|
| 197 |
-
|
| 198 |
-
if __name__ == "__main__":
|
| 199 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
class ResumeBuilder(FPDF):
|
| 2 |
def header(self):
|
| 3 |
self.set_font("Arial", "B", 16)
|
|
|
|
| 14 |
self.multi_cell(0, 10, content)
|
| 15 |
self.ln(5)
|
| 16 |
|
| 17 |
+
def add_image(self, image):
|
| 18 |
+
# Open the image
|
| 19 |
+
image = Image.open(image)
|
| 20 |
+
|
| 21 |
+
# Convert image to RGB (remove alpha channel if it exists)
|
| 22 |
+
if image.mode == "RGBA":
|
| 23 |
+
image = image.convert("RGB")
|
| 24 |
+
|
| 25 |
+
# Save the image in a temporary file in a format that FPDF accepts (JPEG)
|
| 26 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
|
| 27 |
+
image.save(temp_file, "JPEG") # Ensure the image is saved as JPEG
|
| 28 |
+
temp_file_path = temp_file.name
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# Add the image to the PDF
|
| 31 |
+
self.image(temp_file_path, x=10, y=self.get_y(), w=30, h=30)
|
| 32 |
+
self.set_y(self.get_y() + 35)
|
| 33 |
|
| 34 |
def add_social_icons(self, linkedin=None, email=None, phone=None):
|
| 35 |
self.set_font("Arial", "B", 12)
|
|
|
|
| 50 |
self.set_font("Arial", "", 12)
|
| 51 |
self.multi_cell(0, 10, "\n".join(skills))
|
| 52 |
self.ln(5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|