MuhammadQASIM111 commited on
Commit
15d927b
·
verified ·
1 Parent(s): bc20c39

Delete app (1).py

Browse files
Files changed (1) hide show
  1. app (1).py +0 -180
app (1).py DELETED
@@ -1,180 +0,0 @@
1
- # Warning control
2
- import warnings
3
- warnings.filterwarnings('ignore')
4
-
5
-
6
- import fitz # PyMuPDF for PDF processing
7
- import docx # python-docx for DOCX processing
8
- import gradio as gr
9
- import os
10
- from crewai import Agent, Task, Crew
11
- from crewai_tools import SerperDevTool
12
-
13
-
14
- os.environ['OPENAI_API_KEY'] = os.getenv("openaikey")
15
- os.environ["OPENAI_MODEL_NAME"] = 'gpt-4o-mini'
16
- os.environ["SERPER_API_KEY"] = os.getenv("serper_key")
17
-
18
-
19
-
20
- def extract_text_from_pdf(file_path):
21
- """Extracts text from a PDF file using PyMuPDF."""
22
- doc = fitz.open(file_path)
23
- text = ""
24
- for page in doc:
25
- text += page.get_text()
26
- return text
27
-
28
- def extract_text_from_docx(file_path):
29
- """Extracts text from a DOCX file using python-docx."""
30
- doc = docx.Document(file_path)
31
- fullText = []
32
- for para in doc.paragraphs:
33
- fullText.append(para.text)
34
- return "\n".join(fullText)
35
-
36
- def extract_text_from_resume(file_path):
37
- """Determines file type and extracts text."""
38
- if file_path.endswith(".pdf"):
39
- return extract_text_from_pdf(file_path)
40
- elif file_path.endswith(".docx"):
41
- return extract_text_from_docx(file_path)
42
- else:
43
- return "Unsupported file format."
44
-
45
-
46
-
47
- # Agent 1: Resume Strategist
48
- resume_feedback = Agent(
49
- role="Professional Resume Advisor",
50
- goal="Give feedback on the resume to make it stand out in the job market.",
51
- verbose=True,
52
- backstory="With a strategic mind and an eye for detail, you excel at providing feedback on resumes to highlight the most relevant skills and experiences."
53
- )
54
-
55
-
56
- # Task for Resume Strategist Agent: Align Resume with Job Requirements
57
- resume_feedback_task = Task(
58
- description=(
59
- """Give feedback on the resume to make it stand out for recruiters.
60
- Review every section, inlcuding the summary, work experience, skills, and education. Suggest to add relevant sections if they are missing.
61
- Also give an overall score to the resume out of 10. This is the resume: {resume}"""
62
- ),
63
- expected_output="The overall score of the resume followed by the feedback in bullet points.",
64
- agent=resume_feedback
65
- )
66
-
67
- # Agent 2: Resume Strategist
68
- resume_advisor = Agent(
69
- role="Professional Resume Writer",
70
- goal="Based on the feedback recieved from Resume Advisor, make changes to the resume to make it stand out in the job market.",
71
- verbose=True,
72
- backstory="With a strategic mind and an eye for detail, you excel at refining resumes based on the feedback to highlight the most relevant skills and experiences."
73
- )
74
-
75
- # Task for Resume Strategist Agent: Align Resume with Job Requirements
76
- resume_advisor_task = Task(
77
- description=(
78
- """Rewrite the resume based on the feedback to make it stand out for recruiters. You can adjust and enhance the resume but don't make up facts.
79
- Review and update every section, including the summary, work experience, skills, and education to better reflect the candidates abilities. This is the resume: {resume}"""
80
- ),
81
- expected_output= "Resume in markdown format that effectively highlights the candidate's qualifications and experiences",
82
- # output_file="improved_resume.md",
83
- context=[resume_feedback_task],
84
- agent=resume_advisor
85
- )
86
-
87
- search_tool = SerperDevTool()
88
-
89
-
90
- # Agent 3: Researcher
91
- job_researcher = Agent(
92
- role = "Senior Recruitment Consultant",
93
- goal = "Find the 5 most relevant, recently posted jobs based on the improved resume recieved from resume advisor and the location preference",
94
- tools = [search_tool],
95
- verbose = True,
96
- backstory = """As a senior recruitment consultant your prowess in finding the most relevant jobs based on the resume and location preference is unmatched.
97
- You can scan the resume efficiently, identify the most suitable job roles and search for the best suited recently posted open job positions at the preffered location."""
98
- )
99
-
100
- research_task = Task(
101
- description = """Find the 5 most relevant recent job postings based on the resume recieved from resume advisor and location preference. This is the preferred location: {location} .
102
- Use the tools to gather relevant content and shortlist the 5 most relevant, recent, job openings""",
103
- expected_output=(
104
- "A bullet point list of the 5 job openings, with the appropriate links and detailed description about each job, in markdown format"
105
- ),
106
- # output_file="relevant_jobs.md",
107
- agent=job_researcher
108
- )
109
-
110
-
111
- crew = Crew(
112
- agents=[resume_feedback, resume_advisor, job_researcher],
113
- tasks=[resume_feedback_task, resume_advisor_task, research_task],
114
- verbose=True
115
- )
116
-
117
-
118
-
119
- def resume_agent(file_path, location):
120
- resume_text = extract_text_from_resume(file_path)
121
-
122
- result = crew.kickoff(inputs={"resume": resume_text, "location": location})
123
-
124
- # Extract outputs
125
- feedback = resume_feedback_task.output.raw.strip("```markdown").strip("```").strip()
126
- improved_resume = resume_advisor_task.output.raw.strip("```markdown").strip("```").strip()
127
- job_roles = research_task.output.raw.strip("```markdown").strip("```").strip()
128
-
129
- return feedback, improved_resume, job_roles
130
-
131
-
132
- # Gradio Interface
133
- with gr.Blocks() as demo:
134
- gr.Markdown("# Resume Feedback and Job Matching Tool")
135
- gr.Markdown("*Expected Runtime: 1 Min*")
136
-
137
- with gr.Column():
138
- with gr.Row():
139
- resume_upload = gr.File(label="Upload Your Resume (PDF or DOCX)", height=120)
140
- location_input = gr.Textbox(label="Preferred Location", placeholder="e.g., San Francisco")
141
- submit_button = gr.Button("Submit")
142
-
143
- with gr.Column():
144
- feedback_output = gr.Markdown(label="Resume Feedback")
145
- improved_resume_output = gr.Markdown(label="Improved Resume")
146
- job_roles_output = gr.Markdown(label="Relevant Job Roles")
147
-
148
- # Define the click event for the submit button
149
- def format_outputs(feedback, improved_resume, job_roles):
150
- # Add bold headings to each section
151
- feedback_with_heading = f"## Resume Feedback:**\n\n{feedback}"
152
- improved_resume_with_heading = f"## Improved Resume:\n\n{improved_resume}"
153
- job_roles_with_heading = f"## Relevant Job Roles:\n\n{job_roles}"
154
- return feedback_with_heading, improved_resume_with_heading, job_roles_with_heading
155
-
156
-
157
-
158
- submit_button.click(
159
- lambda: gr.update(value="Processing..."),
160
- inputs=[],
161
- outputs=submit_button
162
- ).then(
163
- resume_agent,
164
- inputs=[resume_upload, location_input],
165
- outputs=[feedback_output, improved_resume_output, job_roles_output]
166
- ).then(
167
- format_outputs,
168
- inputs=[feedback_output, improved_resume_output, job_roles_output],
169
- outputs=[feedback_output, improved_resume_output, job_roles_output]
170
- ).then(
171
- lambda: gr.update(value="Submit"),
172
- inputs=[],
173
- outputs=submit_button
174
- )
175
-
176
- demo.queue()
177
- demo.launch()
178
-
179
-
180
-