File size: 11,852 Bytes
f89b85c
7918327
be3ff98
7918327
380431e
6d50491
33623b4
 
 
2968d9e
d0b05f3
33623b4
 
d9652a8
33623b4
 
 
d0b05f3
33623b4
7afc8cd
 
23e76b6
380431e
 
393ef8f
380431e
 
 
 
 
393ef8f
 
 
 
380431e
 
 
 
 
 
7693eec
1f9d9f2
 
 
 
 
 
380431e
 
 
 
 
 
 
1e8a963
fc3b8b8
27bb6b2
fc3b8b8
a9b5d31
0ba9e5c
 
 
 
 
 
 
 
 
1170aa1
 
4850d7d
1170aa1
 
 
 
 
 
 
 
 
3fcf8f1
380431e
 
 
 
 
 
 
 
 
 
 
 
 
dac4e58
 
7918327
7693eec
380431e
 
 
 
 
 
 
1e8a963
 
380431e
 
 
1e8a963
 
 
 
380431e
 
 
 
 
 
 
7693eec
9c1b0e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d0b05f3
1514986
ec8a367
be51652
1514986
d0b05f3
9c1b0e2
d0b05f3
 
a32f626
 
 
 
 
04ae7da
a32f626
6e2eb2a
0ba9e5c
 
fc3b8b8
 
 
0ba9e5c
4f5d6eb
a32f626
 
d0b05f3
7693eec
a64d2a1
4a342bf
2968d9e
7693eec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
954cd3c
9c1b0e2
7693eec
020888a
 
 
 
 
 
7693eec
1e8a963
7693eec
 
0ba9e5c
 
020888a
c628faa
 
01974e4
c628faa
 
 
 
 
 
01974e4
401c3a3
 
 
 
 
1170aa1
c628faa
 
 
 
 
 
 
7693eec
c628faa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
import streamlit as st
import smtplib
from email.message import EmailMessage
import ssl 
from datetime import datetime
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_groq import ChatGroq

api_choice = st.sidebar.selectbox("Choose API:", ["Gemini", "Groq"])

# Initialize the Google Generative AI with the model and API key
# llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])

if api_choice == "Gemini":
    llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])
elif api_choice == "Groq":
    llm = ChatGroq(model_name="mixtral-8x7b-32768", temperature=0, api_key=st.secrets["GROQ_API_KEY"])

    
st.title("Job Interview Ready 💼")
st.markdown("Get job interview ready by practicing questions at your pace. Get insightful feedback, tips and resources. Also get to analyze your interview over time.")

def generate_questions(role, topic, num_questions, difficulty):
    prompt = (
        f"Generate exactly {num_questions} {topic.lower()} interview questions for a {role} position at difficulty level {difficulty}."
    )
    try:
        response = llm.invoke(prompt)
        questions = response.content.split('\n')
        questions = [q.strip() for q in questions if q.strip()]

        if len(questions) > num_questions:
            questions = questions[:num_questions]
            
        return questions if questions else []
    except Exception as e:
        st.error(f"Error generating questions: {str(e)}")
        return []

def generate_feedback(responses):
    # prompt = "Provide feedback for the following interview responses along with that if the response is not upto mark give the word decline in it, otherwise give the word improve):\n" + "\n".join(responses)
    prompt = (
        "Evaluate the following interview responses. For each response, provide: \n"
        "1. Normal feedback.\n"
        "2. A summary evaluation marked as either 'improve' if the response is good or 'decline' if the response is lacking.\n\n"
        "Responses : \n" + "\n".join(responses)
    )
    try:
        response = llm.invoke(prompt)
        return response.content
    except Exception as e:
        st.error(f"Error generating feedback: {str(e)}")
        return "Feedback generation failed."

def generate_tips(role=None, topic=None, general=False):
    if general:
        prompt = f"Provide only 3 general interview tips such as body language, dress code and etiquette."
    else:
        prompt = f"Provide 3 interview tips for someone applying for a {role} role."
    try:
        response = llm.invoke(prompt)
        tips = response.content.split('\n')
        tips = [tip.strip() for tip in tips if tip.strip()]
        return tips if tips else ["No tips available at the moment."]
    except Exception as e:
        st.error(f"Error generating tips: {str(e)}")
        return ["Tip generation failed."]


