Spaces:
Sleeping
Sleeping
Update app.py
Browse filesUpdated to include pdf upload of resume
app.py
CHANGED
@@ -1,83 +1,93 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
3 |
|
4 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
4. Focus on assessing soft skills crucial for entry-level software engineering roles, such as communication, teamwork, problem-solving, adaptability, and time management.
|
14 |
-
5. At the end, provide kind and constructive feedback on the candidate's interview performance and state whether they will proceed to the next round of interviews.
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
- Ask for more details when answers are vague or insufficient.
|
20 |
-
- Transition smoothly between different topics or competencies.
|
21 |
-
- If the resume lacks relevant experiences for a particular question, adapt the question to the candidate's background or ask about hypothetical scenarios.
|
22 |
|
23 |
-
|
24 |
-
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
- Focus on behavioral aspects and soft skills
|
29 |
-
- Ask follow-up questions for clarity or depth
|
30 |
-
- Transition smoothly to the next topic
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
|
38 |
-
"""
|
39 |
|
40 |
-
def
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
temperature,
|
45 |
-
top_p,
|
46 |
-
):
|
47 |
-
messages = [{"role": "system", "content": INTERVIEWER_PROMPT}]
|
48 |
-
for user, assistant in history:
|
49 |
-
messages.append({"role": "user", "content": user})
|
50 |
-
messages.append({"role": "assistant", "content": assistant})
|
51 |
-
messages.append({"role": "user", "content": message})
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
messages,
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
minimum=0.1,
|
72 |
-
maximum=1.0,
|
73 |
-
value=0.95,
|
74 |
-
step=0.05,
|
75 |
-
label="Top-p (nucleus sampling)",
|
76 |
-
),
|
77 |
-
],
|
78 |
-
title="Job Interview Simulator with Alex",
|
79 |
-
description="I'm Alex, your job interviewer today. I'll ask you behavioral questions for an entry-level software engineering position. Let's begin!",
|
80 |
-
)
|
81 |
|
82 |
-
|
83 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
import PyPDF2
|
4 |
+
import io
|
5 |
|
6 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
7 |
|
8 |
+
def pdf_to_text(pdf_file):
|
9 |
+
text = ""
|
10 |
+
pdf_reader = PyPDF2.PdfReader(io.BytesIO(pdf_file))
|
11 |
+
for page in pdf_reader.pages:
|
12 |
+
text += page.extract_text() + "\n"
|
13 |
+
return text
|
14 |
|
15 |
+
def update_resume(pdf_file):
|
16 |
+
if pdf_file is not None:
|
17 |
+
return pdf_to_text(pdf_file)
|
18 |
+
return ""
|
|
|
|
|
19 |
|
20 |
+
def get_system_prompt(resume, job_description):
|
21 |
+
return f"""
|
22 |
+
You are an AI job interviewer. You have the candidate's resume and the job description:
|
|
|
|
|
|
|
23 |
|
24 |
+
Resume:
|
25 |
+
{resume}
|
26 |
|
27 |
+
Job Description:
|
28 |
+
{job_description}
|
|
|
|
|
|
|
29 |
|
30 |
+
Your task is to conduct a job interview by asking relevant behavioral and technical questions based on the candidate's resume and the job requirements. Follow these guidelines:
|
31 |
+
1. Ask one question at a time.
|
32 |
+
2. Start with a question directly related to the candidate's experience or skills mentioned in their resume.
|
33 |
+
3. In subsequent questions, alternate between resume-based questions and job description-based questions.
|
34 |
+
4. Make your questions specific and varied. Do not repeat questions.
|
35 |
+
5. After each candidate response, briefly acknowledge their answer before asking the next question.
|
36 |
+
6. Do not provide feedback on their answers or make hiring decisions.
|
37 |
+
7. Phrase your questions in a professional and courteous manner.
|
38 |
|
39 |
+
Begin the interview with a question based on the candidate's resume.
|
40 |
+
"""
|
41 |
|
42 |
+
def generate_question(history, resume, job_description):
|
43 |
+
messages = [
|
44 |
+
{"role": "system", "content": get_system_prompt(resume, job_description)},
|
45 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
+
for human, ai in history:
|
48 |
+
messages.append({"role": "user", "content": human})
|
49 |
+
messages.append({"role": "assistant", "content": ai})
|
50 |
+
|
51 |
+
if not history:
|
52 |
+
messages.append({"role": "user", "content": "Please start the interview with the first question based on my resume."})
|
53 |
+
else:
|
54 |
+
messages.append({"role": "user", "content": "Thank you for that response. Please ask the next interview question, considering my resume and the job requirements."})
|
55 |
+
|
56 |
+
response = client.chat_completion(messages, max_tokens=150, temperature=0.7)
|
57 |
+
return response.choices[0].message.content
|
58 |
+
|
59 |
+
def respond(message, history, resume, job_description):
|
60 |
+
return generate_question(history, resume, job_description)
|
61 |
+
|
62 |
+
with gr.Blocks() as demo:
|
63 |
+
gr.Markdown("# AI Job Interview Simulator")
|
64 |
+
gr.Markdown("Upload your resume and provide the job description to start a personalized interview.")
|
65 |
+
|
66 |
+
with gr.Row():
|
67 |
+
with gr.Column(scale=1):
|
68 |
+
pdf_input = gr.File(label="Upload Resume (PDF only)", file_types=[".pdf"])
|
69 |
+
resume_text = gr.Textbox(lines=10, label="Extracted Resume Text", interactive=True)
|
70 |
+
job_description = gr.Textbox(lines=10, label="Job Description")
|
71 |
+
|
72 |
+
with gr.Column(scale=2):
|
73 |
+
chatbot = gr.Chatbot(label="Interview Session")
|
74 |
+
|
75 |
+
message = gr.Textbox(label="Your response")
|
76 |
+
|
77 |
+
pdf_input.upload(fn=update_resume, inputs=[pdf_input], outputs=[resume_text])
|
78 |
+
|
79 |
+
submit = gr.Button("Submit Response")
|
80 |
+
submit.click(
|
81 |
+
fn=respond,
|
82 |
+
inputs=[message, chatbot, resume_text, job_description],
|
83 |
+
outputs=[chatbot, message]
|
84 |
+
)
|
85 |
|
86 |
+
gr.Markdown("## Instructions:")
|
87 |
+
gr.Markdown("1. Upload your resume as a PDF file.")
|
88 |
+
gr.Markdown("2. Review and edit the extracted text if necessary.")
|
89 |
+
gr.Markdown("3. Paste the job description.")
|
90 |
+
gr.Markdown("4. Click 'Submit Response' to start the interview or answer questions.")
|
91 |
+
gr.Markdown("5. Respond to each question in the 'Your response' box.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
+
demo.launch()
|
|