Parthiban97 commited on
Commit
83e507b
ยท
verified ยท
1 Parent(s): b625cc4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +149 -0
app.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Importing Libraries
2
+ import streamlit as st
3
+ import os
4
+ from PyPDF2 import PdfReader
5
+ import google.generativeai as genai
6
+ from dotenv import load_dotenv
7
+
8
+ # Loading the .env keys
9
+ load_dotenv()
10
+
11
+ # Define functions
12
+ def get_gemini_response(model_id, prompt, pdf_content, input_text):
13
+ model = genai.GenerativeModel(model_id)
14
+ response = model.generate_content([prompt, pdf_content, input_text])
15
+ return response.text
16
+
17
+ def get_pdf_text(pdf_docs):
18
+ text = ""
19
+ for doc in pdf_docs:
20
+ if doc.name.endswith(".pdf"):
21
+ pdf_reader = PdfReader(doc)
22
+ for page in pdf_reader.pages:
23
+ text += page.extract_text()
24
+ elif doc.name.endswith(".docx"):
25
+ try:
26
+ import docx
27
+ doc_reader = docx.Document(doc)
28
+ for para in doc_reader.paragraphs:
29
+ text += para.text + "\n"
30
+ except ImportError:
31
+ st.error("Please make sure you have installed the `python-docx` package.")
32
+ return text
33
+
34
+ # Define input prompts
35
+ input_prompts = {
36
+ "evaluate_resume": """
37
+ You are an experienced Technical Human Resource Manager,your task is to review the provided resume against the job description.
38
+ Please share your professional evaluation on whether the candidate's profile aligns with the role.
39
+ Highlight the strengths and weaknesses of the applicant in relation to the specified job requirements.
40
+ """,
41
+ "improve_skills": """
42
+ You are an Technical Human Resource Manager with expertise in data science,
43
+ your role is to scrutinize the resume in light of the job description provided.
44
+ Share your insights on the candidate's suitability for the role from an HR perspective.
45
+ Additionally, offer advice on enhancing the candidate's skills and identify areas where improvement is needed.
46
+ """,
47
+ "missing_keywords": """
48
+ You are an skilled ATS (Applicant Tracking System) scanner with a deep understanding of data science and ATS functionality,
49
+ your task is to evaluate the resume against the provided job description. As a Human Resource manager,
50
+ assess the compatibility of the resume with the role. Give me what are the keywords that are missing
51
+ Also, provide recommendations for enhancing the candidate's skills and identify which areas require further development.
52
+ """,
53
+ "percentage_match": """
54
+ You are an skilled ATS (Applicant Tracking System) scanner with a deep understanding of data science and ATS functionality,
55
+ your task is to evaluate the resume against the provided job description. give me the percentage of match if the resume matches
56
+ the job description. First the output should come as percentage and then keywords missing and last final thoughts.
57
+ """,
58
+ "answer_query": """
59
+ You are an experienced Technical Human Resource Manager. Please answer the following query based on the resume and job description provided.
60
+ """
61
+ }
62
+
63
+ # Define model options
64
+ model_options = [
65
+ "models/gemini-1.0-pro",
66
+ "models/gemini-1.0-pro-001",
67
+ "models/gemini-1.0-pro-latest",
68
+ "models/gemini-1.0-pro-vision-latest",
69
+ "models/gemini-1.5-flash-latest",
70
+ "models/gemini-1.5-pro-latest",
71
+ "models/gemini-pro",
72
+ "models/gemini-pro-vision"
73
+ ]
74
+
75
+ # Streamlit App
76
+ st.set_page_config(page_title="Resume Expert System", page_icon=":chart_with_upwards_trend:")
77
+ st.title("Smart ATS System ๐Ÿ’ผ๐Ÿ”")
78
+
79
+ # Sidebar for API key, model selection, and resume uploader
80
+ with st.sidebar:
81
+ st.markdown("[Get your Google API Key](https://aistudio.google.com/app/apikey)")
82
+ api_key = st.text_input("Enter your Google API Key", type="password")
83
+ selected_model = st.selectbox("Select Gemini Model", model_options)
84
+ uploaded_files = st.file_uploader("Upload Your Resume in .PDF or .DOCX format ๐Ÿ“‚", type=["pdf", "docx"], accept_multiple_files=True)
85
+ if uploaded_files is None:
86
+ st.error("Please upload a PDF or DOCX file to proceed.")
87
+
88
+ # Set the API key for genai
89
+ if api_key:
90
+ genai.configure(api_key=api_key)
91
+
92
+ input_text = st.text_area("Paste the Job Description ๐Ÿ“„")
93
+
94
+ # Align buttons in one row
95
+ col1, col2, col3, col4, col5 = st.columns(5)
96
+
97
+ with col1:
98
+ evaluate_resume_btn = st.button("Evaluate Resume")
99
+ with col2:
100
+ improve_skills_btn = st.button("Improve Skills")
101
+ with col3:
102
+ missing_keywords_btn = st.button("Identify Missing Keywords")
103
+ with col4:
104
+ percentage_match_btn = st.button("Calculate Match Percentage")
105
+ with col5:
106
+ answer_query_btn = st.button("Answer My Query")
107
+
108
+ show_error_api_key = False
109
+ show_error_uploaded_files = False
110
+ show_error_input_text = False
111
+
112
+ if evaluate_resume_btn or improve_skills_btn or missing_keywords_btn or percentage_match_btn or answer_query_btn:
113
+ if not api_key:
114
+ show_error_api_key = True
115
+ if not uploaded_files:
116
+ show_error_uploaded_files = True
117
+ if not input_text:
118
+ show_error_input_text = True
119
+
120
+ if not show_error_api_key and not show_error_uploaded_files and not show_error_input_text:
121
+ pdf_content = get_pdf_text(uploaded_files)
122
+
123
+ if evaluate_resume_btn:
124
+ response = get_gemini_response(selected_model, input_prompts["evaluate_resume"], pdf_content, input_text)
125
+ st.subheader("The Response is")
126
+ st.write(response)
127
+ elif improve_skills_btn:
128
+ response = get_gemini_response(selected_model, input_prompts["improve_skills"], pdf_content, input_text)
129
+ st.subheader("The Response is")
130
+ st.write(response)
131
+ elif missing_keywords_btn:
132
+ response = get_gemini_response(selected_model, input_prompts["missing_keywords"], pdf_content, input_text)
133
+ st.subheader("The Response is")
134
+ st.write(response)
135
+ elif percentage_match_btn:
136
+ response = get_gemini_response(selected_model, input_prompts["percentage_match"], pdf_content, input_text)
137
+ st.subheader("The Response is")
138
+ st.write(response)
139
+ elif answer_query_btn:
140
+ response = get_gemini_response(selected_model, input_prompts["answer_query"], pdf_content, input_text)
141
+ st.subheader("The Response is")
142
+ st.write(response)
143
+
144
+ # Display error messages near respective fields
145
+ if show_error_api_key:
146
+ with st.sidebar:
147
+ st.error("Please enter your Google API Key.")
148
+ if show_error_input_text:
149
+ st.error("Please paste the job description to proceed.", icon="๐Ÿ“„")