Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,8 @@ from transformers import pipeline
|
|
| 4 |
from sentence_transformers import SentenceTransformer
|
| 5 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 6 |
import PyPDF2
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Load local models for inference
|
| 9 |
stt_model = pipeline("automatic-speech-recognition", model="openai/whisper-base")
|
|
@@ -50,6 +52,21 @@ def generate_question(user_input, resume_embeddings, job_desc_embedding):
|
|
| 50 |
most_relevant_section = max(similarities, key=similarities.get)
|
| 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):
|
|
@@ -61,13 +78,13 @@ class MockInterview:
|
|
| 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
|
| 65 |
|
| 66 |
-
def conduct_interview(self,
|
| 67 |
if not self.interview_active:
|
| 68 |
return "Please upload your resume and job description first.", ""
|
| 69 |
|
| 70 |
-
transcription = stt_model(
|
| 71 |
question = generate_question(transcription, self.resume_embeddings, self.job_desc_embedding)
|
| 72 |
return transcription, question
|
| 73 |
|
|
@@ -80,11 +97,16 @@ mock_interview = MockInterview()
|
|
| 80 |
def upload_inputs(resume, job_desc):
|
| 81 |
return mock_interview.upload_inputs(resume, job_desc)
|
| 82 |
|
| 83 |
-
def
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
|
| 87 |
-
return mock_interview.end_interview()
|
| 88 |
|
| 89 |
interface = gr.Blocks()
|
| 90 |
with interface:
|
|
@@ -94,20 +116,15 @@ Upload your resume and job description, then engage in a realistic interview sim
|
|
| 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 |
-
|
| 110 |
-
end_button.click(end_interview, outputs=[transcription_output])
|
| 111 |
|
| 112 |
if __name__ == "__main__":
|
| 113 |
interface.launch()
|
|
|
|
| 4 |
from sentence_transformers import SentenceTransformer
|
| 5 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 6 |
import PyPDF2
|
| 7 |
+
import sounddevice as sd
|
| 8 |
+
import queue
|
| 9 |
|
| 10 |
# Load local models for inference
|
| 11 |
stt_model = pipeline("automatic-speech-recognition", model="openai/whisper-base")
|
|
|
|
| 52 |
most_relevant_section = max(similarities, key=similarities.get)
|
| 53 |
return f"Based on your experience in {most_relevant_section}, can you elaborate more?"
|
| 54 |
|
| 55 |
+
# Real-time audio recording and processing
|
| 56 |
+
def record_audio(callback):
|
| 57 |
+
"""Record audio and process it in real-time."""
|
| 58 |
+
q = queue.Queue()
|
| 59 |
+
|
| 60 |
+
def audio_callback(indata, frames, time, status):
|
| 61 |
+
if status:
|
| 62 |
+
print(status)
|
| 63 |
+
q.put(indata.copy())
|
| 64 |
+
|
| 65 |
+
with sd.InputStream(samplerate=16000, channels=1, callback=audio_callback):
|
| 66 |
+
while True:
|
| 67 |
+
audio_data = q.get()
|
| 68 |
+
callback(audio_data)
|
| 69 |
+
|
| 70 |
# Gradio interface
|
| 71 |
class MockInterview:
|
| 72 |
def __init__(self):
|
|
|
|
| 78 |
self.resume_embeddings = process_resume(resume)
|
| 79 |
self.job_desc_embedding = process_job_description(job_desc)
|
| 80 |
self.interview_active = True
|
| 81 |
+
return "Resume and job description processed. Interview is starting."
|
| 82 |
|
| 83 |
+
def conduct_interview(self, audio_data):
|
| 84 |
if not self.interview_active:
|
| 85 |
return "Please upload your resume and job description first.", ""
|
| 86 |
|
| 87 |
+
transcription = stt_model(audio_data)["text"] # Transcribe audio
|
| 88 |
question = generate_question(transcription, self.resume_embeddings, self.job_desc_embedding)
|
| 89 |
return transcription, question
|
| 90 |
|
|
|
|
| 97 |
def upload_inputs(resume, job_desc):
|
| 98 |
return mock_interview.upload_inputs(resume, job_desc)
|
| 99 |
|
| 100 |
+
def start_interview(audio_data_callback):
|
| 101 |
+
"""Start the interview automatically, processing audio in real-time."""
|
| 102 |
+
if not mock_interview.interview_active:
|
| 103 |
+
return "Please upload your resume and job description first."
|
| 104 |
+
|
| 105 |
+
def process_audio(audio_data):
|
| 106 |
+
transcription, question = mock_interview.conduct_interview(audio_data)
|
| 107 |
+
audio_data_callback(transcription, question)
|
| 108 |
|
| 109 |
+
record_audio(process_audio)
|
|
|
|
| 110 |
|
| 111 |
interface = gr.Blocks()
|
| 112 |
with interface:
|
|
|
|
| 116 |
with gr.Row():
|
| 117 |
resume_input = gr.File(label="Upload Resume (PDF)")
|
| 118 |
job_desc_input = gr.Textbox(label="Paste Job Description")
|
| 119 |
+
upload_button = gr.Button("Upload and Start Interview")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
with gr.Row():
|
| 122 |
transcription_output = gr.Textbox(label="Transcription")
|
| 123 |
question_output = gr.Textbox(label="Question")
|
| 124 |
+
end_button = gr.Button("End Interview")
|
| 125 |
|
| 126 |
upload_button.click(upload_inputs, inputs=[resume_input, job_desc_input], outputs=[transcription_output])
|
| 127 |
+
end_button.click(mock_interview.end_interview, outputs=[transcription_output])
|
|
|
|
| 128 |
|
| 129 |
if __name__ == "__main__":
|
| 130 |
interface.launch()
|