def generate_resources(role):
    prompt = f"Provide 3 resources (books, videos, or articles) that would be useful for someone preparing for a {role} position. Provide links for each of them."
    try:
        response = llm.invoke(prompt)
        resources = response.content.split('\n')
        resources = [res.strip() for res in resources if res.strip()]
        return resources if resources else ["No resources available at the moment."]
    except Exception as e:
        st.error(f"Error generating resources: {str(e)}")
        return ["Resource generation failed."]


def save_performance(role, topic, difficulty, feedback):
    if 'performance_history' not in st.session_state:
        st.session_state['performance_history'] = []
    
    performance_entry = {
        "date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
        "role": role,
        "topic": topic,
        "difficulty": difficulty,
        "feedback": feedback
    }
    st.session_state['performance_history'].append(performance_entry)

def schedule_mock_interview(date_time):
    return f"Mock interview scheduled for {date_time}"


def analyze_performance():
    if 'performance_history' not in st.session_state or not st.session_state['performance_history']:
        st.write("No performance data available.")
        return
    
    history = st.session_state['performance_history']
    st.write("### Performance Summary")

    total_interviews = len(history)
    improvement_count = sum(1 for entry in history if "improve" in entry['feedback'].lower())
    deterioration_count = sum(1 for entry in history if "decline" in entry['feedback'].lower())

    st.write(f"**Total Interviews Conducted:** {total_interviews}")
    st.write(f"**Improvements Noted:** {improvement_count}")
    st.write(f"**Deteriorations Noted:** {deterioration_count}")

    if improvement_count > deterioration_count:
        st.success("Overall performance is improving!")
    elif deterioration_count > improvement_count:
        st.warning("Performance is deteriorating.")
    else:
        st.info("Performance is stable.")


# Initialize session state
if 'questions' not in st.session_state:
    st.session_state['questions'] = []
if 'current_question' not in st.session_state:
    st.session_state['current_question'] = 0
if 'responses' not in st.session_state:
    st.session_state['responses'] = []
if 'feedback' not in st.session_state:
    st.session_state['feedback'] = ""
if 'interview_complete' not in st.session_state:
    st.session_state['interview_complete'] = False
if 'tips' not in st.session_state:
    st.session_state['tips'] = []
if 'general_tips_shown' not in st.session_state:
    st.session_state['general_tips_shown'] = False
if 'resources_shown' not in st.session_state:
    st.session_state['resources_shown'] = False

with st.form("question_form"):
    role = st.selectbox("Select Role:", ["Software Developer", "Data Analyst", "Marketing Manager", "Product Manager", "UX/UI Designer", "Data Scientist","GenAI Engineer", "Machine Learning Engineer", "DevOps Engineer", "Cybersecurity Analyst", "Quality Assurance (QA) Engineer", "Network Administrator", "Systems Architect", "Database Administrator", "Cloud Solutions Architect", "Front-End Developer", "Business Analyst", "Systems Engineer", "Big Data Engineer", "Salesforce Developer", "Blockchain Developer"], key="role_select")
    topic = st.selectbox("Select Topic:", ["Behavioral", "Technical", "Situational", "Problem-Solving", "Verbal", "Analytical Thinking","Leadership"], key="topic_select")
    num_questions = st.slider("Number of Questions:", 1, 10)
    difficulty = st.selectbox("Difficulty Level:", ["Beginner", "Intermediate", "Advanced"], key="difficulty_select")
    generate = st.form_submit_button("Generate Questions")
    st.warning("Double click on the Submit button to submit your answer.")

    if generate:
        with st.spinner("Generating questions..."):
            questions = generate_questions(role, topic, num_questions, difficulty)
            if questions:
                st.session_state['questions'] = questions
                st.session_state['current_question'] = 0
                st.session_state['responses'] = []
                st.session_state['feedback'] = ""
                st.session_state['interview_complete'] = False

                # Generate tips
                if not st.session_state['general_tips_shown']:
                    st.session_state['tips'] = generate_tips(general=True)
                    st.session_state['general_tips_shown'] = True

                st.write(f"Generated {len(questions)} questions.")
            else:
                st.error("No questions were generated. Please try again.")


