Spaces:
Running
Running
File size: 5,571 Bytes
b3670e0 d8cb149 f000501 b3670e0 d8cb149 0ee69bb b3670e0 0ee69bb b3670e0 0ee69bb b3670e0 cca6234 b3670e0 d8cb149 b3670e0 d8cb149 d1b0662 d8cb149 99f27a0 d8cb149 d1b0662 4e7998e d1b0662 d8cb149 b3670e0 d8cb149 b3670e0 ae6c42c d8cb149 ae6c42c d8cb149 ae6c42c d8cb149 ae6c42c d8cb149 ae6c42c d8cb149 b3670e0 cca6234 |
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 140 141 142 143 144 145 146 147 148 149 150 |
import streamlit as st
import sys
import os
import tempfile
import uuid
import webbrowser
from urllib.parse import urlencode
# Add the src directory to the Python path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src')))
from src.resume_analyzer import optimize_resume
from src.pdf_handler import read_pdf
from src.google_docs_api_processing import google_docs_auth, create_google_doc
from credentials_creation import create_credentials
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from io import BytesIO
st.set_page_config(page_title="Resume Optimizer", layout="wide")
# Generate credentials.json dynamically
create_credentials()
# Create a directory to store uploaded files
UPLOAD_DIR = os.path.join(os.path.dirname(__file__), '..', 'uploads')
os.makedirs(UPLOAD_DIR, exist_ok=True)
def create_pdf(text):
buffer = BytesIO()
c = canvas.Canvas(buffer, pagesize=letter)
width, height = letter
y = height - 50 # Start near the top of the page
for line in text.split('\n'):
if y < 50: # If we're near the bottom of the page
c.showPage() # Start a new page
y = height - 50 # Reset y to the top of the new page
c.drawString(50, y, line)
y -= 15 # Move down for the next line
c.save()
buffer.seek(0)
return buffer
def save_uploaded_file(uploaded_file):
"""Save the uploaded file and return the file path."""
try:
file_path = os.path.join(UPLOAD_DIR, uploaded_file.name)
with open(file_path, 'wb') as f:
f.write(uploaded_file.getvalue())
return file_path
except Exception as e:
st.error(f"An error occurred while saving the file: {str(e)}")
return None
def main():
st.title("Resume Tailor")
# File upload and manual entry option
upload_option = st.radio("Choose how to input your resume:", ("Upload PDF", "Enter manually"))
resume_content = None
if upload_option == "Upload PDF":
resume_file = st.file_uploader("Upload your resume (PDF)", type="pdf")
if resume_file is not None:
file_path = save_uploaded_file(resume_file)
if file_path:
resume_content = read_pdf(file_path)
if resume_content.startswith("An error occurred"):
st.error(resume_content)
resume_content = None
else:
st.success("PDF successfully read!")
st.text_area("Extracted Content", resume_content, height=200, placeholder="Your resume content will appear here...")
# Clean up: remove the file after reading
os.remove(file_path)
else:
resume_content = st.text_area("Enter your resume text", height=300, placeholder="Paste or type your resume here...")
job_description = st.text_area("Enter the job description", placeholder="Paste the job description here...")
# Create a container for buttons with custom CSS
button_container = st.container()
with button_container:
col1, col2, col3 = st.columns([1, 2, 1])
with col1:
optimize_button = st.button("Optimize Resume")
# with col2:
# open_in_google_docs_button = st.button("Open in Google Docs")
# Add custom CSS to style the buttons
st.markdown("""
<style>
div.stButton > button {
width: 50%;
margin: 0;
display: block
}
</style>
""", unsafe_allow_html=True)
# Initialize session state for storing results
if 'analysis_dict' not in st.session_state:
st.session_state.analysis_dict = None
if 'updated_resume' not in st.session_state:
st.session_state.updated_resume = None
if optimize_button and resume_content and job_description:
with st.spinner("Analyzing and optimizing your resume..."):
st.session_state.analysis_dict, st.session_state.updated_resume = optimize_resume(resume_content, job_description)
if st.session_state.analysis_dict and st.session_state.updated_resume:
st.success("Analysis complete!")
display_results()
else:
st.error("An error occurred during analysis. Please try again.")
# if open_in_google_docs_button and st.session_state.updated_resume:
# # Authenticate and create Google Docs API service
# service = google_docs_auth()
# # Create a Google Doc and get its URL
# doc_url = create_google_doc(service, st.session_state.updated_resume)
# st.success('Google Doc created successfully')
# st.write(f'[Open the Google Doc]({doc_url})')
# # Open the document in the browser
# webbrowser.open(doc_url)
# # Display results again to keep them visible
# display_results()
def display_results():
if st.session_state.analysis_dict and st.session_state.updated_resume:
# Display analysis results
for key, value in st.session_state.analysis_dict.items():
st.subheader(key.replace('_', ' ').title())
if isinstance(value, list):
for item in value:
st.write(f"- {item}")
else:
st.write(value)
# Display updated resume
st.subheader("Updated Resume")
st.text_area("", value=st.session_state.updated_resume, height=300, placeholder="Your optimized resume will appear here...")
if __name__ == "__main__":
main()
|