Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,49 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 3 |
-
import time
|
| 4 |
-
|
| 5 |
-
# Initialize the Gemini API
|
| 6 |
-
gemini_api_key = "GOOGLE_API_KEY"
|
| 7 |
-
model_identifier = "models/gemini-v1"
|
| 8 |
-
chat_model = ChatGoogleGenerativeAI(api_key=gemini_api_key, model=model_identifier)
|
| 9 |
|
| 10 |
st.title("Job Interview Preparation Bot")
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Generate Interview Questions
|
| 16 |
-
st.
|
| 17 |
-
role = st.selectbox("Select Role:", ["Software Developer", "Data Analyst", "Marketing Manager"])
|
| 18 |
-
topic = st.selectbox("Select Topic:", ["Behavioral", "Technical", "Situational"])
|
| 19 |
-
num_questions = st.slider("Number of Questions:", 1, 10, 5)
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
if 'questions' in st.session_state:
|
| 30 |
current_question = st.session_state['current_question']
|
| 31 |
st.subheader(f"Question {current_question + 1}:")
|
|
@@ -35,86 +53,28 @@ if 'questions' in st.session_state:
|
|
| 35 |
submit_response = st.button("Submit")
|
| 36 |
|
| 37 |
if submit_response:
|
| 38 |
-
# Store response
|
| 39 |
if 'responses' not in st.session_state:
|
| 40 |
st.session_state['responses'] = []
|
| 41 |
st.session_state['responses'].append(user_response)
|
| 42 |
|
| 43 |
-
# Move to next question or end interview
|
| 44 |
if current_question < num_questions - 1:
|
| 45 |
st.session_state['current_question'] += 1
|
| 46 |
else:
|
| 47 |
st.session_state['interview_complete'] = True
|
| 48 |
st.write("Interview Complete. Analyzing your responses...")
|
| 49 |
|
| 50 |
-
|
| 51 |
-
feedback_prompt = "Provide feedback for the following interview responses:\n" + "\n".join(st.session_state['responses'])
|
| 52 |
-
feedback = chat_model.generate(feedback_prompt)
|
| 53 |
st.write(feedback)
|
| 54 |
|
| 55 |
if 'interview_complete' in st.session_state:
|
| 56 |
st.header("Feedback")
|
| 57 |
st.write(feedback)
|
| 58 |
|
| 59 |
-
st.header("General Interview Tips")
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
st.write(
|
| 63 |
-
|
| 64 |
-
st.header("
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
st.write(role_tips)
|
| 68 |
-
|
| 69 |
-
# Mock Interviews
|
| 70 |
-
st.header("Mock Interview")
|
| 71 |
-
mock_questions_prompt = f"Generate {num_questions} {topic.lower()} questions for a mock {role} interview."
|
| 72 |
-
mock_questions = chat_model.generate(mock_questions_prompt)
|
| 73 |
-
|
| 74 |
-
st.session_state['mock_questions'] = mock_questions
|
| 75 |
-
st.session_state['current_mock_question'] = 0
|
| 76 |
-
st.session_state['mock_start_time'] = time.time()
|
| 77 |
-
|
| 78 |
-
if 'mock_questions' in st.session_state:
|
| 79 |
-
current_mock_question = st.session_state['current_mock_question']
|
| 80 |
-
st.subheader(f"Mock Question {current_mock_question + 1}:")
|
| 81 |
-
st.write(st.session_state['mock_questions'][current_mock_question])
|
| 82 |
-
|
| 83 |
-
user_mock_response = st.text_area("Your Response:", key="user_mock_response")
|
| 84 |
-
submit_mock_response = st.button("Submit Mock Response")
|
| 85 |
-
|
| 86 |
-
if submit_mock_response or time.time() - st.session_state['mock_start_time'] > 60:
|
| 87 |
-
# Store response
|
| 88 |
-
if 'mock_responses' not in st.session_state:
|
| 89 |
-
st.session_state['mock_responses'] = []
|
| 90 |
-
st.session_state['mock_responses'].append(user_mock_response)
|
| 91 |
-
|
| 92 |
-
# Move to next question or end interview
|
| 93 |
-
if current_mock_question < num_questions - 1:
|
| 94 |
-
st.session_state['current_mock_question'] += 1
|
| 95 |
-
st.session_state['mock_start_time'] = time.time()
|
| 96 |
-
else:
|
| 97 |
-
st.session_state['mock_interview_complete'] = True
|
| 98 |
-
st.write("Mock Interview Complete. Analyzing your responses...")
|
| 99 |
-
|
| 100 |
-
# Analyze responses and provide feedback
|
| 101 |
-
mock_feedback_prompt = "Provide feedback for the following mock interview responses:\n" + "\n".join(st.session_state['mock_responses'])
|
| 102 |
-
mock_feedback = chat_model.generate(mock_feedback_prompt)
|
| 103 |
-
st.write(mock_feedback)
|
| 104 |
-
|
| 105 |
-
if 'mock_interview_complete' in st.session_state:
|
| 106 |
-
if 'mock_interview_count' not in st.session_state:
|
| 107 |
-
st.session_state['mock_interview_count'] = 0
|
| 108 |
-
st.session_state['mock_interview_count'] += 1
|
| 109 |
-
|
| 110 |
-
st.header("Engagement Metrics")
|
| 111 |
-
st.write(f"Number of Mock Interviews Taken: {st.session_state['mock_interview_count']}")
|
| 112 |
-
|
| 113 |
-
# Example improvement tracking (placeholder)
|
| 114 |
-
st.write("Your performance is improving!" if st.session_state['mock_interview_count'] > 1 else "Keep practicing!")
|
| 115 |
-
|
| 116 |
-
# Resource Recommendations
|
| 117 |
-
st.header("Resource Recommendations")
|
| 118 |
-
resources_prompt = f"Recommend articles, books, and videos for further learning for a {role} interview."
|
| 119 |
-
resources = chat_model.generate(resources_prompt)
|
| 120 |
-
st.write(resources)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
st.title("Job Interview Preparation Bot")
|
| 5 |
|
| 6 |
+
# Initialize the Google Generative AI with the model and API key
|
| 7 |
+
llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])
|
| 8 |
+
|
| 9 |
+
def generate_questions(role, topic, num_questions, difficulty):
|
| 10 |
+
prompt = (
|
| 11 |
+
f"Generate {num_questions} {topic.lower()} interview questions for a {role} position at difficulty level {difficulty}."
|
| 12 |
+
)
|
| 13 |
+
response = llm.invoke(prompt)
|
| 14 |
+
return response.content
|
| 15 |
+
|
| 16 |
+
def generate_feedback(responses):
|
| 17 |
+
prompt = "Provide feedback for the following interview responses:\n" + "\n".join(responses)
|
| 18 |
+
response = llm.invoke(prompt)
|
| 19 |
+
return response.content
|
| 20 |
+
|
| 21 |
+
def generate_tips(role):
|
| 22 |
+
general_tips_prompt = f"Provide general interview tips for a {role} position."
|
| 23 |
+
role_tips_prompt = f"Provide interview tips specific to a {role} role."
|
| 24 |
+
general_tips = llm.invoke(general_tips_prompt).content
|
| 25 |
+
role_tips = llm.invoke(role_tips_prompt).content
|
| 26 |
+
return general_tips, role_tips
|
| 27 |
+
|
| 28 |
+
def generate_resources(role):
|
| 29 |
+
prompt = f"Recommend articles, books, and videos for further learning for a {role} interview."
|
| 30 |
+
response = llm.invoke(prompt)
|
| 31 |
+
return response.content
|
| 32 |
|
| 33 |
# Generate Interview Questions
|
| 34 |
+
with st.form("question_form"):
|
| 35 |
+
role = st.selectbox("Select Role:", ["Software Developer", "Data Analyst", "Marketing Manager"])
|
| 36 |
+
topic = st.selectbox("Select Topic:", ["Behavioral", "Technical", "Situational"])
|
| 37 |
+
num_questions = st.slider("Number of Questions:", 1, 10, 5)
|
| 38 |
+
difficulty = st.slider("Difficulty Level:", 1, 5, 3)
|
| 39 |
+
generate = st.form_submit_button("Generate Questions")
|
| 40 |
+
|
| 41 |
+
if generate:
|
| 42 |
+
questions = generate_questions(role, topic, num_questions, difficulty)
|
| 43 |
+
st.session_state['questions'] = questions
|
| 44 |
+
st.session_state['current_question'] = 0
|
| 45 |
+
|
| 46 |
+
# Display Questions and Collect Responses
|
| 47 |
if 'questions' in st.session_state:
|
| 48 |
current_question = st.session_state['current_question']
|
| 49 |
st.subheader(f"Question {current_question + 1}:")
|
|
|
|
| 53 |
submit_response = st.button("Submit")
|
| 54 |
|
| 55 |
if submit_response:
|
|
|
|
| 56 |
if 'responses' not in st.session_state:
|
| 57 |
st.session_state['responses'] = []
|
| 58 |
st.session_state['responses'].append(user_response)
|
| 59 |
|
|
|
|
| 60 |
if current_question < num_questions - 1:
|
| 61 |
st.session_state['current_question'] += 1
|
| 62 |
else:
|
| 63 |
st.session_state['interview_complete'] = True
|
| 64 |
st.write("Interview Complete. Analyzing your responses...")
|
| 65 |
|
| 66 |
+
feedback = generate_feedback(st.session_state['responses'])
|
|
|
|
|
|
|
| 67 |
st.write(feedback)
|
| 68 |
|
| 69 |
if 'interview_complete' in st.session_state:
|
| 70 |
st.header("Feedback")
|
| 71 |
st.write(feedback)
|
| 72 |
|
| 73 |
+
st.header("General and Role-Specific Interview Tips")
|
| 74 |
+
general_tips, role_tips = generate_tips(role)
|
| 75 |
+
st.write("**General Tips:**", general_tips)
|
| 76 |
+
st.write("**Role-Specific Tips:**", role_tips)
|
| 77 |
+
|
| 78 |
+
st.header("Resource Recommendations")
|
| 79 |
+
resources = generate_resources(role)
|
| 80 |
+
st.write(resources)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|