Spaces:
Sleeping
Sleeping
File size: 7,021 Bytes
bee3f72 b72536d 1ee9de7 bee3f72 ab1ad86 f1664d6 ab1ad86 f1664d6 ab1ad86 f1664d6 ab1ad86 f1664d6 ab1ad86 f1664d6 ab1ad86 f1664d6 ab1ad86 1ee9de7 ab1ad86 1ee9de7 ab1ad86 f1664d6 ab1ad86 f1664d6 ab1ad86 | 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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | import streamlit as st
from services import analyse_service, generation_service
from mock_data import MOCK_JD, MOCK_RESUME, Analysis_Summary, Resume, Cover_Letter
def initialize_session_state():
"""Initializes session state variables."""
if 'summary' not in st.session_state:
st.session_state.summary = None
if 'resume_md' not in st.session_state:
st.session_state.resume_md = None
if 'cover_letter_txt' not in st.session_state:
st.session_state.cover_letter_txt = None
if 'error' not in st.session_state:
st.session_state.error = None
def handle_analyse(jd, user_info):
"""Handles the 'Analyse' button click."""
if not jd or not user_info:
st.session_state.error = "Job Description and User Info cannot be empty."
return
st.session_state.error = None
with st.spinner("Analyzing job description..."):
try:
summary = analyse_service.analyse(jd, user_info)
st.session_state.summary = summary
except Exception as e:
st.session_state.error = f"An error occurred during analysis: {e}"
def handle_generate_resume():
"""Handles the 'Generate Resume' button click."""
if not st.session_state.summary:
st.session_state.error = "You must perform an initial analysis first."
return
st.session_state.error = None
with st.spinner("Generating resume..."):
try:
user_info = st.session_state.user_info_input
resume_md = generation_service.generate_resume(st.session_state.summary, user_info)
st.session_state.resume_md = resume_md
except Exception as e:
st.session_state.error = f"An error occurred during resume generation: {e}"
def handle_generate_cover_letter():
"""Handles the 'Generate Cover Letter' button click."""
if not st.session_state.summary:
st.session_state.error = "You must perform an initial analysis first."
return
st.session_state.error = None
with st.spinner("Generating cover letter..."):
try:
user_info = st.session_state.user_info_input
cover_letter_txt = generation_service.generate_cover_letter(st.session_state.summary, user_info)
st.session_state.cover_letter_txt = cover_letter_txt
except Exception as e:
st.session_state.error = f"An error occurred during cover letter generation: {e}"
def handle_refine(feedback):
"""Handles the 'Refine' button click."""
if not st.session_state.summary:
st.session_state.error = "You must perform an initial analysis first."
return
if not feedback:
st.session_state.error = "Feedback cannot be empty."
return
st.session_state.error = None
with st.spinner("Refining analysis..."):
try:
user_info = st.session_state.user_info_input
updated_summary = analyse_service.refine(st.session_state.summary, feedback)
st.session_state.summary = updated_summary
except Exception as e:
st.session_state.error = f"An error occurred during refinement: {e}"
def handle_mock_analyse():
"""Handles the 'Mock Analyse' button click."""
st.session_state.error = None
st.session_state.summary = Analysis_Summary
st.session_state.resume_md = Resume
st.session_state.cover_letter_txt = Cover_Letter
def main():
"""Main function to run the Streamlit app."""
st.set_page_config(layout="wide")
st.title("AI-powered Resume & Cover Letter Generator")
initialize_session_state()
# --- Sidebar for Inputs and Controls ---
with st.sidebar:
st.header("Inputs")
# Mock data buttons
col1, col2, col3 = st.columns(3)
with col1:
if st.button("Load Mock JD", help="Load sample job description"):
st.session_state.jd_mock = MOCK_JD
with col2:
if st.button("Load Mock Resume", help="Load sample resume"):
st.session_state.resume_mock = MOCK_RESUME
with col3:
if st.button("Mock Analyse", help="Load sample analysis results"):
handle_mock_analyse()
jd_input = st.text_area("1. Paste Job Description",
value=st.session_state.get('jd_mock', ''),
height=150)
user_info_input = st.text_area("2. Paste Your Resume/Info",
value=st.session_state.get('resume_mock', ''),
height=200)
st.session_state.user_info_input = user_info_input # Store for refine
if st.button("Analyse", use_container_width=True):
handle_analyse(jd_input, user_info_input)
st.header("Generate Documents")
col1, col2 = st.columns(2)
with col1:
if st.button("Generate Resume", use_container_width=True):
handle_generate_resume()
with col2:
if st.button("Generate Cover Letter", use_container_width=True):
handle_generate_cover_letter()
st.header("Refine")
feedback_input = st.text_area("3. Provide Feedback to Refine", height=100)
if st.button("Refine", use_container_width=True):
handle_refine(feedback_input)
# --- Main Area for Outputs ---
if st.session_state.error:
st.error(st.session_state.error)
if st.session_state.summary:
st.header("Analysis Summary")
summary = st.session_state.summary
# Key Skills
if 'key_skills' in summary:
st.subheader("🎯 Key Skills")
st.write(", ".join(summary['key_skills']))
# Match Points
if 'match_points' in summary:
st.subheader("✅ Match Points")
for point in summary['match_points']:
st.write(f"• {point}")
# Gap Points
if 'gap_points' in summary:
st.subheader("⚠️ Gap Points")
for gap in summary['gap_points']:
st.write(f"• {gap}")
# Suggestions
if 'suggestions' in summary:
st.subheader("💡 Suggestions")
for suggestion in summary['suggestions']:
st.write(f"• {suggestion}")
# Pitch
if 'pitch' in summary:
st.subheader("🎤 Executive Pitch")
st.write(summary['pitch'])
col1, col2 = st.columns(2)
with col1:
st.header("Resume Preview")
if st.session_state.resume_md:
st.markdown(st.session_state.resume_md)
else:
st.info("Resume will be generated here.")
with col2:
st.header("Cover Letter Preview")
if st.session_state.cover_letter_txt:
st.text(st.session_state.cover_letter_txt)
else:
st.info("Cover Letter will be generated here.")
if __name__ == "__main__":
main()
|