Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,14 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import openai
|
| 3 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 4 |
-
from langchain_groq import ChatGroqGenerativeAI # Assume this is the correct import for Groq
|
| 5 |
from datetime import datetime, timedelta
|
| 6 |
import time
|
| 7 |
|
| 8 |
# API keys
|
| 9 |
GOOGLE_API_KEY = st.secrets["GOOGLE_API_KEY"]
|
| 10 |
OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
|
| 11 |
-
GROQ_API_KEY = st.secrets["GROQ_API_KEY"]
|
| 12 |
|
| 13 |
-
# Initialize
|
| 14 |
openai.api_key = OPENAI_API_KEY
|
| 15 |
|
| 16 |
# In-memory storage for progress tracking
|
|
@@ -20,31 +18,14 @@ progress_data = {
|
|
| 20 |
},
|
| 21 |
"mock_interviews_taken": 0,
|
| 22 |
"feedback_provided": 0,
|
| 23 |
-
"tips_retrieved": 0
|
| 24 |
-
"resources_used": 0
|
| 25 |
}
|
| 26 |
|
| 27 |
-
# Define list of roles for dropdown
|
| 28 |
-
ROLE_OPTIONS = [
|
| 29 |
-
"Software Engineer",
|
| 30 |
-
"Data Scientist",
|
| 31 |
-
"Product Manager",
|
| 32 |
-
"UX Designer",
|
| 33 |
-
"Business Analyst",
|
| 34 |
-
"Project Manager",
|
| 35 |
-
"Marketing Specialist",
|
| 36 |
-
"Sales Manager",
|
| 37 |
-
"Customer Support Specialist",
|
| 38 |
-
"Other"
|
| 39 |
-
]
|
| 40 |
-
|
| 41 |
def get_llm(model_choice):
|
| 42 |
if model_choice == "Gemini":
|
| 43 |
return ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_API_KEY)
|
| 44 |
elif model_choice == "OpenAI":
|
| 45 |
return None
|
| 46 |
-
elif model_choice == "Groq":
|
| 47 |
-
return ChatGroqGenerativeAI(api_key=GROQ_API_KEY)
|
| 48 |
else:
|
| 49 |
raise ValueError("Unsupported model choice.")
|
| 50 |
|
|
@@ -64,10 +45,6 @@ def generate_questions(model_choice, role, question_type, num_questions, difficu
|
|
| 64 |
llm = get_llm(model_choice)
|
| 65 |
response = llm.invoke(prompt)
|
| 66 |
return response.content.split("\n")
|
| 67 |
-
elif model_choice == "Groq":
|
| 68 |
-
llm = get_llm(model_choice)
|
| 69 |
-
response = llm.invoke(prompt)
|
| 70 |
-
return response.content.split("\n")
|
| 71 |
else:
|
| 72 |
raise ValueError("Unsupported model choice.")
|
| 73 |
|
|
@@ -84,10 +61,6 @@ def provide_feedback(model_choice, answer):
|
|
| 84 |
llm = get_llm(model_choice)
|
| 85 |
response = llm.invoke(prompt)
|
| 86 |
return response.content
|
| 87 |
-
elif model_choice == "Groq":
|
| 88 |
-
llm = get_llm(model_choice)
|
| 89 |
-
response = llm.invoke(prompt)
|
| 90 |
-
return response.content
|
| 91 |
else:
|
| 92 |
raise ValueError("Unsupported model choice.")
|
| 93 |
|
|
@@ -104,10 +77,6 @@ def get_tips(model_choice, role):
|
|
| 104 |
llm = get_llm(model_choice)
|
| 105 |
response = llm.invoke(prompt)
|
| 106 |
return response.content
|
| 107 |
-
elif model_choice == "Groq":
|
| 108 |
-
llm = get_llm(model_choice)
|
| 109 |
-
response = llm.invoke(prompt)
|
| 110 |
-
return response.content
|
| 111 |
else:
|
| 112 |
raise ValueError("Unsupported model choice.")
|
| 113 |
|
|
@@ -214,7 +183,6 @@ def connect_resources():
|
|
| 214 |
st.error("Please fill out all fields.")
|
| 215 |
else:
|
| 216 |
st.success("Thank you for contacting us! We will get back to you soon.")
|
| 217 |
-
progress_data["resources_used"] += 1
|
| 218 |
|
| 219 |
def style_output(text, color):
|
| 220 |
return f'<div class="output-container"><span style="color: {color}; font-weight: bold;">{text}</span></div>'
|
|
@@ -227,6 +195,10 @@ st.markdown(
|
|
| 227 |
body {
|
| 228 |
background-color: #e0f7fa; /* Light cyan background color */
|
| 229 |
font-family: Arial, sans-serif;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
}
|
| 231 |
.stButton>button {
|
| 232 |
width: 100%;
|
|
@@ -243,11 +215,18 @@ st.markdown(
|
|
| 243 |
background-color: #45a049;
|
| 244 |
}
|
| 245 |
.output-container {
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
border-radius: 8px;
|
| 250 |
-
|
|
|
|
|
|
|
| 251 |
}
|
| 252 |
.sidebar {
|
| 253 |
background-color: #ffffff; /* Sidebar background color */
|
|
@@ -286,17 +265,11 @@ with welcome_message.container():
|
|
| 286 |
time.sleep(4) # Wait for 4 seconds
|
| 287 |
welcome_message.empty() # Remove the welcome message
|
| 288 |
|
| 289 |
-
# Initialize session state for questions
|
| 290 |
if 'questions' not in st.session_state:
|
| 291 |
st.session_state.questions = []
|
| 292 |
-
if 'answers' not in st.session_state:
|
| 293 |
-
st.session_state.answers = []
|
| 294 |
-
if 'feedback' not in st.session_state:
|
| 295 |
-
st.session_state.feedback = []
|
| 296 |
if 'question_index' not in st.session_state:
|
| 297 |
st.session_state.question_index = 0
|
| 298 |
-
if 'show_results' not in st.session_state:
|
| 299 |
-
st.session_state.show_results = False
|
| 300 |
|
| 301 |
# Sidebar Navigation
|
| 302 |
st.sidebar.title("TechPrep Navigation")
|
|
@@ -307,20 +280,17 @@ nav_option = st.sidebar.radio("Choose an option:",
|
|
| 307 |
if nav_option == "Generate Questions":
|
| 308 |
st.header("📝 Generate Interview Questions")
|
| 309 |
|
| 310 |
-
model_choice = st.selectbox("Choose Model:", ["OpenAI", "Gemini"
|
| 311 |
-
role = st.
|
| 312 |
question_type = st.selectbox("Question Type:", ["Behavioral", "Technical", "Situational", "Case Study", "Problem Solving"])
|
| 313 |
num_questions = st.number_input("Number of Questions:", min_value=1, max_value=20, value=5)
|
| 314 |
-
difficulty = st.selectbox("Difficulty Level:", ["
|
| 315 |
|
| 316 |
if st.button("Generate Questions", key="generate_questions"):
|
| 317 |
with st.spinner("Generating questions..."):
|
| 318 |
questions = generate_questions(model_choice, role, question_type, num_questions, difficulty)
|
| 319 |
st.session_state.questions = questions
|
| 320 |
-
st.session_state.answers = ["" for _ in questions]
|
| 321 |
-
st.session_state.feedback = ["" for _ in questions]
|
| 322 |
st.session_state.question_index = 0
|
| 323 |
-
st.session_state.show_results = False
|
| 324 |
progress_data["questions_solved"][question_type] += num_questions
|
| 325 |
|
| 326 |
# Display questions with navigation
|
|
@@ -328,22 +298,28 @@ if nav_option == "Generate Questions":
|
|
| 328 |
question_list = st.session_state.questions
|
| 329 |
index = st.session_state.question_index
|
| 330 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
if index < len(question_list):
|
| 332 |
st.write(f"**Question {index + 1}:** {question_list[index]}")
|
| 333 |
|
| 334 |
# Answer input box
|
| 335 |
answer = st.text_area("Your Answer", key="text_area_answer")
|
| 336 |
-
|
| 337 |
col1, col2 = st.columns(2)
|
| 338 |
with col1:
|
| 339 |
if index > 0:
|
| 340 |
if st.button("Previous"):
|
| 341 |
st.session_state.question_index -= 1
|
|
|
|
| 342 |
|
| 343 |
with col2:
|
| 344 |
if index < len(question_list) - 1:
|
| 345 |
if st.button("Next"):
|
| 346 |
st.session_state.question_index += 1
|
|
|
|
| 347 |
|
| 348 |
# Submit answer and provide feedback
|
| 349 |
if st.button("Submit Answer"):
|
|
@@ -352,35 +328,10 @@ if nav_option == "Generate Questions":
|
|
| 352 |
else:
|
| 353 |
with st.spinner("Providing feedback..."):
|
| 354 |
feedback = provide_feedback(model_choice, answer)
|
| 355 |
-
st.session_state.answers[index] = answer
|
| 356 |
-
st.session_state.feedback[index] = feedback
|
| 357 |
st.markdown(style_output("Feedback Received:", "#FF5722"), unsafe_allow_html=True)
|
| 358 |
st.write(feedback)
|
| 359 |
progress_data["feedback_provided"] += 1
|
| 360 |
|
| 361 |
-
# Show results and score when all questions have been answered
|
| 362 |
-
if index == len(question_list) - 1:
|
| 363 |
-
st.session_state.show_results = True
|
| 364 |
-
|
| 365 |
-
if st.session_state.show_results:
|
| 366 |
-
st.write("### Your Results")
|
| 367 |
-
total_questions = len(st.session_state.questions)
|
| 368 |
-
answered_questions = sum(1 for ans in st.session_state.answers if ans)
|
| 369 |
-
score = (answered_questions / total_questions) * 100
|
| 370 |
-
st.write(f"**Score:** {score:.2f}%")
|
| 371 |
-
|
| 372 |
-
# Display feedback and tips
|
| 373 |
-
st.write("### Feedback Summary")
|
| 374 |
-
for i, (q, ans, fb) in enumerate(zip(st.session_state.questions, st.session_state.answers, st.session_state.feedback)):
|
| 375 |
-
st.write(f"**Question {i + 1}:** {q}")
|
| 376 |
-
st.write(f"**Your Answer:** {ans}")
|
| 377 |
-
st.write(f"**Feedback:** {fb}")
|
| 378 |
-
|
| 379 |
-
tips = get_tips(model_choice, role)
|
| 380 |
-
st.write("### Tips to Improve")
|
| 381 |
-
st.write(tips)
|
| 382 |
-
progress_data["tips_retrieved"] += 1
|
| 383 |
-
|
| 384 |
elif nav_option == "Mock Interview":
|
| 385 |
st.header("🎥 Mock Interview")
|
| 386 |
schedule_mock_interview()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import openai
|
| 3 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
|
|
|
| 4 |
from datetime import datetime, timedelta
|
| 5 |
import time
|
| 6 |
|
| 7 |
# API keys
|
| 8 |
GOOGLE_API_KEY = st.secrets["GOOGLE_API_KEY"]
|
| 9 |
OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
|
|
|
|
| 10 |
|
| 11 |
+
# Initialize OpenAI
|
| 12 |
openai.api_key = OPENAI_API_KEY
|
| 13 |
|
| 14 |
# In-memory storage for progress tracking
|
|
|
|
| 18 |
},
|
| 19 |
"mock_interviews_taken": 0,
|
| 20 |
"feedback_provided": 0,
|
| 21 |
+
"tips_retrieved": 0
|
|
|
|
| 22 |
}
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
def get_llm(model_choice):
|
| 25 |
if model_choice == "Gemini":
|
| 26 |
return ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_API_KEY)
|
| 27 |
elif model_choice == "OpenAI":
|
| 28 |
return None
|
|
|
|
|
|
|
| 29 |
else:
|
| 30 |
raise ValueError("Unsupported model choice.")
|
| 31 |
|
|
|
|
| 45 |
llm = get_llm(model_choice)
|
| 46 |
response = llm.invoke(prompt)
|
| 47 |
return response.content.split("\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
else:
|
| 49 |
raise ValueError("Unsupported model choice.")
|
| 50 |
|
|
|
|
| 61 |
llm = get_llm(model_choice)
|
| 62 |
response = llm.invoke(prompt)
|
| 63 |
return response.content
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
else:
|
| 65 |
raise ValueError("Unsupported model choice.")
|
| 66 |
|
|
|
|
| 77 |
llm = get_llm(model_choice)
|
| 78 |
response = llm.invoke(prompt)
|
| 79 |
return response.content
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
else:
|
| 81 |
raise ValueError("Unsupported model choice.")
|
| 82 |
|
|
|
|
| 183 |
st.error("Please fill out all fields.")
|
| 184 |
else:
|
| 185 |
st.success("Thank you for contacting us! We will get back to you soon.")
|
|
|
|
| 186 |
|
| 187 |
def style_output(text, color):
|
| 188 |
return f'<div class="output-container"><span style="color: {color}; font-weight: bold;">{text}</span></div>'
|
|
|
|
| 195 |
body {
|
| 196 |
background-color: #e0f7fa; /* Light cyan background color */
|
| 197 |
font-family: Arial, sans-serif;
|
| 198 |
+
background-image: url('https://example.com/your-watermark-image.png'); /* URL to your watermark image */
|
| 199 |
+
background-repeat: no-repeat;
|
| 200 |
+
background-position: center;
|
| 201 |
+
background-size: cover;
|
| 202 |
}
|
| 203 |
.stButton>button {
|
| 204 |
width: 100%;
|
|
|
|
| 215 |
background-color: #45a049;
|
| 216 |
}
|
| 217 |
.output-container {
|
| 218 |
+
border: 2px solid #2196F3;
|
| 219 |
+
border-radius: 8px;
|
| 220 |
+
padding: 15px;
|
| 221 |
+
margin: 15px 0;
|
| 222 |
+
background-color: #f1f1f1;
|
| 223 |
+
}
|
| 224 |
+
.progress-container {
|
| 225 |
+
border: 2px solid #2196F3;
|
| 226 |
border-radius: 8px;
|
| 227 |
+
padding: 15px;
|
| 228 |
+
margin: 15px 0;
|
| 229 |
+
background-color: #f9f9f9;
|
| 230 |
}
|
| 231 |
.sidebar {
|
| 232 |
background-color: #ffffff; /* Sidebar background color */
|
|
|
|
| 265 |
time.sleep(4) # Wait for 4 seconds
|
| 266 |
welcome_message.empty() # Remove the welcome message
|
| 267 |
|
| 268 |
+
# Initialize session state for questions and current index
|
| 269 |
if 'questions' not in st.session_state:
|
| 270 |
st.session_state.questions = []
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
if 'question_index' not in st.session_state:
|
| 272 |
st.session_state.question_index = 0
|
|
|
|
|
|
|
| 273 |
|
| 274 |
# Sidebar Navigation
|
| 275 |
st.sidebar.title("TechPrep Navigation")
|
|
|
|
| 280 |
if nav_option == "Generate Questions":
|
| 281 |
st.header("📝 Generate Interview Questions")
|
| 282 |
|
| 283 |
+
model_choice = st.selectbox("Choose Model:", ["OpenAI", "Gemini"])
|
| 284 |
+
role = st.text_input("Role", placeholder="e.g. Software Engineer")
|
| 285 |
question_type = st.selectbox("Question Type:", ["Behavioral", "Technical", "Situational", "Case Study", "Problem Solving"])
|
| 286 |
num_questions = st.number_input("Number of Questions:", min_value=1, max_value=20, value=5)
|
| 287 |
+
difficulty = st.selectbox("Difficulty Level:", ["Easy", "Medium", "Hard"])
|
| 288 |
|
| 289 |
if st.button("Generate Questions", key="generate_questions"):
|
| 290 |
with st.spinner("Generating questions..."):
|
| 291 |
questions = generate_questions(model_choice, role, question_type, num_questions, difficulty)
|
| 292 |
st.session_state.questions = questions
|
|
|
|
|
|
|
| 293 |
st.session_state.question_index = 0
|
|
|
|
| 294 |
progress_data["questions_solved"][question_type] += num_questions
|
| 295 |
|
| 296 |
# Display questions with navigation
|
|
|
|
| 298 |
question_list = st.session_state.questions
|
| 299 |
index = st.session_state.question_index
|
| 300 |
|
| 301 |
+
# Debugging information
|
| 302 |
+
st.write(f"**Current Index:** {index}")
|
| 303 |
+
st.write(f"**Total Questions:** {len(question_list)}")
|
| 304 |
+
|
| 305 |
if index < len(question_list):
|
| 306 |
st.write(f"**Question {index + 1}:** {question_list[index]}")
|
| 307 |
|
| 308 |
# Answer input box
|
| 309 |
answer = st.text_area("Your Answer", key="text_area_answer")
|
| 310 |
+
|
| 311 |
col1, col2 = st.columns(2)
|
| 312 |
with col1:
|
| 313 |
if index > 0:
|
| 314 |
if st.button("Previous"):
|
| 315 |
st.session_state.question_index -= 1
|
| 316 |
+
st.experimental_rerun() # Re-run to update display
|
| 317 |
|
| 318 |
with col2:
|
| 319 |
if index < len(question_list) - 1:
|
| 320 |
if st.button("Next"):
|
| 321 |
st.session_state.question_index += 1
|
| 322 |
+
st.experimental_rerun() # Re-run to update display
|
| 323 |
|
| 324 |
# Submit answer and provide feedback
|
| 325 |
if st.button("Submit Answer"):
|
|
|
|
| 328 |
else:
|
| 329 |
with st.spinner("Providing feedback..."):
|
| 330 |
feedback = provide_feedback(model_choice, answer)
|
|
|
|
|
|
|
| 331 |
st.markdown(style_output("Feedback Received:", "#FF5722"), unsafe_allow_html=True)
|
| 332 |
st.write(feedback)
|
| 333 |
progress_data["feedback_provided"] += 1
|
| 334 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
elif nav_option == "Mock Interview":
|
| 336 |
st.header("🎥 Mock Interview")
|
| 337 |
schedule_mock_interview()
|