File size: 7,322 Bytes
af06f03
e6f3be5
00fa330
af06f03
7e618b5
 
 
 
1564347
7e618b5
af06f03
7e618b5
 
 
00fa330
b196e5a
7e618b5
 
 
2aacd56
7e618b5
 
 
 
 
 
 
c81bb04
7e618b5
2aacd56
b15e05b
7e618b5
 
 
 
 
 
 
 
 
 
 
 
 
df122f4
00fa330
6fb0686
b196e5a
e6f3be5
7e618b5
e6f3be5
 
 
 
af35711
e6f3be5
 
 
 
 
 
 
 
 
 
 
 
af35711
 
7e618b5
af35711
7e618b5
af35711
7e618b5
e6f3be5
7e618b5
 
 
00fa330
4463d9f
 
7e618b5
 
4463d9f
7e618b5
 
e6f3be5
 
 
 
af35711
 
 
e6f3be5
 
 
7e618b5
 
 
 
 
 
 
6fb0686
7e618b5
 
 
 
 
 
 
 
 
 
5daceab
 
 
 
 
 
 
 
 
b2ed45a
5daceab
b2ed45a
5daceab
 
 
 
 
 
 
 
 
e2b4eda
c81bb04
ce299a7
c81bb04
7e618b5
 
 
5daceab
 
 
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
from sentence_transformers import SentenceTransformer
import streamlit as st
import pandas as pd
from PyPDF2 import PdfReader
from sklearn.metrics.pairwise import cosine_similarity
from gliner import GLiNER
import plotly.express as px
import time
import numpy as np 


with st.sidebar:
    st.button("DEMO APP", type="primary")
   

    expander = st.expander("**Important notes on the AI Resume Analysis based on Sentence Similarity App**")
    expander.write('''
    
    
    **Supported File Formats**
    This app accepts files in .pdf formats.
    
    **How to Use**
    Paste the job description first. Then, upload the resume of each applicant to retrieve the results.  
    
    **Usage Limits**
    For each applicant you can upload their resume and request results once (1 request per applicant's resume).
    At the bottom of the app, you can also upload an applicant's resume once (1 request) to visualize their profile as a treemap chart. If you hover over the interactive graph, an icon will appear to download it.
    
    **Subscription Management**
    This demo app offers a one-day subscription, expiring after 24 hours. If you are interested in building your own AI Resume Analysis based on Sentence Similarity Web App, we invite you to explore our NLP Web App Store on our website. You can select your desired features, place your order, and we will deliver your custom app within five business days. If you wish to delete your Account with us, please contact us at [email protected]
    
    **Customization**
    To change the app's background color to white or black, click the three-dot menu on the right-hand side of your app, go to Settings and then Choose app theme, colors and fonts.
    
    **File Handling and Errors**
    The app may display an error message if your file is corrupt, or has other errors.
    
    
    For any errors or inquiries, please contact us at [email protected]
   
    
    
''')


model = SentenceTransformer("all-MiniLM-L6-v2")
st.title("AI Resume Analysis based on Sentence Similarity App")
st.divider()
job_desc = st.text_area("Paste the job description and then press Ctrl + Enter", key="job_desc")

if 'applicant_data' not in st.session_state:
    st.session_state['applicant_data'] = {}
