# -*- coding: utf-8 -*- import streamlit as st import os import pandas as pd import matplotlib.pyplot as plt from resume_generation_gemini_pro import generate_gemini from similarity_score_refined import similarity_main from pdf2image import convert_from_path # Helper function to save uploaded files temporarily and return their paths def save_uploaded_file(uploaded_file): file_path = os.path.join("/tmp", uploaded_file.name) with open(file_path, "wb") as f: f.write(uploaded_file.getbuffer()) return file_path # Custom CSS for styling st.markdown(""" """, unsafe_allow_html=True) # Add ResumeMagic Logo # st.image("logo.jpeg", use_container_width=True) st.markdown('
', unsafe_allow_html=True) st.image("logo.jpeg", width=80) st.markdown('', unsafe_allow_html=True) # Title and Description st.title("Resume Tailoring with Google Generative AI") st.markdown("### Upload your resume and job description to check similarity and generate a tailored resume.") # Two columns for file uploaders col1, col2 = st.columns(2) with col1: uploaded_resume = st.file_uploader("Upload Current Resume (.docx or .pdf)", type=["docx", "pdf"], key="resume") with col2: uploaded_job_description = st.file_uploader("Upload Job Description (.docx or .pdf)", type=["docx", "pdf"], key="job_description") def get_score(resume_path, job_description_path): similarity_score = similarity_main(resume_path, job_description_path) if isinstance(similarity_score, str) and '%' in similarity_score: similarity_score = float(similarity_score.replace('%', '')) # Display messages based on score range if similarity_score < 50: st.markdown('Low chance, skills gap identified!
', unsafe_allow_html=True) pie_colors = ['#FF4B4B', '#E5E5E5'] elif 50 <= similarity_score < 70: st.markdown('Good chance but you can improve further!
', unsafe_allow_html=True) pie_colors = ['#FFC107', '#E5E5E5'] else: st.markdown('Excellent! You can submit your CV.
', unsafe_allow_html=True) pie_colors = ['#4CAF50', '#E5E5E5'] return similarity_score, pie_colors def display_score(similarity, colors): # Display Score as a Pie Chart st.markdown(f"### Resume - Job Match: {int(similarity_score)}%") # Pie chart to show similarity fig, ax = plt.subplots() # ax.pie([similarity_score, 100 - similarity_score], labels=['Match', 'Difference'], autopct='%1.1f%%', startangle=140, colors=['#4B7BE5', '#E5E5E5']) ax.pie([similarity_score, 100 - similarity_score], labels=['Match', 'Difference'], autopct='%1.1f%%', startangle=140, colors=pie_colors) ax.axis('equal') st.pyplot(fig) def save_docx_as_pdf(doc_content, output_path='output.pdf'): # Save document content as a .docx file temp_doc_path = 'temp.docx' doc = Document() doc.add_paragraph(doc_content) doc.save(temp_doc_path) # Convert .docx to PDF from docx2pdf import convert convert(temp_doc_path, output_path) os.remove(temp_doc_path) def display_doc_as_image(pdf_path): poppler_path = 'usr/bin' images = convert_from_path(pdf_path, poppler_path=poppler_path) for img in images: buf = BytesIO() img.save(buf, format="PNG") st.image(buf) # Process if files are uploaded if uploaded_resume and uploaded_job_description: # Save files resume_path = save_uploaded_file(uploaded_resume) job_description_path = save_uploaded_file(uploaded_job_description) # Similarity Score Section st.markdown("---") # st.subheader("Check Job Match") if st.button("Resume-JD Matching"): with st.spinner("Computing Match"): similarity_score, pie_colors = get_score(resume_path, job_description_path) display_score(similarity_score, pie_colors) #Autoscroll st.markdown(""" """, unsafe_allow_html=True) # Generate Tailored Resume Section st.markdown("---") # st.subheader("Tailor Resume") if st.button("Tailor Resume"): with st.spinner("Generating resume..."): generated_resume, new_resume_path = generate_gemini(resume_path, job_description_path) # st.markdown("Generated Tailored Resume:") # st.write(generated_resume) #Autoscroll st.markdown(""" """, unsafe_allow_html=True) col1, col2 = st.columns(2) with col1: st.markdown("### Uploaded Resume:") # if resume_path.endswith('.docx'): # save_docx_as_pdf(uploaded_resume.getvalue().decode('utf-8'), 'uploaded_resume.pdf') if uploaded_resume.type == "application/pdf": display_doc_as_image(resume_path) else: save_docx_as_pdf(resume_path, 'uploaded_resume.pdf') display_doc_as_image('uploaded_resume.pdf') with col2: st.markdown("### Tailored Resume:") save_docx_as_pdf(generated_resume, 'tailored_resume.pdf') display_doc_as_image('tailored_resume.pdf') with st.spinner("Computing Match"): similarity_score, pie_colors = get_score(resume_path, job_description_path) display_score(similarity_score, pie_colors) if generated_resume is not None: from io import BytesIO from docx import Document doc = Document() doc.add_paragraph(generated_resume) resume_bytes = BytesIO() doc.save(resume_bytes) resume_bytes.seek(0) st.download_button( label="Download Resume", data=resume_bytes, file_name="tailored_resume.docx", mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document" ) else: st.warning("Please upload both the resume and job description files.")