rashid01 commited on
Commit
4108d48
·
verified ·
1 Parent(s): efc598e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -46
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import streamlit as st
2
  import openai
3
  from langchain_google_genai import ChatGoogleGenerativeAI
4
- import requests # For Groq model
5
  from datetime import datetime, timedelta
6
  import time
7
 
@@ -10,7 +10,7 @@ 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 OpenAI
14
  openai.api_key = OPENAI_API_KEY
15
 
16
  # In-memory storage for progress tracking
@@ -44,7 +44,7 @@ def get_llm(model_choice):
44
  elif model_choice == "OpenAI":
45
  return None
46
  elif model_choice == "Groq":
47
- return GROQ_API_KEY # Example placeholder
48
  else:
49
  raise ValueError("Unsupported model choice.")
50
 
@@ -65,9 +65,9 @@ def generate_questions(model_choice, role, question_type, num_questions, difficu
65
  response = llm.invoke(prompt)
66
  return response.content.split("\n")
67
  elif model_choice == "Groq":
68
- headers = {"Authorization": f"Bearer {GROQ_API_KEY}"}
69
- response = requests.post("https://api.groq.com/generate", headers=headers, json={"prompt": prompt})
70
- return response.json().get("text", "").split("\n")
71
  else:
72
  raise ValueError("Unsupported model choice.")
73
 
@@ -85,9 +85,9 @@ def provide_feedback(model_choice, answer):
85
  response = llm.invoke(prompt)
86
  return response.content
87
  elif model_choice == "Groq":
88
- headers = {"Authorization": f"Bearer {GROQ_API_KEY}"}
89
- response = requests.post("https://api.groq.com/feedback", headers=headers, json={"prompt": prompt})
90
- return response.json().get("text", "")
91
  else:
92
  raise ValueError("Unsupported model choice.")
93
 
@@ -105,9 +105,9 @@ def get_tips(model_choice, role):
105
  response = llm.invoke(prompt)
106
  return response.content
107
  elif model_choice == "Groq":
108
- headers = {"Authorization": f"Bearer {GROQ_API_KEY}"}
109
- response = requests.post("https://api.groq.com/tips", headers=headers, json={"prompt": prompt})
110
- return response.json().get("text", "")
111
  else:
112
  raise ValueError("Unsupported model choice.")
113
 
@@ -185,7 +185,6 @@ def track_progress():
185
  <p><strong>Mock Interviews Taken:</strong> {progress_data['mock_interviews_taken']}</p>
186
  <p><strong>Feedback Provided:</strong> {progress_data['feedback_provided']}</p>
187
  <p><strong>Tips Retrieved:</strong> {progress_data['tips_retrieved']}</p>
188
- <p><strong>Resources Used:</strong> {progress_data['resources_used']}</p>
189
  </div>
190
  """, unsafe_allow_html=True)
191
 
@@ -204,41 +203,41 @@ def connect_resources():
204
 
205
  # Form to connect with career coaches or mentors
206
  with st.form("contact_form"):
207
- st.write("For personalized assistance, please fill out the form below:")
208
- name = st.text_input("Your Name")
209
- email = st.text_input("Your Email")
210
  message = st.text_area("Message")
211
- submit_button = st.form_submit_button("Send Message")
212
 
213
  if submit_button:
214
- if name and email and message:
215
- st.success("Thank you for reaching out! We'll get back to you soon.")
216
- progress_data["resources_used"] += 1
217
  else:
218
- st.error("Please fill out all fields before submitting.")
 
219
 
220
- # Style for feedback and results
221
- def style_output(title, color):
222
- return f"""
223
- <div class="output-container" style="border-left: 5px solid {color};">
224
- <h3>{title}</h3>
225
- </div>
226
- """
227
 
228
- # Custom CSS
229
- st.markdown("""
 
 
230
  <style>
 
 
 
 
231
  .stButton>button {
232
- background-color: #4CAF50;
 
 
233
  color: white;
 
234
  border: none;
235
- padding: 10px 20px;
236
- text-align: center;
237
- text-decoration: none;
238
- display: inline-block;
239
- font-size: 16px;
240
  border-radius: 8px;
241
  cursor: pointer;
 
242
  }
243
  .stButton>button:hover {
244
  background-color: #45a049;
@@ -251,7 +250,7 @@ st.markdown("""
251
  border: 1px solid #d0d0d0;
252
  }
253
  .sidebar {
254
- background-color: #ffffff;
255
  padding: 1em;
256
  }
257
  .footer {
@@ -264,11 +263,10 @@ st.markdown("""
264
  width: 100%;
265
  border-top: 2px solid #ffffff;
266
  }
267
- .progress-container p {
268
- margin: 5px 0;
269
- }
270
  </style>
271
- """, unsafe_allow_html=True)
 
 
272
 
273
  # Show welcome message with an icon for 3-4 seconds
274
  welcome_message = st.empty()
@@ -285,10 +283,10 @@ with welcome_message.container():
285
  <i class="fa fa-smile-o" aria-hidden="true" style="font-size: 40px;"></i> Welcome to TechPrep!
286
  </div>
287
  """, unsafe_allow_html=True)
288
- time.sleep(4)
289
- welcome_message.empty()
290
 
291
- # Initialize session state
292
  if 'questions' not in st.session_state:
293
  st.session_state.questions = []
294
  if 'answers' not in st.session_state:
@@ -302,7 +300,7 @@ if 'show_results' not in st.session_state:
302
 
303
  # Sidebar Navigation
304
  st.sidebar.title("TechPrep Navigation")
305
- nav_option = st.sidebar.radio("Choose an option:",
306
  ["Generate Questions", "Mock Interview", "Track Progress", "Connect with Resources"])
307
 
308
  # Handling page navigation
@@ -313,7 +311,7 @@ if nav_option == "Generate Questions":
313
  role = st.selectbox("Role", ROLE_OPTIONS)
314
  question_type = st.selectbox("Question Type:", ["Behavioral", "Technical", "Situational", "Case Study", "Problem Solving"])
315
  num_questions = st.number_input("Number of Questions:", min_value=1, max_value=20, value=5)
316
- difficulty = st.selectbox("Difficulty Level:", ["Easy", "Medium", "Hard"])
317
 
318
  if st.button("Generate Questions", key="generate_questions"):
319
  with st.spinner("Generating questions..."):
 
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
 
 
10
  OPENAI_API_KEY = st.secrets["OPENAI_API_KEY"]
11
  GROQ_API_KEY = st.secrets["GROQ_API_KEY"]
12
 
13
+ # Initialize APIs
14
  openai.api_key = OPENAI_API_KEY
15
 
16
  # In-memory storage for progress tracking
 
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
 
 
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
 
 
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
 
 
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
 
 
185
  <p><strong>Mock Interviews Taken:</strong> {progress_data['mock_interviews_taken']}</p>
186
  <p><strong>Feedback Provided:</strong> {progress_data['feedback_provided']}</p>
187
  <p><strong>Tips Retrieved:</strong> {progress_data['tips_retrieved']}</p>
 
188
  </div>
189
  """, unsafe_allow_html=True)
190
 
 
203
 
204
  # Form to connect with career coaches or mentors
205
  with st.form("contact_form"):
206
+ st.write("For personalized assistance, please fill out this form:")
207
+ name = st.text_input("Name")
208
+ email = st.text_input("Email")
209
  message = st.text_area("Message")
210
+ submit_button = st.form_submit_button("Submit")
211
 
212
  if submit_button:
213
+ if not name or not email or not message:
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>'
 
 
 
 
 
221
 
222
+ # Streamlit app layout
223
+ st.set_page_config(page_title="TechPrep", layout="wide")
224
+ st.markdown(
225
+ """
226
  <style>
227
+ body {
228
+ background-color: #e0f7fa; /* Light cyan background color */
229
+ font-family: Arial, sans-serif;
230
+ }
231
  .stButton>button {
232
+ width: 100%;
233
+ height: 3em;
234
+ font-size: 1.2em;
235
  color: white;
236
+ background-color: #4CAF50;
237
  border: none;
 
 
 
 
 
238
  border-radius: 8px;
239
  cursor: pointer;
240
+ transition: background-color 0.3s ease;
241
  }
242
  .stButton>button:hover {
243
  background-color: #45a049;
 
250
  border: 1px solid #d0d0d0;
251
  }
252
  .sidebar {
253
+ background-color: #ffffff; /* Sidebar background color */
254
  padding: 1em;
255
  }
256
  .footer {
 
263
  width: 100%;
264
  border-top: 2px solid #ffffff;
265
  }
 
 
 
266
  </style>
267
+ """,
268
+ unsafe_allow_html=True
269
+ )
270
 
271
  # Show welcome message with an icon for 3-4 seconds
272
  welcome_message = st.empty()
 
283
  <i class="fa fa-smile-o" aria-hidden="true" style="font-size: 40px;"></i> Welcome to TechPrep!
284
  </div>
285
  """, unsafe_allow_html=True)
286
+ time.sleep(4) # Wait for 4 seconds
287
+ welcome_message.empty() # Remove the welcome message
288
 
289
+ # Initialize session state for questions, answers, and current index
290
  if 'questions' not in st.session_state:
291
  st.session_state.questions = []
292
  if 'answers' not in st.session_state:
 
300
 
301
  # Sidebar Navigation
302
  st.sidebar.title("TechPrep Navigation")
303
+ nav_option = st.sidebar.radio("Choose an option:",
304
  ["Generate Questions", "Mock Interview", "Track Progress", "Connect with Resources"])
305
 
306
  # Handling page navigation
 
311
  role = st.selectbox("Role", ROLE_OPTIONS)
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:", ["Basic", "Medium", "Complex"])
315
 
316
  if st.button("Generate Questions", key="generate_questions"):
317
  with st.spinner("Generating questions..."):