girishwangikar commited on
Commit
3781bd4
β€’
1 Parent(s): 62df8fe

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +164 -0
app.py ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from groq import Groq
4
+ from PyPDF2 import PdfReader
5
+ from docx import Document
6
+
7
+ GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
8
+ client = Groq(api_key=GROQ_API_KEY)
9
+
10
+ CSS = """
11
+ .duplicate-button {
12
+ margin: auto !important;
13
+ color: white !important;
14
+ background: black !important;
15
+ border-radius: 100vh !important;
16
+ }
17
+ h3, p, h1 {
18
+ text-align: center;
19
+ color: white;
20
+ }
21
+ footer {
22
+ text-align: center;
23
+ padding: 10px;
24
+ width: 100%;
25
+ background-color: rgba(240, 240, 240, 0.8);
26
+ z-index: 1000;
27
+ position: relative;
28
+ margin-top: 10px;
29
+ color: black;
30
+ }
31
+ """
32
+
33
+ FOOTER_TEXT = """
34
+ <footer>
35
+ <p>If you enjoyed the functionality of the app, please leave a like!<br>
36
+ Check out more on <a href="https://www.linkedin.com/in/girish-wangikar/" target="_blank">LinkedIn</a> |
37
+ <a href="https://girishwangikar.github.io/Girish_Wangikar_Portfolio.github.io/" target="_blank">Portfolio</a></p>
38
+ </footer>
39
+ """
40
+
41
+ TITLE = "<h1>πŸ“„πŸ” ATS Resume Analyzer System</h1>"
42
+ PLACEHOLDER = "Chat with AI about your resume and job descriptions..."
43
+
44
+ def extract_text_from_pdf(pdf_file):
45
+ reader = PdfReader(pdf_file)
46
+ text = ""
47
+ for page in reader.pages:
48
+ text += page.extract_text()
49
+ return text
50
+
51
+ def extract_text_from_docx(docx_file):
52
+ doc = Document(docx_file)
53
+ text = ""
54
+ for para in doc.paragraphs:
55
+ text += para.text + "\n"
56
+ return text
57
+
58
+ def generate_response(message: str, history: list, system_prompt: str, temperature: float = 0.5, max_tokens: int = 512):
59
+ conversation = [
60
+ {"role": "system", "content": system_prompt}
61
+ ]
62
+ for prompt, answer in history:
63
+ conversation.extend([
64
+ {"role": "user", "content": prompt},
65
+ {"role": "assistant", "content": answer},
66
+ ])
67
+ conversation.append({"role": "user", "content": message})
68
+
69
+ response = client.chat.completions.create(
70
+ model="llama-3.1-8B-Instant",
71
+ messages=conversation,
72
+ temperature=temperature,
73
+ max_tokens=max_tokens,
74
+ stream=True
75
+ )
76
+
77
+ partial_message = ""
78
+ for chunk in response:
79
+ if chunk.choices[0].delta.content is not None:
80
+ partial_message += chunk.choices[0].delta.content
81
+ yield partial_message
82
+
83
+ def analyze_resume(resume_text, job_description):
84
+ prompt = f"""
85
+ Please analyze the following resume in the context of the job description provided. Strictly check every single line in the job description and analyze the resume for exact matches. Maintain high ATS standards and give scores only to the correct matches. Focus on missing hard skills and soft skills. Provide the following details:
86
+
87
+ 1. The match percentage of the resume to the job description.
88
+ 2. A list of accurate missing keywords.
89
+ 3. Final thoughts on the resume's overall match with the job description in 3 lines.
90
+ 4. Recommendations on how to add the missing keywords and improve the resume in 3-4 points with examples.
91
+
92
+ Job Description: {job_description}
93
+ Resume: {resume_text}
94
+ """
95
+ return generate_response(prompt, [], "You are an expert ATS resume analyzer.")
96
+
97
+ def rephrase_text(text):
98
+ prompt = f"""
99
+ Please rephrase the following text according to ATS standards, including quantifiable measures and improvements where possible. Maintain precise and concise points which will pass ATS screening:
100
+
101
+ Original Text: {text}
102
+ """
103
+ return generate_response(prompt, [], "You are an expert in rephrasing content for ATS optimization.")
104
+
105
+ def clear_conversation():
106
+ return [], None
107
+
108
+ with gr.Blocks(css=CSS, theme="Nymbo/Nymbo_Theme") as demo:
109
+ gr.HTML(TITLE)
110
+
111
+ with gr.Tab("Resume Analyzer"):
112
+ with gr.Row():
113
+ with gr.Column():
114
+ job_description = gr.Textbox(label="Job Description", lines=5)
115
+ resume_file = gr.File(label="Upload Resume (PDF or DOCX)")
116
+ with gr.Column():
117
+ resume_content = gr.Textbox(label="Parsed Resume Content", lines=10)
118
+ analyze_btn = gr.Button("Analyze Resume")
119
+ output = gr.Markdown()
120
+
121
+ with gr.Tab("Content Rephraser"):
122
+ text_to_rephrase = gr.Textbox(label="Text to Rephrase", lines=5)
123
+ rephrase_btn = gr.Button("Rephrase")
124
+ rephrased_output = gr.Markdown()
125
+
126
+ with gr.Accordion("βš™οΈ Parameters", open=False):
127
+ system_prompt = gr.Textbox(
128
+ value="You are a helpful ATS resume expert, specialized in resume analysis and optimization.",
129
+ label="System Prompt",
130
+ )
131
+ temperature = gr.Slider(
132
+ minimum=0, maximum=1, step=0.1, value=0.5, label="Temperature",
133
+ )
134
+ max_tokens = gr.Slider(
135
+ minimum=50, maximum=1024, step=1, value=512, label="Max tokens",
136
+ )
137
+
138
+ def process_resume(file):
139
+ if file is not None:
140
+ file_type = file.name.split('.')[-1].lower()
141
+ if file_type == 'pdf':
142
+ return extract_text_from_pdf(file.name)
143
+ elif file_type == 'docx':
144
+ return extract_text_from_docx(file.name)
145
+ return ""
146
+
147
+ resume_file.upload(process_resume, resume_file, resume_content)
148
+
149
+ analyze_btn.click(
150
+ analyze_resume,
151
+ inputs=[resume_content, job_description],
152
+ outputs=[output]
153
+ )
154
+
155
+ rephrase_btn.click(
156
+ rephrase_text,
157
+ inputs=[text_to_rephrase],
158
+ outputs=[rephrased_output]
159
+ )
160
+
161
+ gr.HTML(FOOTER_TEXT)
162
+
163
+ if __name__ == "__main__":
164
+ demo.launch()