Spaces:
Running
Running
File size: 6,806 Bytes
5dec17e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
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") |