Sharath1036 commited on
Commit
8be5e15
·
1 Parent(s): 939745d

added langsmith tracing

Browse files
Files changed (6) hide show
  1. .github/workflows/cicd.yml +20 -0
  2. .gitignore +3 -0
  3. Dockerfile +3 -3
  4. app.py +289 -0
  5. langfuse.sh +6 -0
  6. requirements.txt +9 -3
.github/workflows/cicd.yml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face hub
2
+ on:
3
+ push:
4
+ branches: [main]
5
+
6
+ # to run this workflow manually from the Actions tab
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ sync-to-hub:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ with:
15
+ fetch-depth: 0
16
+ lfs: true
17
+ - name: Push to hub
18
+ env:
19
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
20
+ run: git push --force https://Sharath1036:$HF_TOKEN@huggingface.co/spaces/Sharath1036/resume-ats main
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ myenv/
2
+ __pycache__
3
+ .env
Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM python:3.9-slim
2
 
3
  WORKDIR /app
4
 
@@ -10,7 +10,7 @@ RUN apt-get update && apt-get install -y \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
  COPY requirements.txt ./
13
- COPY src/ ./src/
14
 
15
  RUN pip3 install -r requirements.txt
16
 
@@ -18,4 +18,4 @@ EXPOSE 8501
18
 
19
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
20
 
21
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
1
+ FROM python:3.11-slim
2
 
3
  WORKDIR /app
4
 
 
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
  COPY requirements.txt ./
13
+ COPY . .
14
 
15
  RUN pip3 install -r requirements.txt
16
 
 
18
 
19
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
20
 
