Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,11 @@ def parse_resume(pdf):
|
|
20 |
sections = {"Resume Content": text}
|
21 |
return sections
|
22 |
|
|
|
|
|
|
|
|
|
|
|
23 |
# Process resume and generate embeddings
|
24 |
def process_resume(pdf):
|
25 |
resume_content = parse_resume(pdf)
|
@@ -29,13 +34,13 @@ def process_resume(pdf):
|
|
29 |
return resume_embeddings
|
30 |
|
31 |
# Generate a conversation response
|
32 |
-
def generate_conversation_response(user_input):
|
33 |
-
prompt = f"The user said: {user_input}. Respond appropriately as a
|
34 |
response = conversation_model(prompt, max_length=100, num_return_sequences=1)
|
35 |
return response[0]["generated_text"]
|
36 |
|
37 |
# Generate question from user response
|
38 |
-
def generate_question(user_input, resume_embeddings):
|
39 |
"""Find the most relevant section in the resume and generate a question."""
|
40 |
user_embedding = embedding_model.encode(user_input)
|
41 |
similarities = {
|
@@ -46,19 +51,63 @@ def generate_question(user_input, resume_embeddings):
|
|
46 |
return f"Based on your experience in {most_relevant_section}, can you elaborate more?"
|
47 |
|
48 |
# Gradio interface
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
if __name__ == "__main__":
|
64 |
interface.launch()
|
|
|
20 |
sections = {"Resume Content": text}
|
21 |
return sections
|
22 |
|
23 |
+
# Process job description text
|
24 |
+
def process_job_description(job_desc):
|
25 |
+
"""Encode the job description for analysis."""
|
26 |
+
return embedding_model.encode(job_desc)
|
27 |
+
|
28 |
# Process resume and generate embeddings
|
29 |
def process_resume(pdf):
|
30 |
resume_content = parse_resume(pdf)
|
|
|
34 |
return resume_embeddings
|
35 |
|
36 |
# Generate a conversation response
|
37 |
+
def generate_conversation_response(user_input, job_desc_embedding):
|
38 |
+
prompt = f"The user said: {user_input}. Respond appropriately as a professional hiring manager. Focus on how the response relates to the job description."
|
39 |
response = conversation_model(prompt, max_length=100, num_return_sequences=1)
|
40 |
return response[0]["generated_text"]
|
41 |
|
42 |
# Generate question from user response
|
43 |
+
def generate_question(user_input, resume_embeddings, job_desc_embedding):
|
44 |
"""Find the most relevant section in the resume and generate a question."""
|
45 |
user_embedding = embedding_model.encode(user_input)
|
46 |
similarities = {
|
|
|
51 |
return f"Based on your experience in {most_relevant_section}, can you elaborate more?"
|
52 |
|
53 |
# Gradio interface
|
54 |
+
class MockInterview:
|
55 |
+
def __init__(self):
|
56 |
+
self.resume_embeddings = None
|
57 |
+
self.job_desc_embedding = None
|
58 |
+
self.interview_active = False
|
59 |
+
|
60 |
+
def upload_inputs(self, resume, job_desc):
|
61 |
+
self.resume_embeddings = process_resume(resume)
|
62 |
+
self.job_desc_embedding = process_job_description(job_desc)
|
63 |
+
self.interview_active = True
|
64 |
+
return "Resume and job description processed. Interview is ready to begin."
|
65 |
+
|
66 |
+
def conduct_interview(self, audio):
|
67 |
+
if not self.interview_active:
|
68 |
+
return "Please upload your resume and job description first.", ""
|
69 |
+
|
70 |
+
transcription = stt_model(audio)["text"] # Transcribe audio
|
71 |
+
question = generate_question(transcription, self.resume_embeddings, self.job_desc_embedding)
|
72 |
+
return transcription, question
|
73 |
+
|
74 |
+
def end_interview(self):
|
75 |
+
self.interview_active = False
|
76 |
+
return "Interview ended. Thank you for participating."
|
77 |
+
|
78 |
+
mock_interview = MockInterview()
|
79 |
+
|
80 |
+
def upload_inputs(resume, job_desc):
|
81 |
+
return mock_interview.upload_inputs(resume, job_desc)
|
82 |
+
|
83 |
+
def conduct_interview(audio):
|
84 |
+
return mock_interview.conduct_interview(audio)
|
85 |
+
|
86 |
+
def end_interview():
|
87 |
+
return mock_interview.end_interview()
|
88 |
+
|
89 |
+
interface = gr.Blocks()
|
90 |
+
with interface:
|
91 |
+
gr.Markdown("""# Mock Interview AI
|
92 |
+
Upload your resume and job description, then engage in a realistic interview simulation.""")
|
93 |
+
|
94 |
+
with gr.Row():
|
95 |
+
resume_input = gr.File(label="Upload Resume (PDF)")
|
96 |
+
job_desc_input = gr.Textbox(label="Paste Job Description")
|
97 |
+
upload_button = gr.Button("Upload")
|
98 |
+
|
99 |
+
with gr.Row():
|
100 |
+
audio_input = gr.Audio(type="filepath", label="Speak Your Answer")
|
101 |
+
submit_button = gr.Button("Submit Response")
|
102 |
+
end_button = gr.Button("End Interview")
|
103 |
+
|
104 |
+
with gr.Row():
|
105 |
+
transcription_output = gr.Textbox(label="Transcription")
|
106 |
+
question_output = gr.Textbox(label="Question")
|
107 |
+
|
108 |
+
upload_button.click(upload_inputs, inputs=[resume_input, job_desc_input], outputs=[transcription_output])
|
109 |
+
submit_button.click(conduct_interview, inputs=[audio_input], outputs=[transcription_output, question_output])
|
110 |
+
end_button.click(end_interview, outputs=[transcription_output])
|
111 |
|
112 |
if __name__ == "__main__":
|
113 |
interface.launch()
|