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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -32
app.py CHANGED
@@ -1,12 +1,14 @@
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
@@ -18,7 +20,8 @@ progress_data = {
18
  },
19
  "mock_interviews_taken": 0,
20
  "feedback_provided": 0,
21
- "tips_retrieved": 0
 
22
  }
23
 
24
  # Define list of roles for dropdown
@@ -40,6 +43,8 @@ def get_llm(model_choice):
40
  return ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_API_KEY)
41
  elif model_choice == "OpenAI":
42
  return None
 
 
43
  else:
44
  raise ValueError("Unsupported model choice.")
45
 
@@ -59,6 +64,10 @@ def generate_questions(model_choice, role, question_type, num_questions, difficu
59
  llm = get_llm(model_choice)
60
  response = llm.invoke(prompt)
61
  return response.content.split("\n")
 
 
 
 
62
  else:
63
  raise ValueError("Unsupported model choice.")
64
 
@@ -75,6 +84,10 @@ def provide_feedback(model_choice, answer):
75
  llm = get_llm(model_choice)
76
  response = llm.invoke(prompt)
77
  return response.content
 
 
 
 
78
  else:
79
  raise ValueError("Unsupported model choice.")
80
 
@@ -91,6 +104,10 @@ def get_tips(model_choice, role):
91
  llm = get_llm(model_choice)
92
  response = llm.invoke(prompt)
93
  return response.content
 
 
 
 
94
  else:
95
  raise ValueError("Unsupported model choice.")
96
 
@@ -168,6 +185,7 @@ def track_progress():
168
  <p><strong>Mock Interviews Taken:</strong> {progress_data['mock_interviews_taken']}</p>
169
  <p><strong>Feedback Provided:</strong> {progress_data['feedback_provided']}</p>
170
  <p><strong>Tips Retrieved:</strong> {progress_data['tips_retrieved']}</p>
 
171
  </div>
172
  """, unsafe_allow_html=True)
173
 
@@ -186,40 +204,41 @@ def connect_resources():
186
 
187
  # Form to connect with career coaches or mentors
188
  with st.form("contact_form"):
189
- st.write("For personalized assistance, please fill out this form:")
190
- name = st.text_input("Name")
191
- email = st.text_input("Email")
192
  message = st.text_area("Message")
193
- submit_button = st.form_submit_button("Submit")
194
 
195
  if submit_button:
196
- if not name or not email or not message:
197
- st.error("Please fill out all fields.")
 
198
  else:
199
- st.success("Thank you for contacting us! We will get back to you soon.")
200
 
201
- def style_output(text, color):
202
- return f'<div class="output-container"><span style="color: {color}; font-weight: bold;">{text}</span></div>'
203
-
204
- # Streamlit app layout
205
- st.set_page_config(page_title="TechPrep", layout="wide")
206
- st.markdown(
207
  """
 
 
 
208
  <style>
209
- body {
210
- background-color: #e0f7fa; /* Light cyan background color */
211
- font-family: Arial, sans-serif;
212
- }
213
  .stButton>button {
214
- width: 100%;
215
- height: 3em;
216
- font-size: 1.2em;
217
- color: white;
218
  background-color: #4CAF50;
 
219
  border: none;
 
 
 
 
 
220
  border-radius: 8px;
221
  cursor: pointer;
222
- transition: background-color 0.3s ease;
223
  }
224
  .stButton>button:hover {
225
  background-color: #45a049;
@@ -232,7 +251,7 @@ st.markdown(
232
  border: 1px solid #d0d0d0;
233
  }
234
  .sidebar {
235
- background-color: #ffffff; /* Sidebar background color */
236
  padding: 1em;
237
  }
238
  .footer {
@@ -245,10 +264,11 @@ st.markdown(
245
  width: 100%;
246
  border-top: 2px solid #ffffff;
247
  }
 
 
 
248
  </style>
249
- """,
250
- unsafe_allow_html=True
251
- )
252
 
253
  # Show welcome message with an icon for 3-4 seconds
254
  welcome_message = st.empty()
@@ -265,10 +285,10 @@ with welcome_message.container():
265
  <i class="fa fa-smile-o" aria-hidden="true" style="font-size: 40px;"></i> Welcome to TechPrep!
266
  </div>
267
  """, unsafe_allow_html=True)
268
- time.sleep(4) # Wait for 4 seconds
269
- welcome_message.empty() # Remove the welcome message
270
 
271
- # Initialize session state for questions, answers, and current index
272
  if 'questions' not in st.session_state:
273
  st.session_state.questions = []
274
  if 'answers' not in st.session_state:
@@ -282,14 +302,14 @@ if 'show_results' not in st.session_state:
282
 
283
  # Sidebar Navigation
284
  st.sidebar.title("TechPrep Navigation")
285
- nav_option = st.sidebar.radio("Choose an option:",
286
  ["Generate Questions", "Mock Interview", "Track Progress", "Connect with Resources"])
287
 
288
  # Handling page navigation
289
  if nav_option == "Generate Questions":
290
  st.header("📝 Generate Interview Questions")
291
 
292
- model_choice = st.selectbox("Choose Model:", ["OpenAI", "Gemini"])
293
  role = st.selectbox("Role", ROLE_OPTIONS)
294
  question_type = st.selectbox("Question Type:", ["Behavioral", "Technical", "Situational", "Case Study", "Problem Solving"])
295
  num_questions = st.number_input("Number of Questions:", min_value=1, max_value=20, value=5)
 
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
 
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 OpenAI
14
  openai.api_key = OPENAI_API_KEY
 
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
 
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 GROQ_API_KEY # Example placeholder
48
  else:
49
  raise ValueError("Unsupported model choice.")
50
 
 
64
  llm = get_llm(model_choice)
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
 
 
84
  llm = get_llm(model_choice)
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
 
 
104
  llm = get_llm(model_choice)
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
  <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
 
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
  border: 1px solid #d0d0d0;
252
  }
253
  .sidebar {
254
+ background-color: #ffffff;
255
  padding: 1em;
256
  }
257
  .footer {
 
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
  <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
 
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
309
  if nav_option == "Generate Questions":
310
  st.header("📝 Generate Interview Questions")
311
 
312
+ model_choice = st.selectbox("Choose Model:", ["OpenAI", "Gemini", "Groq"])
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)