Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,98 +1,117 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from streamlit_webrtc import webrtc_streamer
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
import
|
| 6 |
-
|
| 7 |
-
import
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
url = "https://api.ocr.space/parse/image"
|
| 20 |
-
payload = {
|
| 21 |
-
'apikey': OCR_API_KEY,
|
| 22 |
-
'language': 'eng',
|
| 23 |
-
'filetype': 'PNG'
|
| 24 |
}
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
#
|
| 39 |
-
st.
|
| 40 |
-
st.
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
if "OCR Error" in answer_key_text:
|
| 51 |
-
st.error("Error extracting text from answer key: " + answer_key_text)
|
| 52 |
else:
|
| 53 |
-
|
| 54 |
-
st.
|
| 55 |
-
st.write("
|
| 56 |
-
st.write(
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Save as `interview_copilot.py`
|
| 2 |
import streamlit as st
|
| 3 |
+
from streamlit_webrtc import webrtc_streamer
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
from sentence_transformers import SentenceTransformer
|
| 6 |
+
import openai
|
| 7 |
+
import whisper
|
| 8 |
+
import time
|
| 9 |
+
import random
|
| 10 |
+
|
| 11 |
+
# Configuration for Streamlit
|
| 12 |
+
st.set_page_config(page_title="Interview Copilot", layout="wide")
|
| 13 |
+
st.markdown(
|
| 14 |
+
"""
|
| 15 |
+
<style>
|
| 16 |
+
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap');
|
| 17 |
+
html, body, [class*="css"] {
|
| 18 |
+
font-family: 'Poppins', sans-serif;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
}
|
| 20 |
+
</style>
|
| 21 |
+
""", unsafe_allow_html=True)
|
| 22 |
+
|
| 23 |
+
# Page Title
|
| 24 |
+
st.title("ποΈ Interview Copilot")
|
| 25 |
+
st.write("### Conduct professional mock interviews, receive feedback, and ace your next job opportunity!")
|
| 26 |
+
st.image("https://via.placeholder.com/800x200?text=Interview+Copilot", use_column_width=True)
|
| 27 |
+
|
| 28 |
+
# Step 1: Input Job Title
|
| 29 |
+
st.subheader("Step 1: Enter Job Details")
|
| 30 |
+
job_title = st.text_input("Enter Job Title:", placeholder="e.g., Data Scientist, Software Engineer")
|
| 31 |
+
job_description = st.text_area("Enter Job Description:", placeholder="Provide details about the role")
|
| 32 |
+
|
| 33 |
+
# Step 2: Upload CV
|
| 34 |
+
st.subheader("Step 2: Upload Your CV")
|
| 35 |
+
uploaded_cv = st.file_uploader("Upload Your CV (PDF or Text):", type=["pdf", "txt"])
|
| 36 |
+
if uploaded_cv:
|
| 37 |
+
cv_content = uploaded_cv.read().decode("utf-8") if uploaded_cv.type == "text/plain" else "Uploaded PDF file"
|
| 38 |
+
|
| 39 |
+
# Step 3: Start Interview
|
| 40 |
+
st.subheader("Step 3: Start the Interview")
|
| 41 |
+
if st.button("Start Interview"):
|
| 42 |
+
if not job_title or not job_description or not uploaded_cv:
|
| 43 |
+
st.error("Please fill in all the required fields (Job Title, Description, CV)!")
|
|
|
|
|
|
|
|
|
|
| 44 |
else:
|
| 45 |
+
# Simulate Interview Start
|
| 46 |
+
st.subheader("π₯ Live Interview Simulation")
|
| 47 |
+
st.write("The interview will begin shortly. Prepare yourself!")
|
| 48 |
+
st.write("π€ **Bot:** Hello, letβs start the interview!")
|
| 49 |
+
|
| 50 |
+
# Timer
|
| 51 |
+
start_time = time.time()
|
| 52 |
+
duration = 5 * 60 # 5 minutes
|
| 53 |
+
webrtc_streamer(key="camera", rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]})
|
| 54 |
+
|
| 55 |
+
# Predefined questions
|
| 56 |
+
questions = [
|
| 57 |
+
"Introduce yourself.",
|
| 58 |
+
"Why do you want this job?",
|
| 59 |
+
]
|
| 60 |
+
technical_questions = [
|
| 61 |
+
"Tell me about a challenging project you've worked on.",
|
| 62 |
+
f"What skills do you bring to the role of {job_title}?",
|
| 63 |
+
]
|
| 64 |
+
non_technical_questions = [
|
| 65 |
+
"How do you handle conflict in a team setting?",
|
| 66 |
+
"What are your strengths and weaknesses?",
|
| 67 |
+
]
|
| 68 |
+
|
| 69 |
+
# Generate AI-based questions using Hugging Face models
|
| 70 |
+
question_generator = pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B")
|
| 71 |
+
generated_questions = question_generator(
|
| 72 |
+
f"Generate 3 interview questions for the role of {job_title} based on this CV:\n{cv_content}",
|
| 73 |
+
max_length=50, num_return_sequences=3
|
| 74 |
+
)
|
| 75 |
+
ai_questions = [q["generated_text"] for q in generated_questions]
|
| 76 |
+
|
| 77 |
+
# Combine questions
|
| 78 |
+
all_questions = questions + random.sample(technical_questions, 2) + random.sample(non_technical_questions, 2) + ai_questions
|
| 79 |
+
|
| 80 |
+
# Conduct interview
|
| 81 |
+
responses = []
|
| 82 |
+
for idx, question in enumerate(all_questions):
|
| 83 |
+
st.write(f"**Question {idx + 1}: {question}**")
|
| 84 |
+
user_response = st.text_area(f"Your Answer to Question {idx + 1}", key=f"response_{idx}")
|
| 85 |
+
responses.append(user_response)
|
| 86 |
+
|
| 87 |
+
if time.time() - start_time > duration:
|
| 88 |
+
st.warning("β±οΈ Interview time is up!")
|
| 89 |
+
break
|
| 90 |
+
|
| 91 |
+
# Step 4: Evaluation
|
| 92 |
+
st.subheader("π Evaluation")
|
| 93 |
+
st.write("Evaluating your performance based on your answers...")
|
| 94 |
+
|
| 95 |
+
# Communication Skills Analysis
|
| 96 |
+
sentiment_analyzer = pipeline("sentiment-analysis")
|
| 97 |
+
sentiment_results = [sentiment_analyzer(response)[0] for response in responses if response]
|
| 98 |
+
positive_count = sum(1 for result in sentiment_results if result["label"] == "POSITIVE")
|
| 99 |
+
|
| 100 |
+
# Feedback
|
| 101 |
+
score = positive_count * 10 # Simplified scoring
|
| 102 |
+
if score >= 70:
|
| 103 |
+
st.success(f"π Great job! You scored {score}/100. You're ready to ace the interview!")
|
| 104 |
+
else:
|
| 105 |
+
st.error(f"π You scored {score}/100. Here's how you can improve:")
|
| 106 |
+
st.write("- Practice communicating your ideas clearly.")
|
| 107 |
+
st.write("- Provide detailed examples to technical questions.")
|
| 108 |
+
st.write("- Work on your confidence and tone of speech.")
|
| 109 |
+
|
| 110 |
+
# CV Recommendations
|
| 111 |
+
st.subheader("π CV Recommendations")
|
| 112 |
+
st.write("- Add measurable achievements to your CV.")
|
| 113 |
+
st.write("- Tailor your CV to match the job description.")
|
| 114 |
+
|
| 115 |
+
# Add Graphics and Animation
|
| 116 |
+
st.markdown("---")
|
| 117 |
+
st.markdown("#### Powered by AI | Built with π» and Streamlit")
|