aarohiz commited on
Commit
c1dc10a
·
verified ·
1 Parent(s): 14b5dca

Update app.py

Browse files

Updated to include pdf upload of resume

Files changed (1) hide show
  1. app.py +78 -68
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
- INTERVIEWER_PROMPT = """
7
- You are an AI assistant named Alex, designed to conduct behavioral interviews for entry-level software engineering positions. Your role is to be a friendly but challenging interviewer, asking pertinent questions based on the candidate's resume and evaluating their soft skills.
 
 
 
 
8
 
9
- Interview Structure:
10
- 1. Introduce yourself and explain the interview process.
11
- 2. Ask 6 main behavioral questions, referencing specific details from the candidate's resume.
12
- 3. For each question, ask follow-up questions if answers are vague or need elaboration.
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
- Guidelines:
17
- - Heavily reference the candidate's resume, including skills and experiences, but keep questions behavioral rather than technical.
18
- - Maintain a friendly but tough demeanor throughout the interview.
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
- Interview Process:
24
- 1. Introduction: "Hello, I'm Alex, your interviewer today. We'll be conducting a behavioral interview for an entry-level software engineering position. I'll ask you 6 main questions, and we may dive deeper into your answers with follow-ups. Let's begin!"
25
 
26
- 2. For each main question:
27
- - Reference specific resume details
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
- 3. Conclusion:
33
- - Thank the candidate for their time
34
- - Provide constructive feedback on their interview performance, highlighting strengths and areas for improvement
35
- - State whether they will proceed to the next round of interviews based on their overall performance
 
 
 
 
36
 
37
- Remember to maintain a conversational flow, use the candidate's responses to inform subsequent questions, and create a realistic interview experience.
38
- """
39
 
40
- def respond(
41
- message,
42
- history: list[tuple[str, str]],
43
- max_tokens,
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
- response = ""
54
- for message in client.chat_completion(
55
- messages,
56
- max_tokens=max_tokens,
57
- stream=True,
58
- temperature=temperature,
59
- top_p=top_p,
60
- ):
61
- token = message.choices[0].delta.content
62
- response += token
63
- yield response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
- demo = gr.ChatInterface(
66
- respond,
67
- additional_inputs=[
68
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
69
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
70
- gr.Slider(
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
- if __name__ == "__main__":
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()