max_attempts = 1
for i in range(1, 51):  # Looping for 50 applicants
    st.subheader(f"Applicant {i} Resume", divider="green")
    applicant_key = f"applicant_{i}"
    upload_key = f"candidate_{i}"
    if applicant_key not in st.session_state['applicant_data']:
        st.session_state['applicant_data'][applicant_key] = {'upload_count': 0, 'uploaded_file': None, 'analysis_done': False}
    if st.session_state['applicant_data'][applicant_key]['upload_count'] < max_attempts:
        uploaded_file = st.file_uploader(f"Upload Applicant's {i} resume", type="pdf", key=upload_key)
        if uploaded_file:
            st.session_state['applicant_data'][applicant_key]['uploaded_file'] = uploaded_file
            st.session_state['applicant_data'][applicant_key]['upload_count'] += 1
            st.session_state['applicant_data'][applicant_key]['analysis_done'] = False # Reset analysis flag
        if st.session_state['applicant_data'][applicant_key]['uploaded_file'] and not st.session_state['applicant_data'][applicant_key]['analysis_done']:
            try:
                pdf_reader = PdfReader(st.session_state['applicant_data'][applicant_key]['uploaded_file'])
                text_data = ""
                for page in pdf_reader.pages:
                    text_data += page.extract_text()
                with st.expander(f"See Applicant's {i} resume"):
                    st.write(text_data)

                # Encode the job description and resume text separately
                job_embedding = model.encode([job_desc])
                resume_embedding = model.encode([text_data])

                
                

                with st.spinner("Wait for it...", show_time=True):
                    similarity_score = model.similarity(job_embedding, resume_embedding)[0][0]
                    time.sleep(2)

                with st.popover(f"See Result for Applicant {i}"):
                    st.write(f"Similarity between Applicant's resume and job description based on keywords: {similarity_score:.2f}")
                    st.info(
                        f"A score closer to 1 (0.80, 0.90) means higher similarity between Applicant's {i} resume and job description. A score closer to 0 (0.20, 0.30) means lower similarity between Applicant's {i} resume and job description.")
                st.session_state['applicant_data'][applicant_key]['analysis_done'] = True
            except Exception as e:
                st.error(f"An error occurred while processing Applicant {i}'s resume: {e}")
    else:
        st.warning(f"Maximum upload attempts has been reached ({max_attempts}).")
        if st.session_state['applicant_data'][applicant_key]['upload_count'] > 0:
            st.info(f"Files uploaded for Applicant {i}: {st.session_state['applicant_data'][applicant_key]['upload_count']} time(s).")




st.divider()
st.subheader("Visualise", divider="blue")
model = SentenceTransformer("all-MiniLM-L6-v2")

if 'upload_count' not in st.session_state:
    st.session_state['upload_count'] = 0
    max_attempts = 1

if st.session_state['upload_count'] < max_attempts:
    uploaded_files = st.file_uploader("Upload Applicant's resume", type="pdf", key="applicant 1")
    if uploaded_files:
        st.session_state['upload_count'] += 1
        with st.spinner("Wait for it...", show_time=True):
            time.sleep(2)
            pdf_reader = PdfReader(uploaded_files)
            text_data = ""
            for page in pdf_reader.pages:
                text_data += page.extract_text()
            job_desc_series = pd.Series([job_desc], name='Text')  # Convert job_desc to a Series
            data = pd.Series([text_data], name='Text')        # Ensure text_data is also a Series
            frames = [job_desc_series, data]
            result = pd.concat(frames, ignore_index=True)  # Concatenate along rows, reset index
            model1 = GLiNER.from_pretrained("urchade/gliner_base")
            labels = ["person", "country", "organization", "role", "skills"]
            entities = model1.predict_entities(text_data, labels)
            df = pd.DataFrame(entities)
            st.subheader("Applicant's Profile", divider = "orange")
            fig = px.treemap(entities, path=[px.Constant("all"), 'text', 'label'],
                                     values='score', color='label')
            fig.update_layout(margin=dict(t=50, l=25, r=25, b=25))
            st.plotly_chart(fig, key="figure 1")
            job_embedding = model.encode([job_desc])
            resume_embedding = model.encode([text_data])
            similarity_score = model.similarity(job_embedding, resume_embedding)[0][0]
            
            
            st.metric(label="Similarity Score between Applicant's Profile and Job Description", value=f"{similarity_score:.2f}", border=True)
            
else:
    st.warning(f"Maximum upload attempts has been reached ({max_attempts}).")
    if 'upload_count' in st.session_state and st.session_state['upload_count'] > 0:
        st.info(f"Files uploaded {st.session_state['upload_count']} time(s).")