Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import time
|
3 |
-
from transformers import pipeline
|
4 |
from sentence_transformers import SentenceTransformer
|
5 |
from sklearn.metrics.pairwise import cosine_similarity
|
6 |
from TTS.api import TTS # Coqui TTS library
|
@@ -9,10 +9,9 @@ import PyPDF2
|
|
9 |
# Initialize Models
|
10 |
stt_model = pipeline("automatic-speech-recognition", model="openai/whisper-tiny")
|
11 |
embedding_model = SentenceTransformer("all-MiniLM-L6-v2")
|
|
|
|
|
12 |
tts_model = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False)
|
13 |
-
gpt_model_name = "OpenAssistant/oasst-sft-6-llama-30b"
|
14 |
-
gpt_tokenizer = AutoTokenizer.from_pretrained(gpt_model_name)
|
15 |
-
gpt_model = AutoModelForCausalLM.from_pretrained(gpt_model_name)
|
16 |
|
17 |
# Parse PDF and create resume content
|
18 |
def parse_resume(pdf):
|
@@ -29,20 +28,17 @@ def process_inputs(resume, job_desc):
|
|
29 |
job_desc_embedding = embedding_model.encode(job_desc)
|
30 |
return resume_embeddings, job_desc_embedding
|
31 |
|
32 |
-
# Generate a follow-up question
|
33 |
-
def
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
Based on
|
41 |
-
|
42 |
-
|
43 |
-
outputs = gpt_model.generate(**inputs, max_length=150, num_beams=3, early_stopping=True)
|
44 |
-
question = gpt_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
45 |
-
return question.strip()
|
46 |
|
47 |
# Generate TTS audio for a question
|
48 |
def generate_audio(question):
|
@@ -74,8 +70,8 @@ class MockInterview:
|
|
74 |
if not transcription.strip():
|
75 |
return "No response detected. Please try again.", None
|
76 |
|
77 |
-
# Generate the next question
|
78 |
-
self.current_question =
|
79 |
return transcription, generate_audio(self.current_question)
|
80 |
|
81 |
def end_interview(self):
|
@@ -106,12 +102,13 @@ with interface:
|
|
106 |
audio_input = gr.Audio(type="filepath", label="Your Response")
|
107 |
question_audio_output = gr.Audio(label="Question Audio")
|
108 |
transcription_output = gr.Textbox(label="Transcription")
|
109 |
-
|
110 |
-
resume_input.change(start_interview, inputs=[resume_input, job_desc_input], outputs=[transcription_output, question_audio_output])
|
111 |
-
audio_input.change(next_interaction, inputs=[audio_input], outputs=[transcription_output, question_audio_output])
|
112 |
-
|
113 |
end_button = gr.Button("End Interview")
|
|
|
|
|
|
|
114 |
end_button.click(end_interview, outputs=[transcription_output, question_audio_output])
|
115 |
|
116 |
if __name__ == "__main__":
|
117 |
interface.launch()
|
|
|
|
1 |
import gradio as gr
|
2 |
import time
|
3 |
+
from transformers import pipeline
|
4 |
from sentence_transformers import SentenceTransformer
|
5 |
from sklearn.metrics.pairwise import cosine_similarity
|
6 |
from TTS.api import TTS # Coqui TTS library
|
|
|
9 |
# Initialize Models
|
10 |
stt_model = pipeline("automatic-speech-recognition", model="openai/whisper-tiny")
|
11 |
embedding_model = SentenceTransformer("all-MiniLM-L6-v2")
|
12 |
+
conversation_model = pipeline("text-generation", model="deepseek/deepsense-open") # Using DeepSeek for question generation
|
13 |
+
|
14 |
tts_model = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False)
|
|
|
|
|
|
|
15 |
|
16 |
# Parse PDF and create resume content
|
17 |
def parse_resume(pdf):
|
|
|
28 |
job_desc_embedding = embedding_model.encode(job_desc)
|
29 |
return resume_embeddings, job_desc_embedding
|
30 |
|
31 |
+
# Generate a follow-up question
|
32 |
+
def generate_question(response, resume_embeddings):
|
33 |
+
user_embedding = embedding_model.encode(response)
|
34 |
+
similarities = {
|
35 |
+
section: cosine_similarity([user_embedding], [embedding])[0][0]
|
36 |
+
for section, embedding in resume_embeddings.items()
|
37 |
+
}
|
38 |
+
most_relevant_section = max(similarities, key=similarities.get)
|
39 |
+
question_prompt = f"You are interviewing a candidate. Based on their resume and experience in {most_relevant_section}, ask a follow-up question."
|
40 |
+
question = conversation_model(question_prompt, max_length=50, num_return_sequences=1)[0]['generated_text']
|
41 |
+
return question
|
|
|
|
|
|
|
42 |
|
43 |
# Generate TTS audio for a question
|
44 |
def generate_audio(question):
|
|
|
70 |
if not transcription.strip():
|
71 |
return "No response detected. Please try again.", None
|
72 |
|
73 |
+
# Generate the next question
|
74 |
+
self.current_question = generate_question(transcription, self.resume_embeddings)
|
75 |
return transcription, generate_audio(self.current_question)
|
76 |
|
77 |
def end_interview(self):
|
|
|
102 |
audio_input = gr.Audio(type="filepath", label="Your Response")
|
103 |
question_audio_output = gr.Audio(label="Question Audio")
|
104 |
transcription_output = gr.Textbox(label="Transcription")
|
105 |
+
interaction_button = gr.Button("Next Interaction")
|
|
|
|
|
|
|
106 |
end_button = gr.Button("End Interview")
|
107 |
+
|
108 |
+
resume_uploaded = resume_input.change(start_interview, inputs=[resume_input, job_desc_input], outputs=[transcription_output, question_audio_output])
|
109 |
+
interaction_button.click(next_interaction, inputs=[audio_input], outputs=[transcription_output, question_audio_output])
|
110 |
end_button.click(end_interview, outputs=[transcription_output, question_audio_output])
|
111 |
|
112 |
if __name__ == "__main__":
|
113 |
interface.launch()
|
114 |
+
|