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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
|
| 6 |
+
import requests
|
| 7 |
+
import json
|
| 8 |
+
|
| 9 |
+
# Slack Webhook
|
| 10 |
+
SLACK_WEBHOOK_URL = os.environ["SLACK_WEBHOOK_URL"]
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def send_candidate_info(name, email, years_of_experience, skills, performance_score=None):
|
| 14 |
+
# Prepare the candidate details message
|
| 15 |
+
candidate_message = {
|
| 16 |
+
"text": f"Round - 1\nCandidate Name - {name}\nEmail: {email}\nTotal experience - {years_of_experience} years\nSkills: {skills}\nPerformance Score: {performance_score}"
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
# Send the candidate details message
|
| 20 |
+
response = requests.post(SLACK_WEBHOOK_URL, data=json.dumps(candidate_message), headers={'Content-Type': 'application/json'})
|
| 21 |
+
|
| 22 |
+
if response.status_code == 200:
|
| 23 |
+
print("Candidate info sent successfully!")
|
| 24 |
+
else:
|
| 25 |
+
print(f"Failed to send candidate info: {response.status_code}, {response.text}")
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def call():
|
| 29 |
+
# Store the start time if it's the first time
|
| 30 |
+
if 'start_time' not in st.session_state:
|
| 31 |
+
st.session_state['start_time'] = datetime.now()
|
| 32 |
+
|
| 33 |
+
# Define questions
|
| 34 |
+
questions = [
|
| 35 |
+
{
|
| 36 |
+
"question": "What is 2+2?",
|
| 37 |
+
"option1": "3",
|
| 38 |
+
"option2": "4",
|
| 39 |
+
"option3": "5",
|
| 40 |
+
"option4": "6",
|
| 41 |
+
"answer": "4",
|
| 42 |
+
"importance": "high"
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"question": "What is 3*6?",
|
| 46 |
+
"option1": "12",
|
| 47 |
+
"option2": "18",
|
| 48 |
+
"option3": "21",
|
| 49 |
+
"option4": "24",
|
| 50 |
+
"answer": "18",
|
| 51 |
+
"importance": "low"
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
"question": "What is 8/2?",
|
| 55 |
+
"option1": "2",
|
| 56 |
+
"option2": "3",
|
| 57 |
+
"option3": "4",
|
| 58 |
+
"option4": "5",
|
| 59 |
+
"answer": "4",
|
| 60 |
+
"importance": "medium"
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"question": "What is 5-3?",
|
| 64 |
+
"option1": "1",
|
| 65 |
+
"option2": "2",
|
| 66 |
+
"option3": "3",
|
| 67 |
+
"option4": "4",
|
| 68 |
+
"answer": "2",
|
| 69 |
+
"importance": "high"
|
| 70 |
+
}
|
| 71 |
+
]
|
| 72 |
+
|
| 73 |
+
marks = {
|
| 74 |
+
"high": 3,
|
| 75 |
+
"medium": 2,
|
| 76 |
+
"low": 1
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
score = 0
|
| 80 |
+
total_questions = len(questions)
|
| 81 |
+
|
| 82 |
+
# Create a progress bar
|
| 83 |
+
progress_bar = st.progress(0)
|
| 84 |
+
|
| 85 |
+
# Time logic for countdown
|
| 86 |
+
start_time = st.session_state['start_time']
|
| 87 |
+
elapsed_time = datetime.now() - start_time
|
| 88 |
+
remaining_time = max(0, 300 - int(elapsed_time.total_seconds())) # 5 minutes = 300 seconds
|
| 89 |
+
minutes, seconds = divmod(remaining_time, 60)
|
| 90 |
+
st.text(f"Time Remaining: {minutes:02}:{seconds:02}")
|
| 91 |
+
|
| 92 |
+
for idx, question in enumerate(questions):
|
| 93 |
+
# Section for each question with styling
|
| 94 |
+
st.markdown(f"### Question {idx + 1}: {question['question']}")
|
| 95 |
+
selected_option = st.radio(
|
| 96 |
+
"",
|
| 97 |
+
[question['option1'], question['option2'], question['option3'], question['option4']],
|
| 98 |
+
key=f"q{idx}",
|
| 99 |
+
label_visibility="collapsed",
|
| 100 |
+
help="Choose the correct answer"
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
# Checking for correct answer and assigning points based on importance
|
| 104 |
+
if selected_option == question['answer']:
|
| 105 |
+
score += 1
|
| 106 |
+
|
| 107 |
+
# Update the progress bar after each question
|
| 108 |
+
progress_bar.progress((idx + 1) / total_questions)
|
| 109 |
+
|
| 110 |
+
if st.button("Submit Test", use_container_width=True):
|
| 111 |
+
st.session_state['test_started'] = False
|
| 112 |
+
st.success(f"Test completed!")
|
| 113 |
+
send_candidate_info(st.session_state['name'], st.session_state['email'], st.session_state['experience'], st.session_state['technology'], (score/total_questions)*100)
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def main():
|
| 117 |
+
# Set page config with custom title and layout
|
| 118 |
+
st.set_page_config(page_title="Candidate MCQ Platform", layout="wide")
|
| 119 |
+
|
| 120 |
+
# Display logo and header in the top section
|
| 121 |
+
st.markdown("""
|
| 122 |
+
<style>
|
| 123 |
+
.header {
|
| 124 |
+
text-align: center;
|
| 125 |
+
font-size: 36px;
|
| 126 |
+
font-weight: bold;
|
| 127 |
+
margin-top: 20px;
|
| 128 |
+
color: #059D66;
|
| 129 |
+
}
|
| 130 |
+
.logo {
|
| 131 |
+
display: block;
|
| 132 |
+
margin: 0 auto;
|
| 133 |
+
max-width: 100px;
|
| 134 |
+
height: auto;
|
| 135 |
+
}
|
| 136 |
+
</style>
|
| 137 |
+
<div class="header">
|
| 138 |
+
<img src="https://framerusercontent.com/images/QNgS2NOAyBozR6eFdgzSFhJRbY.png?scale-down-to=512" class="logo" />
|
| 139 |
+
Candidate Assessment Platform
|
| 140 |
+
</div>
|
| 141 |
+
""", unsafe_allow_html=True)
|
| 142 |
+
|
| 143 |
+
if 'test_started' not in st.session_state:
|
| 144 |
+
st.session_state['test_started'] = False
|
| 145 |
+
|
| 146 |
+
if not st.session_state['test_started']:
|
| 147 |
+
st.title("Welcome to the Candidate Assessment Platform")
|
| 148 |
+
with st.form("signup_form"):
|
| 149 |
+
st.header("Sign Up")
|
| 150 |
+
name = st.text_input("Full Name", help="Please enter your full name")
|
| 151 |
+
email = st.text_input("Email", help="Please enter your email")
|
| 152 |
+
experience = st.slider("Total Years of Experience", 0, 20, 0, help="Select your years of experience")
|
| 153 |
+
technology = st.selectbox("Technology", ["Python", "Django", "RoR", "NodeJS", "React", "Flutter"])
|
| 154 |
+
|
| 155 |
+
# Validation to ensure inputs are provided
|
| 156 |
+
signup_submit = st.form_submit_button("Start Test")
|
| 157 |
+
if signup_submit:
|
| 158 |
+
if not name or not email:
|
| 159 |
+
st.error("Name and Email are required! Please fill both fields.")
|
| 160 |
+
else:
|
| 161 |
+
st.session_state['test_started'] = True
|
| 162 |
+
st.session_state['name'] = name
|
| 163 |
+
st.session_state['email'] = email
|
| 164 |
+
st.session_state['experience'] = experience
|
| 165 |
+
st.session_state['technology'] = technology
|
| 166 |
+
st.header("Instructions")
|
| 167 |
+
st.info("""
|
| 168 |
+
1. You have 30 minutes to complete the test.
|
| 169 |
+
2. Each question is multiple-choice.
|
| 170 |
+
3. Your results will be shared upon completion.
|
| 171 |
+
""")
|
| 172 |
+
else:
|
| 173 |
+
call()
|
| 174 |
+
|
| 175 |
+
if __name__ == "__main__":
|
| 176 |
+
main()
|