Spaces:
Build error
Build error
File size: 5,707 Bytes
7d734fc 08c0778 17a6583 4d4efcc 7500646 65b46a5 7500646 1a768f7 7500646 7ce924e 7500646 65b46a5 7500646 08c0778 4d4efcc 08c0778 4d4efcc 08c0778 156b0ac 4d4efcc 17a6583 4d4efcc 08c0778 4d4efcc 17a6583 4d4efcc 7500646 4d4efcc 7500646 08c0778 17a6583 08c0778 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
import streamlit as st
import random
import time
from transformers import pipeline
import speech_recognition as sr
from streamlit_webrtc import webrtc_streamer, VideoTransformerBase
import numpy as np
import io
# Streamlit Configuration
st.set_page_config(page_title="Interview Copilot", layout="wide")
st.markdown(
"""
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap');
html, body, [class*="css"] {
font-family: 'Poppins', sans-serif;
}
</style>
""", unsafe_allow_html=True)
# Page Title
st.title("ποΈ Interview Copilot")
st.write("### Conduct professional mock interviews, receive feedback, and ace your next job opportunity!")
# Step 1: Input Job Title
st.subheader("Step 1: Enter Job Details")
job_title = st.text_input("Enter Job Title:", placeholder="e.g., Data Scientist, Software Engineer")
job_description = st.text_area("Enter Job Description:", placeholder="Provide details about the role")
# Step 2: Upload CV
st.subheader("Step 2: Upload Your CV")
uploaded_cv = st.file_uploader("Upload Your CV (PDF or Text):", type=["pdf", "txt"])
if uploaded_cv:
cv_content = uploaded_cv.read().decode("utf-8") if uploaded_cv.type == "text/plain" else "Uploaded PDF file"
# Step 3: Start Interview
st.subheader("Step 3: Start the Interview")
if st.button("Start Interview"):
if not job_title or not job_description or not uploaded_cv:
st.error("Please fill in all the required fields (Job Title, Description, CV)!")
else:
# Predefined questions
questions = [
"Introduce yourself.",
"Why do you want this job?",
]
technical_questions = [
"Tell me about a challenging project you've worked on.",
f"What skills do you bring to the role of {job_title}?",
]
non_technical_questions = [
"How do you handle conflict in a team setting?",
"What are your strengths and weaknesses?",
]
# Add random questions to interview
random_questions = random.sample(technical_questions, 2) + random.sample(non_technical_questions, 2)
all_questions = questions + random_questions
# Session state to track question index and responses
if 'question_index' not in st.session_state:
st.session_state.question_index = 0
if 'responses' not in st.session_state:
st.session_state.responses = []
# Step 4: Question and Live Voice Response
current_question = all_questions[st.session_state.question_index]
st.write(f"**Question {st.session_state.question_index + 1}:** {current_question}")
st.write("π€ Please record your answer using the microphone.")
# Initialize WebRTC for live audio capture
audio_recorder = webrtc_streamer(key="audio-recorder", video_transformer_factory=VideoTransformerBase)
if audio_recorder and audio_recorder.audio:
audio_data = audio_recorder.audio
audio_bytes = audio_data.tobytes() # Convert audio to byte format for processing
audio_file = io.BytesIO(audio_bytes) # Use BytesIO to simulate file for audio processing
# Process the audio
recognizer = sr.Recognizer()
try:
with sr.AudioFile(audio_file) as source:
audio_data = recognizer.record(source)
# Transcribe audio to text
transcript = recognizer.recognize_google(audio_data)
st.session_state.responses.append(transcript)
st.write(f"π Transcribed Response: {transcript}")
# Proceed to next question or complete interview
if st.session_state.question_index < len(all_questions) - 1:
st.session_state.question_index += 1
else:
st.session_state.question_index = 0 # Reset to first question after the last one
# Show the next question or finish the interview
if len(st.session_state.responses) < len(all_questions):
st.experimental_rerun()
except sr.UnknownValueError:
st.error("Sorry, I couldn't understand the audio.")
except sr.RequestError as e:
st.error(f"Could not request results from Google Speech Recognition service; {e}")
# Show the evaluation once all responses are collected
if len(st.session_state.responses) == len(all_questions):
st.write("### Interview Completed!")
st.subheader("π Evaluation")
sentiment_analyzer = pipeline("sentiment-analysis")
positive_responses = sum(1 for response in st.session_state.responses if sentiment_analyzer(response)[0]["label"] == "POSITIVE")
# Score Calculation
score = (positive_responses / len(all_questions)) * 100
if score >= 70:
st.success(f"π Excellent! You scored {score:.2f}/100. You're ready for the job!")
else:
st.error(f"π You scored {score:.2f}/100. Here's how you can improve:")
st.write("- Work on your communication clarity.")
st.write("- Practice using correct grammar and vocabulary.")
st.write("- Focus on pronunciation and speaking confidently.")
# CV Feedback
st.subheader("π CV Recommendations")
st.write("- Add quantifiable achievements to your CV.")
st.write("- Tailor your CV to the job description.")
|