Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import docx # python-docx for DOCX processing
|
|
| 6 |
import gradio as gr
|
| 7 |
import os
|
| 8 |
from crewai import Agent, Task, Crew
|
| 9 |
-
from crewai_tools import SerperDevTool
|
| 10 |
|
| 11 |
# Ensure environment variables are set
|
| 12 |
openai_key = os.getenv("openaikey")
|
|
@@ -32,8 +32,9 @@ def extract_text_from_docx(file_path):
|
|
| 32 |
doc = docx.Document(file_path)
|
| 33 |
return "\n".join(para.text for para in doc.paragraphs)
|
| 34 |
|
| 35 |
-
def extract_text_from_resume(
|
| 36 |
"""Determines file type and extracts text."""
|
|
|
|
| 37 |
if file_path.endswith(".pdf"):
|
| 38 |
return extract_text_from_pdf(file_path)
|
| 39 |
elif file_path.endswith(".docx"):
|
|
@@ -41,7 +42,6 @@ def extract_text_from_resume(file_path):
|
|
| 41 |
else:
|
| 42 |
return "Unsupported file format."
|
| 43 |
|
| 44 |
-
# Define Agents
|
| 45 |
resume_feedback = Agent(
|
| 46 |
role="Professional Resume Advisor",
|
| 47 |
goal="Give feedback on resumes.",
|
|
@@ -49,6 +49,12 @@ resume_feedback = Agent(
|
|
| 49 |
backstory="Experienced in making resumes stand out."
|
| 50 |
)
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
resume_advisor = Agent(
|
| 53 |
role="Professional Resume Writer",
|
| 54 |
goal="Enhance resumes based on feedback.",
|
|
@@ -56,6 +62,13 @@ resume_advisor = Agent(
|
|
| 56 |
backstory="Expert in refining resumes to highlight key strengths."
|
| 57 |
)
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
search_tool = SerperDevTool()
|
| 60 |
|
| 61 |
job_researcher = Agent(
|
|
@@ -66,62 +79,40 @@ job_researcher = Agent(
|
|
| 66 |
backstory="Skilled in finding job opportunities based on candidate qualifications."
|
| 67 |
)
|
| 68 |
|
| 69 |
-
# Define Tasks
|
| 70 |
-
resume_feedback_task = Task(
|
| 71 |
-
description="Provide detailed feedback on resumes.",
|
| 72 |
-
expected_output="Resume feedback with an overall score.",
|
| 73 |
-
agent=resume_feedback
|
| 74 |
-
)
|
| 75 |
-
|
| 76 |
-
resume_advisor_task = Task(
|
| 77 |
-
description="Rewrite the resume based on feedback.",
|
| 78 |
-
expected_output="Enhanced resume in markdown format.",
|
| 79 |
-
context=[resume_feedback_task],
|
| 80 |
-
agent=resume_advisor
|
| 81 |
-
)
|
| 82 |
-
|
| 83 |
research_task = Task(
|
| 84 |
description="Find 5 relevant jobs based on the resume.",
|
| 85 |
expected_output="List of 5 job openings with links.",
|
| 86 |
agent=job_researcher
|
| 87 |
)
|
| 88 |
|
| 89 |
-
# Crew Setup
|
| 90 |
crew = Crew(
|
| 91 |
agents=[resume_feedback, resume_advisor, job_researcher],
|
| 92 |
tasks=[resume_feedback_task, resume_advisor_task, research_task],
|
| 93 |
verbose=True
|
| 94 |
)
|
| 95 |
|
| 96 |
-
def resume_agent(
|
| 97 |
-
|
| 98 |
-
resume_text = extract_text_from_resume(file_path)
|
| 99 |
-
if "Unsupported" in resume_text:
|
| 100 |
-
return "Invalid file format. Please upload a PDF or DOCX file.", "", ""
|
| 101 |
-
|
| 102 |
result = crew.kickoff(inputs={"resume": resume_text, "location": location})
|
| 103 |
|
| 104 |
-
feedback =
|
| 105 |
-
improved_resume =
|
| 106 |
-
job_roles =
|
| 107 |
|
| 108 |
return feedback, improved_resume, job_roles
|
| 109 |
|
| 110 |
-
# Gradio UI
|
| 111 |
with gr.Blocks() as demo:
|
| 112 |
gr.Markdown("# Resume Feedback and Job Matching Tool")
|
| 113 |
gr.Markdown("*Expected Runtime: 1 Min*")
|
| 114 |
|
| 115 |
-
with gr.
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
improved_resume_output = gr.Markdown()
|
| 124 |
-
job_roles_output = gr.Markdown()
|
| 125 |
|
| 126 |
submit_button.click(
|
| 127 |
lambda: gr.update(value="Processing..."),
|
|
|
|
| 6 |
import gradio as gr
|
| 7 |
import os
|
| 8 |
from crewai import Agent, Task, Crew
|
| 9 |
+
from crewai_tools import SerperDevTool # Ensure it's correctly installed
|
| 10 |
|
| 11 |
# Ensure environment variables are set
|
| 12 |
openai_key = os.getenv("openaikey")
|
|
|
|
| 32 |
doc = docx.Document(file_path)
|
| 33 |
return "\n".join(para.text for para in doc.paragraphs)
|
| 34 |
|
| 35 |
+
def extract_text_from_resume(file):
|
| 36 |
"""Determines file type and extracts text."""
|
| 37 |
+
file_path = file.name if isinstance(file, dict) else file
|
| 38 |
if file_path.endswith(".pdf"):
|
| 39 |
return extract_text_from_pdf(file_path)
|
| 40 |
elif file_path.endswith(".docx"):
|
|
|
|
| 42 |
else:
|
| 43 |
return "Unsupported file format."
|
| 44 |
|
|
|
|
| 45 |
resume_feedback = Agent(
|
| 46 |
role="Professional Resume Advisor",
|
| 47 |
goal="Give feedback on resumes.",
|
|
|
|
| 49 |
backstory="Experienced in making resumes stand out."
|
| 50 |
)
|
| 51 |
|
| 52 |
+
resume_feedback_task = Task(
|
| 53 |
+
description="Provide detailed feedback on resumes.",
|
| 54 |
+
expected_output="Resume feedback with an overall score.",
|
| 55 |
+
agent=resume_feedback
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
resume_advisor = Agent(
|
| 59 |
role="Professional Resume Writer",
|
| 60 |
goal="Enhance resumes based on feedback.",
|
|
|
|
| 62 |
backstory="Expert in refining resumes to highlight key strengths."
|
| 63 |
)
|
| 64 |
|
| 65 |
+
resume_advisor_task = Task(
|
| 66 |
+
description="Rewrite the resume based on feedback.",
|
| 67 |
+
expected_output="Enhanced resume in markdown format.",
|
| 68 |
+
context=[resume_feedback_task],
|
| 69 |
+
agent=resume_advisor
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
search_tool = SerperDevTool()
|
| 73 |
|
| 74 |
job_researcher = Agent(
|
|
|
|
| 79 |
backstory="Skilled in finding job opportunities based on candidate qualifications."
|
| 80 |
)
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
research_task = Task(
|
| 83 |
description="Find 5 relevant jobs based on the resume.",
|
| 84 |
expected_output="List of 5 job openings with links.",
|
| 85 |
agent=job_researcher
|
| 86 |
)
|
| 87 |
|
|
|
|
| 88 |
crew = Crew(
|
| 89 |
agents=[resume_feedback, resume_advisor, job_researcher],
|
| 90 |
tasks=[resume_feedback_task, resume_advisor_task, research_task],
|
| 91 |
verbose=True
|
| 92 |
)
|
| 93 |
|
| 94 |
+
def resume_agent(file, location):
|
| 95 |
+
resume_text = extract_text_from_resume(file)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
result = crew.kickoff(inputs={"resume": resume_text, "location": location})
|
| 97 |
|
| 98 |
+
feedback = resume_feedback_task.output if resume_feedback_task.output else "No feedback available."
|
| 99 |
+
improved_resume = resume_advisor_task.output if resume_advisor_task.output else "No resume improvements available."
|
| 100 |
+
job_roles = research_task.output if research_task.output else "No job listings available."
|
| 101 |
|
| 102 |
return feedback, improved_resume, job_roles
|
| 103 |
|
|
|
|
| 104 |
with gr.Blocks() as demo:
|
| 105 |
gr.Markdown("# Resume Feedback and Job Matching Tool")
|
| 106 |
gr.Markdown("*Expected Runtime: 1 Min*")
|
| 107 |
|
| 108 |
+
with gr.Row():
|
| 109 |
+
resume_upload = gr.File(label="Upload Resume (PDF or DOCX)")
|
| 110 |
+
location_input = gr.Textbox(label="Preferred Location", placeholder="e.g., San Francisco")
|
| 111 |
+
submit_button = gr.Button("Submit")
|
| 112 |
+
|
| 113 |
+
feedback_output = gr.Markdown(label="Resume Feedback")
|
| 114 |
+
improved_resume_output = gr.Markdown(label="Improved Resume")
|
| 115 |
+
job_roles_output = gr.Markdown(label="Relevant Job Roles")
|
|
|
|
|
|
|
| 116 |
|
| 117 |
submit_button.click(
|
| 118 |
lambda: gr.update(value="Processing..."),
|