File size: 7,891 Bytes
6db7601
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import time
from datetime import datetime
import os
from src.groq_client import analyze_resume

def show_analysis_page():
    """Display the analysis page with resume scoring and feedback"""
    st.header("Resume Analysis")
    
    # Check if resume data is available
    if st.session_state.resume_data is None:
        st.info("Please upload your resume on the Home page first.")
        return
    
    # Check if job role is available
    if not st.session_state.job_role:
        st.warning("Please specify your target job role on the Home page.")
        return
    
    # Display resume and job role information
    st.subheader("Analysis Information")
    col1, col2 = st.columns(2)
    with col1:
        st.markdown(f"**Resume**: {st.session_state.resume_data['filename']}")
    with col2:
        st.markdown(f"**Target Job Role**: {st.session_state.job_role}")
    
    # Check if analysis results are already available
    if st.session_state.analysis_results is None:
        # Show analysis in progress
        with st.spinner("Analyzing your resume... This may take a moment."):
            try:
                # Call the Groq API to analyze the resume
                analysis_results = analyze_resume(
                    resume_text=st.session_state.resume_data["text"],
                    job_role=st.session_state.job_role,
                    job_description=st.session_state.get("job_description", None)
                )
                
                # Store the analysis results in session state
                st.session_state.analysis_results = {
                    **analysis_results,
                    "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                }
                
                # Add to history for comparison
                st.session_state.history.append({
                    "filename": st.session_state.resume_data["filename"],
                    "job_role": st.session_state.job_role,
                    "timestamp": st.session_state.analysis_results["timestamp"],
                    "ats_score": st.session_state.analysis_results["ats_score"],
                    "keyword_match": st.session_state.analysis_results["keyword_match"],
                    "format_score": st.session_state.analysis_results["format_score"],
                    "readability_score": st.session_state.analysis_results["readability_score"]
                })
                
                # Success message
                st.success("Analysis completed successfully!")
                
            except Exception as e:
                st.error(f"Error analyzing resume: {str(e)}")
                return
    
    # Display the analysis results
    results = st.session_state.analysis_results
    
    # Overall ATS Score
    st.subheader("ATS Compatibility Score")
    score_col1, score_col2 = st.columns([1, 3])
    with score_col1:
        st.markdown(
            f"<div style='background-color: {'#4CAF50' if results['ats_score'] >= 80 else '#FFC107' if results['ats_score'] >= 60 else '#F44336'}; "
            f"padding: 20px; border-radius: 10px; text-align: center;'>"
            f"<h1 style='color: white; margin: 0;'>{results['ats_score']}/100</h1>"
            f"</div>",
            unsafe_allow_html=True
        )
    with score_col2:
        st.markdown(f"**Analysis Date**: {results['timestamp']}")
        st.markdown(f"**Keyword Match**: {results['keyword_match']}/100")
        st.markdown(f"**Format & Structure**: {results['format_score']}/100")
        st.markdown(f"**Readability**: {results['readability_score']}/100")
        
        # Detailed Format Scores
        st.markdown("### Detailed Format Scores")
        format_scores = {
            "Document Structure": results.get('document_structure_score', 0),
            "Section Headers": results.get('section_headers_score', 0),
            "Content Organization": results.get('content_organization_score', 0),
            "Visual Layout": results.get('visual_layout_score', 0)
        }
        
        for score_name, score in format_scores.items():
            st.markdown(
                f"<div style='margin-bottom: 10px;'>"
                f"<span style='color: #666;'>{score_name}:</span> "
                f"<span style='color: {'#4CAF50' if score >= 80 else '#FFC107' if score >= 60 else '#F44336'};'>"
                f"{score}/100</span></div>",
                unsafe_allow_html=True
            )
        
        # Format Tips
        if format_tips := results.get('format_tips', []):
            with st.expander("Format Improvement Tips", expanded=True):
                for tip in format_tips:
                    st.markdown(f"- {tip}")
    
    # Detailed Analysis
    st.subheader("Detailed Analysis")
    with st.expander("Strengths", expanded=True):
        for strength in results['strengths']:
            st.markdown(f"- {strength}")
    
    with st.expander("Areas for Improvement", expanded=True):
        for improvement in results['improvements']:
            st.markdown(f"- {improvement}")
    
    # Missing Keywords
    st.subheader("Missing Keywords")
    st.markdown("These keywords are commonly found in job descriptions for your target role but are missing from your resume:")
    missing_keywords = results['missing_keywords']
    if missing_keywords:
        # Display as a table
        keyword_df = pd.DataFrame({
            "Keyword": missing_keywords,
            "Importance": ["High" if i < len(missing_keywords)//3 else 
                         "Medium" if i < 2*len(missing_keywords)//3 else 
                         "Low" for i in range(len(missing_keywords))]
        })
        st.dataframe(keyword_df, use_container_width=True)
    else:
        st.info("Great job! Your resume contains all the important keywords for this role.")
    
    # Advanced Resume Review (when job description is provided)
    if st.session_state.get("job_description"):
        st.subheader("Advanced Resume Review")
        
        # Create tabs for different aspects of the advanced review
        review_tabs = st.tabs(["Skill Gaps", "Experience Gaps", "Enhancement Tips"])
        
        # Skill Gaps tab
        with review_tabs[0]:
            st.markdown("### Skill Gaps")
            st.markdown("These are specific skills mentioned in the job description that are missing from your resume:")
            skill_gaps = results.get('skill_gaps', [])
            if skill_gaps:
                for skill in skill_gaps:
                    st.markdown(f"- {skill}")
            else:
                st.success("Great job! Your resume covers all the key skills mentioned in the job description.")
        
        # Experience Gaps tab
        with review_tabs[1]:
            st.markdown("### Experience Gaps")
            st.markdown("These are experience requirements from the job description that aren't clearly demonstrated in your resume:")
            experience_gaps = results.get('experience_gaps', [])
            if experience_gaps:
                for exp in experience_gaps:
                    st.markdown(f"- {exp}")
            else:
                st.success("Your experience appears to match the job requirements well!")
        
        # Enhancement Tips tab
        with review_tabs[2]:
            st.markdown("### Resume Enhancement Tips")
            st.markdown("Specific ways to enhance your resume for this exact job:")
            enhancement_tips = results.get('resume_enhancement_tips', [])
            if enhancement_tips:
                for tip in enhancement_tips:
                    st.markdown(f"- {tip}")
    
    # Recommendations
    st.subheader("Recommendations")
    for recommendation in results['recommendations']:
        st.markdown(f"- {recommendation}")
    
    # Action buttons section removed as requested