# Display questions and collect responses
if st.session_state['questions']:
    current_question = st.session_state['current_question']
    st.write(f"Question {current_question + 1}: {st.session_state['questions'][current_question]}")

    # Form for response
    with st.form(key=f"response_form_{current_question}"):
        user_response = st.text_area("Your Response:", key=f"user_response_{current_question}")
        submit_response = st.form_submit_button("Submit")

        if submit_response:
            if user_response:
                # Ensure no duplicate responses
                if current_question < len(st.session_state['responses']):
                    st.session_state['responses'][current_question] = user_response
                else:
                    st.session_state['responses'].append(user_response)

            # Update the question index
            if len(st.session_state['responses']) == len(st.session_state['questions']):
                st.session_state['interview_complete'] = True
                st.write("Interview Complete. Analyzing your responses...")
                with st.spinner("Generating feedback..."):
                    feedback = generate_feedback(st.session_state['responses'])
                    st.session_state['feedback'] = feedback
                    save_performance(role, topic, difficulty, feedback)
                st.session_state['questions'] = []  # Clear questions to prevent re-displaying
                st.session_state['responses'] = []  # Clear responses
                st.session_state['current_question'] = 0
            else:
                if current_question < len(st.session_state['questions']) - 1:
                    st.session_state['current_question'] += 1

st.sidebar.header("Schedule Mock Interview")
mock_interview_date = st.sidebar.date_input("Select Date:")
mock_interview_time = st.sidebar.time_input("Select Time:")
if st.sidebar.button("Schedule Mock Interview"):
    date_time = f"{mock_interview_date} {mock_interview_time}"
    message = schedule_mock_interview(date_time)
    st.sidebar.success(message)

# Display feedback
if st.session_state['interview_complete']:
    st.header("Feedback")
    st.write(st.session_state['feedback'])

tab1, tab2 = st.tabs(["Tips & Resources", "Performance Analysis"])

with tab1:
    st.write("## Tips")
    if st.button("Get Role-Specific Tips"):
        with st.spinner(f"Generating interview tips for a {role}..."):
            role_specific_tips = generate_tips(role=role, general=False)
            for tip in role_specific_tips:
                st.write(f"- {tip}")

    st.write("## Resources")
    if st.button("Additional Resources"):
        with st.spinner(f"Generating resources for a {role}..."):
            resources = generate_resources(role)
            for resource in resources:
                st.write(f"- {resource}")
    

with tab2:
    st.write("## Analyze Performance")
    if st.button("Analyze Performance"):
        analyze_performance()


# Display tips section
# st.write("## Interview Tips")

# if st.button("General Interview Tips"):
#     st.write("### General Tips")
#     for tip in st.session_state['tips']:
#         st.write(f"- {tip}")


# role_for_tips = st.selectbox("Select Role for Tips:", ["Software Developer", "Data Analyst", "Marketing Manager"], key="role_tips_select")
# if st.button("Role-Specific Interview Tips"):
#     st.write(f"### Tips for {role_for_tips}")
#     role_specific_tips = generate_tips(role=role_for_tips)
#     for tip in role_specific_tips:
#         st.write(f"- {tip}")

# # Display resources section
# st.write("## Interview Resources")
# selected_role = st.selectbox("Select Role to Display Resources:", ["Software Developer", "Data Analyst", "Marketing Manager"], key="resources_select")
# if st.button("Show Resources"):
#     resources = get_resources(selected_role)
#     st.write(f"### Resources for {selected_role}")
#     for resource in resources:
#         st.write(f"- **{resource['type']}:** [{resource['title']}]({resource['link']})")

# # Performance analysis
# st.write("## Analyze Performance")
# if st.button("Analyze Performance"):
#     analyze_performance()