Spaces:
Sleeping
Sleeping
import streamlit as st | |
import groq | |
from prompts import analyze_job_fit, optimize_latex_resume,evaluate_resume,generate_cover_letter | |
import json | |
def main(): | |
st.set_page_config( | |
layout="wide", | |
page_title="Resume Enhancer", | |
initial_sidebar_state="collapsed" | |
) | |
file_path = 'latex.txt' | |
with open(file_path, 'r') as f: | |
latex_template = f.read() | |
MODELS = [ | |
"deepseek-r1-distill-llama-70b", | |
"gemma2-9b-it", | |
"llama-3.2-1b-preview", | |
"llama-3.2-3b-preview", | |
"llama-3.3-70b-versatile", | |
"llama-guard-3-8b", | |
"llama3-70b-8192", | |
"mixtral-8x7b-32768"] | |
# Custom CSS with reduced text sizes | |
st.markdown(""" | |
<style> | |
.block-container { | |
padding-top: 1.5rem; | |
padding-bottom: 1.5rem; | |
max-width: 1200px; | |
} | |
.stButton>button { | |
background-color: #2563eb; | |
color: white; | |
border-radius: 0.375rem; | |
padding: 0.75rem 1.5rem; | |
border: none; | |
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05); | |
margin: 0.5rem; | |
min-width: 200px; | |
font-size: 0.875rem; | |
} | |
[data-testid="stFileUploader"] { | |
border: 2px dashed #e5e7eb; | |
border-radius: 0.5rem; | |
padding: 0.875rem; | |
min-height: 220px; | |
font-size: 0.875rem; | |
} | |
.stTextArea>div>div { | |
border-radius: 0.5rem; | |
min-height: 220px !important; | |
font-size: 0.875rem; | |
} | |
.stTextInput>div>div>input { | |
border-radius: 0.5rem; | |
font-size: 0.875rem; | |
} | |
.resume-html { | |
padding: 1.5rem; | |
max-width: 800px; | |
margin: 0 auto; | |
background: white; | |
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); | |
border-radius: 0.5rem; | |
font-size: 0.875rem; | |
} | |
h1 {font-size: 3rem !important; /* Adjust this value to increase the font size */ | |
} h2 {font-size: 1.5rem !important; /* Adjust this value to increase the font size */ | |
h3, h4, h5, h6 { | |
font-size: 80% !important; | |
} | |
p, li { | |
font-size: 0.875rem !important; | |
} | |
</style> | |
""", unsafe_allow_html=True) | |
# Header with smaller text | |
st.markdown(""" | |
<h1 style='text-align: center; font-size: 2.5rem; font-weight: 800; margin-bottom: 0.875rem;'> | |
Resume and CV crafter | |
</h1> | |
""", unsafe_allow_html=True) | |
st.markdown(""" | |
<h2 style='text-align: center; font-size: 1.5rem; font-weight: 400; margin-bottom: 0.875rem;'> | |
Analyze your profile based on job description and arranges your information accordinly and generates latex code version | |
</h2> | |
""", unsafe_allow_html=True) | |
st.markdown("---") | |
# Initialize variables | |
resume_text = None | |
job_description = None | |
original_file = None | |
# Side-by-side inputs with equal width | |
col1, col2 = st.columns(2) | |
with col1: | |
st.markdown("##### Upload your biodata as JSON file (for sample format check the sample.json in the files section)") | |
resume = st.file_uploader( | |
"Drop your resume file here", | |
type=['json'] | |
) | |
if resume is not None: | |
resume_text = json.load(resume) | |
with col2: | |
st.markdown("##### Job Description") | |
job_description = st.text_area( | |
"Paste job description", | |
placeholder="Paste the job description here...", | |
height=220, | |
label_visibility="collapsed" | |
) | |
# Centered API key input first | |
key = st.text_input( | |
"GROQ API Key", | |
type="password", | |
placeholder="Enter your GROQ API key...", | |
help="Your API key will not be stored" | |
) | |
selected_model =st.selectbox("Select Model", MODELS) | |
st.markdown("The selected model will be used for the major tasks such as latex code generation for resume and cover letter") | |
if key: | |
client = groq.Client(api_key=key) | |
# Centered action buttons | |
col_buttons, _, _ = st.columns([200,1,1]) | |
with col_buttons: | |
col_b1, col_b2, col_b3 = st.columns(3) | |
process_quick = col_b1.button("Quick Analysis") | |
generate_reusme = col_b2.button("Generate Latex code for Resume") | |
geenrate_coverletter = col_b3.button("Generate latex code Cover Letter") | |
#to check if any of the buttons are clicked | |
if any([process_quick, generate_reusme, generate_cover_letter]): | |
if not resume_text: | |
st.error("Please upload your resume data in JSON format.") | |
elif not job_description: | |
st.error("Please paste provide the job description.") | |
else: | |
try: | |
with st.spinner("Processing your resume..."): | |
if process_quick: | |
analysis = analyze_job_fit(client, resume_text, job_description) | |
st.markdown("### Quick Analysis Results") | |
st.markdown(analysis) | |
elif generate_reusme: | |
with st.spinner(f"Optimizing LaTeX Resume using {selected_model}..."): | |
analysis = analyze_job_fit(client, resume_text, job_description) | |
optimized_latex = optimize_latex_resume( | |
client, analysis, latex_template, resume_text, selected_model) | |
st.subheader("Optimized LaTeX Resume") | |
st.code(optimized_latex, language="latex") | |
resume_evalaution = evaluate_resume(client, latex_template, optimized_latex, job_description, selected_model) | |
st.subheader("Resume Evaluation") | |
st.markdown(resume_evalaution) | |
else: # generate cover letter | |
cv_latex = generate_cover_letter(client, resume_text, job_description, selected_model) | |
st.subheader("latex code for Cover Letter") | |
st.code(cv_latex, language="latex") | |
except groq.RateLimitError as e: | |
st.error("API rate limit exceeded. Please try again later or use a different API key.") | |
except Exception as e: | |
st.error(f"An error occurred: {e}") | |
else: | |
st.info("π Please enter your GROQ API key to get started.") | |
if __name__ == "__main__": | |
main() |