ats-optimizer / app.py
CapProj's picture
Upload 25 files
5dec17e verified
import streamlit as st
from ats_optimizer.core import ResumeAnalyzer, ResumeOptimizer
from ats_optimizer.data_models import Resume, JobDescription
from ats_optimizer.utils.file_handlers import FileHandler # Updated import
# from ats_optimizer.utils import FileHandler, Config
from ats_optimizer.utils.config_manager import Config
from pathlib import Path
import tempfile
import sys
# Fix module imports for Hugging Face
sys.path.append(str(Path(__file__).parent))
# def main():
# # Initialize components
# config = Config('config.yaml')
# analyzer = ResumeAnalyzer()
# optimizer = ResumeOptimizer(config.deepseek_api_key)
# # Streamlit UI
# st.title("πŸš€ ATS Optimizer Pro")
# st.markdown("Upload your resume and job description to analyze and optimize for ATS compatibility")
# # File upload section
# with st.expander("Upload Files", expanded=True):
# col1, col2 = st.columns(2)
# with col1:
# resume_file = st.file_uploader("Resume", type=["pdf", "docx"], key="resume_upload")
# with col2:
# jd_file = st.file_uploader("Job Description", type=["pdf", "docx", "txt"], key="jd_upload")
# if st.button("Analyze", type="primary"):
# if resume_file and jd_file:
# with st.spinner("Processing files..."):
# try:
# # Save uploaded files
# with tempfile.TemporaryDirectory() as temp_dir:
# resume_path = FileHandler.save_uploaded_file(resume_file, temp_dir)
# jd_path = FileHandler.save_uploaded_file(jd_file, temp_dir)
# if not resume_path or not jd_path:
# st.error("Failed to process uploaded files")
# return
# # Analyze documents
# resume = analyzer.parse_resume(resume_path)
# jd = analyzer.parse_jd(jd_path)
# # Calculate score
# score = analyzer.calculate_ats_score(resume, jd)
# # Display results
# st.subheader("πŸ“Š Analysis Results")
# st.metric("Overall ATS Score", f"{score['overall_score']:.1f}%")
# with st.expander("Detailed Scores"):
# st.write(f"Keyword Match: {score['keyword_score']:.1f}%")
# st.write(f"Section Completeness: {score['section_score']:.1f}%")
# st.write(f"Experience Match: {score['experience_score']:.1f}%")
# # Optimization section
# st.subheader("πŸ›  Optimization")
# if st.button("Optimize Resume", key="optimize_btn"):
# with st.spinner("Rewriting resume..."):
# optimized = optimizer.rewrite_resume(resume, jd)
# temp_output = Path(temp_dir) / "optimized_resume.docx"
# FileHandler.save_resume(optimized, str(temp_output))
# st.success("Optimization complete!")
# with open(temp_output, "rb") as f:
# st.download_button(
# "Download Optimized Resume",
# data=f,
# file_name="optimized_resume.docx",
# mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
# )
# except Exception as e:
# st.error(f"An error occurred: {str(e)}")
# st.stop()
# else:
# st.warning("Please upload both resume and job description files")
# if __name__ == "__main__":
# main()
def main():
# Initialize components
config = Config('config.yaml')
analyzer = ResumeAnalyzer()
optimizer = ResumeOptimizer(config.deepseek_api_key)
# Streamlit UI
st.title("ATS Optimizer Pro")
# File upload
resume_file = st.file_uploader("Upload Resume", type=["pdf", "docx"])
jd_file = st.file_uploader("Upload Job Description", type=["pdf", "docx", "txt"])
if st.button("Analyze"):
if resume_file and jd_file:
with st.spinner("Processing..."):
try:
# Create temp directory
with tempfile.TemporaryDirectory() as temp_dir:
# Save uploaded files
resume_path = FileHandler.save_uploaded_file(resume_file, temp_dir)
jd_path = FileHandler.save_uploaded_file(jd_file, temp_dir)
if not resume_path or not jd_path:
st.error("Failed to process uploaded files")
return
# Analyze documents
resume = analyzer.parse_resume(resume_path)
jd = analyzer.parse_jd(jd_path)
# Calculate score
score = analyzer.calculate_ats_score(resume, jd)
# Display results
st.subheader("Analysis Results")
st.json(score)
# Optimization
if st.button("Optimize Resume"):
optimized = optimizer.rewrite_resume(resume, jd)
output_path = os.path.join(temp_dir, "optimized_resume.docx")
if FileHandler.save_resume(optimized, output_path):
with open(output_path, "rb") as f:
st.download_button(
"Download Optimized Resume",
data=f,
file_name="optimized_resume.docx"
)
except Exception as e:
st.error(f"An error occurred: {str(e)}")
else:
st.warning("Please upload both resume and job description files")