Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
from langchain_community.llms import HuggingFaceHub
|
| 4 |
+
from PyPDF2 import PdfReader
|
| 5 |
+
import docx2txt
|
| 6 |
+
|
| 7 |
+
# Set Hugging Face token (Get yours from https://huggingface.co/settings/tokens)
|
| 8 |
+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = st.secrets["HUGGINGFACEHUB_API_TOKEN"]
|
| 9 |
+
|
| 10 |
+
# Initialize Mistral 7B model
|
| 11 |
+
repo_id = "mistralai/Mistral-7B-v0.1"
|
| 12 |
+
llm = HuggingFaceHub(
|
| 13 |
+
repo_id=repo_id,
|
| 14 |
+
model_kwargs={"temperature": 0.5, "max_length": 4096}
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
def extract_text(uploaded_file):
|
| 18 |
+
"""Extract text from PDF or DOCX files"""
|
| 19 |
+
if uploaded_file.type == "application/pdf":
|
| 20 |
+
pdf_reader = PdfReader(uploaded_file)
|
| 21 |
+
return "\n".join([page.extract_text() for page in pdf_reader.pages])
|
| 22 |
+
elif uploaded_file.type == "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
|
| 23 |
+
return docx2txt.process(uploaded_file)
|
| 24 |
+
return ""
|
| 25 |
+
|
| 26 |
+
def analyze_resume(resume_text, job_desc):
|
| 27 |
+
"""Analyze resume using Mistral 7B"""
|
| 28 |
+
prompt = f"""
|
| 29 |
+
Analyze this resume against the job description below. Provide:
|
| 30 |
+
1. Top 5 missing keywords from job description
|
| 31 |
+
2. Three suggested improvements
|
| 32 |
+
3. ATS compatibility score (0-100)
|
| 33 |
+
|
| 34 |
+
Resume:
|
| 35 |
+
{resume_text[:3000]}
|
| 36 |
+
|
| 37 |
+
Job Description:
|
| 38 |
+
{job_desc[:2000]}
|
| 39 |
+
|
| 40 |
+
Format output using markdown with clear sections.
|
| 41 |
+
"""
|
| 42 |
+
return llm.invoke(prompt)
|
| 43 |
+
|
| 44 |
+
def check_ats_compliance(text):
|
| 45 |
+
"""Basic ATS formatting checks"""
|
| 46 |
+
forbidden_elements = ["table", "image", "column", "graphic"]
|
| 47 |
+
return all(element not in text.lower() for element in forbidden_elements)
|
| 48 |
+
|
| 49 |
+
def generate_ats_version(text):
|
| 50 |
+
"""Convert text to ATS-friendly format"""
|
| 51 |
+
return text.replace("\n", " ").strip()
|
| 52 |
+
|
| 53 |
+
# Streamlit UI
|
| 54 |
+
st.set_page_config(page_title="ATS Resume Optimizer", layout="wide")
|
| 55 |
+
|
| 56 |
+
st.title("📄 Free ATS Resume Optimizer")
|
| 57 |
+
st.markdown("Upload your resume and job description to get AI-powered optimization tips!")
|
| 58 |
+
|
| 59 |
+
col1, col2 = st.columns(2)
|
| 60 |
+
|
| 61 |
+
with col1:
|
| 62 |
+
uploaded_file = st.file_uploader("Upload Resume (PDF/DOCX)", type=["pdf", "docx"])
|
| 63 |
+
job_description = st.text_area("Paste Job Description", height=200)
|
| 64 |
+
|
| 65 |
+
with col2:
|
| 66 |
+
if uploaded_file and job_description:
|
| 67 |
+
if st.button("Analyze and Optimize"):
|
| 68 |
+
with st.spinner("Processing with Mistral 7B..."):
|
| 69 |
+
resume_text = extract_text(uploaded_file)
|
| 70 |
+
|
| 71 |
+
# Perform analysis
|
| 72 |
+
analysis = analyze_resume(resume_text, job_description)
|
| 73 |
+
ats_compliant = check_ats_compliance(resume_text)
|
| 74 |
+
optimized_text = generate_ats_version(resume_text)
|
| 75 |
+
|
| 76 |
+
# Display results
|
| 77 |
+
st.subheader("Analysis Results")
|
| 78 |
+
st.markdown(analysis)
|
| 79 |
+
|
| 80 |
+
st.subheader("ATS Compliance Check")
|
| 81 |
+
st.metric("Format Status", "Pass ✅" if ats_compliant else "Fail ❌")
|
| 82 |
+
|
| 83 |
+
# Download optimized version
|
| 84 |
+
st.download_button(
|
| 85 |
+
label="Download ATS-Optimized Resume",
|
| 86 |
+
data=optimized_text,
|
| 87 |
+
file_name="optimized_resume.txt",
|
| 88 |
+
mime="text/plain"
|
| 89 |
+
)
|
| 90 |
+
else:
|
| 91 |
+
st.info("👈 Upload your resume and paste a job description to get started")
|
| 92 |
+
|
| 93 |
+
st.markdown("---")
|
| 94 |
+
st.caption("Note: This tool uses Mistral 7B AI model for analysis. Always review suggestions before submitting applications.")
|