21
+ ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
app.py ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ from groq import Groq
4
+ from PyPDF2 import PdfReader
5
+ from langchain_groq import ChatGroq
6
+ from docx import Document
7
+ from dotenv import load_dotenv
8
+ from langsmith import traceable
9
+
10
+ load_dotenv(override=True)
11
+ os.environ['GROQ_API_KEY'] = os.getenv("GROQ_API_KEY")
12
+ os.environ['LANGSMITH_API_KEY'] = os.getenv("LANGSMITH_API_KEY")
13
+ os.environ['LANGSMITH_TRACING'] = "true"
14
+ os.environ['LANGSMITH_PROJECT'] = "resume-ats"
15
+
16
+ CSS = """
17
+ h3, p, h1 {
18
+ text-align: center;
19
+ color: white;
20
+ }
21
+ /* Remove Streamlit's default top padding/margin */
22
+ .block-container {
23
+ padding-top: 1rem !important;
24
+ margin-top: 0 !important;
25
+ }
26
+ """
27
+
28
+ RESUME_ANALYZER_INSTRUCTIONS = """
29
+ <div style="background-color: #000000; color: #ffffff; padding: 10px; border-radius: 5px; margin-bottom: 10px;">
30
+ <p><strong>Instructions:</strong></p>
31
+ <ul>
32
+ <li>Upload your resume (PDF or DOCX) in the file upload area.</li>
33
+ <li>If you want to analyze your resume against a specific job description, keep the checkbox checked and enter the job description in the text box.</li>
34
+ <li>If you want a general resume analysis without a job description, uncheck the "Analyze with Job Description" box.</li>
35
+ <li>Click "Analyze Resume" to get your results.</li>
36
+ </ul>
37
+ </div>
38
+ """
39
+
40
+ COVER_LETTER_INSTRUCTIONS = """
41
+ <div style="background-color: #000000; color: #ffffff; padding: 10px; border-radius: 5px; margin-bottom: 10px;">
42
+ <p><strong>Instructions for Cover Letter Generation:</strong></p>
43
+ <ol>
44
+ <li>First, go to the "Resume Analyzer" tab.</li>
45
+ <li>Upload your resume and enter the job description there.</li>
46
+ <li>Then, come back to this tab and click "Generate Cover Letter".</li>
47
+ </ol>
48
+ </div>
49
+ """
50
+
51
+ INTERVIEW_QUESTIONS_INSTRUCTIONS = """
52
+ <div style="background-color: #000000; color: #ffffff; padding: 10px; border-radius: 5px; margin-bottom: 10px;">
53
+ <p><strong>Instructions for Interview Questions Generation:</strong></p>
54
+ <p>Enter the job description in the text box below and click "Generate Interview Questions".</p>
55
+ </div>
56
+ """
57
+
58
+ # Also update the disclaimer styles to match
59
+ COVER_LETTER_DISCLAIMER = """
60
+ <p style="font-style: italic; color: #cccccc; background-color: #000000; padding: 10px; border-radius: 5px;">
61
+ Disclaimer: This cover letter is generated based on the provided job description and resume.
62
+ It should be carefully reviewed and tailored to your specific needs and the company's requirements before use.
63
+ </p>
64
+ """
65
+
66
+ INTERVIEW_QUESTIONS_DISCLAIMER = """
67
+ <p style="font-style: italic; color: #cccccc; background-color: #000000; padding: 10px; border-radius: 5px;">
68
+ Disclaimer: These interview questions are generated based on the provided job description.
69
+ They should be reviewed and adjusted to better fit the specific role, company culture, and interview process.
70
+ </p>
71
+ """
72
+
73
+ TITLE = "<h1>📄 ATS Resume Analyzer 📄</h1>"
74
+ PLACEHOLDER = "Chat with AI about your resume and job descriptions..."
75
+
76
+ def extract_text_from_pdf(pdf_file):
77
+ reader = PdfReader(pdf_file)
78
+ text = ""
79
+ for page in reader.pages:
80
+ text += page.extract_text()
81
+ return text
82
+
83
+ def extract_text_from_docx(docx_file):
84
+ doc = Document(docx_file)
85
+ text = ""
86
+ for para in doc.paragraphs:
87
+ text += para.text + "\n"
88
+ return text
89
+
90
+ @traceable(run_type="llm")
91
+ def generate_response(message: str, system_prompt: str, temperature: float, max_tokens: int):
92
+ messages = [
93
+ ("system", system_prompt),
94
+ ("human", message),
95
+ ]
96
+
97
+ model="llama-3.3-70b-versatile"
98
+
99
+ response = ChatGroq(
100
+ model=model,
101
+ temperature=0.0,
102
+ max_retries=2,
103
+ )
104
+ result = response.invoke(messages)
105
+ # If result is a dict with 'content', return only the content
106
+ if isinstance(result, dict) and 'content' in result:
107
+ return result['content']
108
+ # If result is an object with a 'content' attribute, return it
109
+ if hasattr(result, 'content'):
110
+ return result.content
111
+ # Otherwise, return as is
112
+ return result
113
+
114
+
115
+ def analyze_resume_with_job_description(resume_text, job_description, temperature, max_tokens):
116
+ prompt = f"""
117
+ 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 core skills and soft skills. Provide the following details:
118
+ 1. The match percentage of the resume to the job description.
119
+ 2. A list of missing keywords.
120
+ 3. Final thoughts on the resume's overall match with the job description in 3 lines.
121
+ 4. Recommendations on how to add the missing keywords and improve the resume in 3-4 points with examples.
122
+ Job Description: {job_description}
123
+ Resume: {resume_text}
124
+ """
125
+ return generate_response(prompt, "You are an expert ATS resume analyzer.", temperature, max_tokens)
126
+
127
+ def analyze_resume_without_job_description(resume_text, temperature, max_tokens):
128
+ prompt = f"""
129
+ Please analyze the following resume without a specific job description. Provide the following details:
130
+ 1. An overall score out of 10 for the resume.
131
+ 2. Suggestions for improvements based on the following criteria:
132
+ - Impact (quantification, repetition, verb usage, tenses, responsibilities, spelling & consistency)
133
+ - Brevity (length, bullet points, filler words)
134
+ - Style (buzzwords, dates, contact details, personal pronouns, active voice, consistency)
135
+ - Sections (summary, education, skills, unnecessary sections)
136
+ 3. A cumulative assessment of all the above fields.
137
+ 4. Recommendations for improving the resume in 3-4 points with examples.
138
+
139
+ Resume: {resume_text}
140
+ """
141
+ return generate_response(prompt, "You are an expert ATS resume analyzer.", temperature, max_tokens)
142
+
143
+
144
+ def analyze_resume(resume_text, job_description, with_job_description, temperature, max_tokens):
145
+ if with_job_description:
146
+ return analyze_resume_with_job_description(resume_text, job_description, temperature, max_tokens)
147
+ else:
148
+ return analyze_resume_without_job_description(resume_text, temperature, max_tokens)
149
+
150
+
151
+
152
+ def rephrase_text(text, temperature, max_tokens):
153
+ prompt = f"""
154
+ 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:
155
+ Original Text: {text}
156
+ """
157
+ return generate_response(prompt, "You are an expert in rephrasing content for ATS optimization.", temperature, max_tokens)
158
+
159
+ def clear_conversation():
160
+ return [], None
161
+
162
+
163
+ def generate_cover_letter(resume_text, job_description, temperature, max_tokens):
164
+ prompt = f"""
165
+ Using the provided resume and job description, create a compelling cover letter. The cover letter should:
166
+ 1. Be tailored to the specific job and company.
167
+ 2. Highlight relevant skills and experiences from the resume.
168
+ 3. Show enthusiasm for the role and company.
169
+ 4. Be professional and concise (about 250-300 words).
170
+
171
+ Resume: {resume_text}
172
+ Job Description: {job_description}
173
+ """
174
+ return generate_response(prompt, "You are an expert in writing tailored cover letters.", temperature, max_tokens)
175
+
176
+ def generate_interview_questions(job_description, temperature, max_tokens):
177
+ prompt = f"""
178
+ Based on the following job description, generate a list of 10 probable interview questions. Include a mix of:
179
+ 1. Role-specific technical questions (if applicable)
180
+ 2. Behavioral questions related to the required skills
181
+ 3. Questions about the candidate's experience and background
182
+ 4. Questions to assess cultural fit
183
+
184
+ Ensure the questions are tailored to the specific job role and requirements.
185
+
186
+ Job Description: {job_description}
187
+ """
188
+ return generate_response(prompt, "You are an expert in creating relevant interview questions based on job descriptions.", temperature, max_tokens)
189
+
190
+
191
+ def main():
192
+ st.set_page_config(page_title="ATS Resume Analyzer", layout="wide")
193
+ st.markdown(f"<style>{CSS}</style>", unsafe_allow_html=True)
194
+ st.markdown(f"<h1 style='text-align:center;color:white;'>{TITLE}</h1>", unsafe_allow_html=True)
195
+ tab1, tab2, tab3, tab4 = st.tabs([
196
+ "Resume Analyzer",
197
+ "Content Rephraser",
198
+ "Cover Letter Generator",
199
+ "Interview Questions Generator"
200
+ ])
201
+
202
+ with tab1:
203
+ st.markdown(RESUME_ANALYZER_INSTRUCTIONS, unsafe_allow_html=True)
204
+ col1, col2 = st.columns(2)
205
+ with col1:
206
+ with_job_description = st.checkbox(
207
+ "Analyze with Job Description",
208
+ value=True,
209
+ help="Uncheck this box for a general resume analysis without a specific job description."
210
+ )
211
+ job_description = ""
212
+ if with_job_description:
213
+ job_description = st.text_area("Job Description", height=120)
214
+ resume_file = st.file_uploader("Upload Resume (PDF or DOCX)", type=["pdf", "docx"])
215
+
216
+ # Handle resume content upload and display
217
+ if resume_file is not None:
218
+ file_type = resume_file.name.split('.')[-1].lower()
219
+ if file_type == 'pdf':
220
+ uploaded_text = extract_text_from_pdf(resume_file)
221
+ elif file_type == 'docx':
222
+ uploaded_text = extract_text_from_docx(resume_file)
223
+ else:
224
+ uploaded_text = ""
225
+ st.session_state["resume_content_uploaded"] = uploaded_text
226
+ st.session_state["resume_content"] = uploaded_text # Always update the editable text area
227
+
228
+ # Default resume_content if not set
229
+ if "resume_content" not in st.session_state:
230
+ st.session_state["resume_content"] = ""
231
+
232
+
233
+ with col2:
234
+ resume_content = st.text_area("Parsed Resume Content", height=250, key="resume_content")
235
+
236
+ # # Always keep resume_content_display in sync for read-only display
237
+ # st.text_area("Parsed Resume Content", value=st.session_state["resume_content"], height=250, key="resume_content_display", disabled=True)
238
+
239
+ temperature = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.5, step=0.1, key="temp1")
240
+ max_tokens = st.slider("Max tokens", min_value=50, max_value=1024, value=1024, step=1, key="max_tokens1")
241
+
242
+ if st.button("Analyze Resume"):
243
+ with st.spinner("Analyzing resume..."):
244
+ result = analyze_resume(
245
+ st.session_state["resume_content"],
246
+ job_description,
247
+ with_job_description,
248
+ temperature,
249
+ max_tokens
250
+ )
251
+ st.markdown(result)
252
+
253
+ with tab2:
254
+ st.markdown("<div style='margin-bottom:10px'></div>", unsafe_allow_html=True)
255
+ text_to_rephrase = st.text_area("Text to Rephrase", height=120)
256
+ temperature2 = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.5, step=0.1, key="temp2")
257
+ max_tokens2 = st.slider("Max tokens", min_value=50, max_value=1024, value=1024, step=1, key="max_tokens2")
258
+ if st.button("Rephrase"):
259
+ with st.spinner("Rephrasing text..."):
260
+ rephrased = rephrase_text(text_to_rephrase, temperature2, max_tokens2)
261
+ st.markdown(rephrased)
262
+
263
+ with tab3:
264
+ st.markdown(COVER_LETTER_INSTRUCTIONS, unsafe_allow_html=True)
265
+ st.markdown(COVER_LETTER_DISCLAIMER, unsafe_allow_html=True)
266
+ temperature3 = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.5, step=0.1, key="temp3")
267
+ max_tokens3 = st.slider("Max tokens", min_value=50, max_value=1024, value=1024, step=1, key="max_tokens3")
268
+ if st.button("Generate Cover Letter"):
269
+ with st.spinner("Generating cover letter..."):
270
+ resume_text = st.session_state.get("resume_content", "")
271
+ job_desc = st.session_state.get("job_description", "") if with_job_description else ""
272
+ if not job_desc:
273
+ job_desc = st.text_area("Job Description", height=120, key="cl_job_desc")
274
+ result = generate_cover_letter(resume_text, job_desc, temperature3, max_tokens3)
275
+ st.markdown(result)
276
+
277
+ with tab4:
278
+ st.markdown(INTERVIEW_QUESTIONS_INSTRUCTIONS, unsafe_allow_html=True)
279
+ st.markdown(INTERVIEW_QUESTIONS_DISCLAIMER, unsafe_allow_html=True)
280
+ interview_job_description = st.text_area("Job Description for Interview Questions", height=120)
281
+ temperature4 = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.5, step=0.1, key="temp4")
282
+ max_tokens4 = st.slider("Max tokens", min_value=50, max_value=1024, value=1024, step=1, key="max_tokens4")
283
+ if st.button("Generate Interview Questions"):
284
+ with st.spinner("Generating interview questions..."):
285
+ result = generate_interview_questions(interview_job_description, temperature4, max_tokens4)
286
+ st.markdown(result)
287
+
288
+ if __name__ == "__main__":
289
+ main()
langfuse.sh ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ wsl -d Ubuntu
2
+ screen -S server
3
+ cd /mnt/d/Sharath/github-repos/langfuse
4
+ docker-compose up -d
5
+
6
+ gradio app.py
requirements.txt CHANGED
@@ -1,3 +1,9 @@
1
- altair
2
- pandas
3
- streamlit
 
 
 
 
 
 
 
1
+ streamlit
2
+ groq
3
+ PyPDF2
4
+ python-docx
5
+ python-dotenv
6
+ langchain
7
+ langchain-community
8
+ langchain-groq
9
+ langsmith