File size: 3,819 Bytes
e336636
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import google.generativeai as genai
import os
import PyPDF2 as pdf
# from dotenv import load_dotenv
import json

# Load environment variables
# load_dotenv()

# Configure Google Generative AI
genai.configure(api_key=os.getenv("API_KEY"))

# Function to get response from Gemini
def get_gemini_response(resume_text, jd):
    input_prompt = f"""
    Act as a skilled ATS (Application Tracking System) evaluator. 
    Your job is to analyze resumes against job descriptions, focusing on software engineering, 
    data science, and related roles. Provide feedback in this **exact JSON structure**:
    {{
        "JD Match": "85%",
        "MissingKeywords": ["keyword1", "keyword2"],
        "Profile Summary": "Summary text"
    }}

    Resume: {resume_text}
    Job Description: {jd}

    Return only JSON data, without extra commentary or formatting.
    """
    model = genai.GenerativeModel("gemini-1.5-pro")
    response = model.generate_content(input_prompt)
    return response.text

# Function to extract text from PDF
def input_pdf_text(uploaded_file):
    reader = pdf.PdfReader(uploaded_file)
    text = ""
    for page in reader.pages:
        text += page.extract_text()
    return text

# Streamlit app UIst.title("GenAI ATS")
st.title("GenAI Application Track System :blue[(ATS)]")
st.text("Know your Resume Score with GenAI ATS")

# Job description input
jd = st.text_area("Paste the Job Description", help="Provide the job description here.")

# Resume upload
uploaded_file = st.file_uploader("Upload Your Resume", type="pdf", help="Please upload your resume as a PDF.")

# Submit button
if st.button("Check Score"):
    if uploaded_file and jd.strip():
        # Extract text from uploaded resume
        resume_text = input_pdf_text(uploaded_file)

        # Get AI response
        response = get_gemini_response(resume_text, jd)

        # Debugging: Log raw response
        # st.write("Raw AI Response:", response)

        try:
            # Preprocess response to remove backticks or non-JSON content
            cleaned_response = response.strip().strip('```json').strip('```').strip()

            # Parse the cleaned AI response
            response_data = json.loads(cleaned_response)
            jd_match = int(response_data["JD Match"].strip('%'))
            missing_keywords = response_data["MissingKeywords"]
            profile_summary = response_data["Profile Summary"]

            # Display results
            st.subheader("Analysis Results")
            
            # Match score as circular progress graph
            st.write("#### JD Match Score")
            st.progress(jd_match / 100)
            st.write(f":blue[Match Score: **{jd_match}%**]")  # Display percentage value

            # Missing keywords as buttons
            st.write("### Missing Keywords")
            if missing_keywords:
                # Create a row of columns with a maximum of 3 buttons per row
                num_columns = 3
                cols = st.columns(num_columns)
                for i, keyword in enumerate(missing_keywords):
                    col_idx = i % num_columns  # Determine which column to place the keyword in
                    with cols[col_idx]:
                        st.markdown(f"<span style='color: orange;'>{keyword}</span>", unsafe_allow_html=True)
            else:
                st.write("No missing keywords detected!")

            # Profile summary
            st.write("### Profile Summary")
            st.text(profile_summary)

        except json.JSONDecodeError as e:
            st.error("Failed to process the response. Please try again.")
            st.write("Error Details:", str(e))
            st.write("Raw AI Response:", response)
    else:
        st.warning("Please upload a resume and provide a job description.")