rashid01 commited on
Commit
afccb5b
·
verified ·
1 Parent(s): 0230a67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -136
app.py CHANGED
@@ -1,16 +1,21 @@
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
15
  progress_data = {
16
  "questions_solved": {
@@ -26,6 +31,8 @@ def get_llm(model_choice):
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
 
@@ -40,11 +47,15 @@ def generate_questions(model_choice, role, question_type, num_questions, difficu
40
  prompt=prompt,
41
  max_tokens=150
42
  )
43
- return response.choices[0].text.strip()
44
  elif model_choice == "Gemini":
45
  llm = get_llm(model_choice)
46
  response = llm.invoke(prompt)
47
- return response.content
 
 
 
 
48
  else:
49
  raise ValueError("Unsupported model choice.")
50
 
@@ -61,6 +72,10 @@ def provide_feedback(model_choice, answer):
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,6 +92,10 @@ def get_tips(model_choice, role):
77
  llm = get_llm(model_choice)
78
  response = llm.invoke(prompt)
79
  return response.content
 
 
 
 
80
  else:
81
  raise ValueError("Unsupported model choice.")
82
 
@@ -185,139 +204,6 @@ def connect_resources():
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>'
189
-
190
- # Streamlit app layout
191
- st.set_page_config(page_title="TechPrep", layout="wide")
192
- st.markdown(
193
- """
194
- <style>
195
- body {
196
- background-color: #e0f7fa; /* Light cyan background color */
197
- font-family: Arial, sans-serif;
198
- }
199
- .stButton>button {
200
- width: 100%;
201
- height: 3em;
202
- font-size: 1.2em;
203
- color: white;
204
- background-color: #4CAF50;
205
- border: none;
206
- border-radius: 8px;
207
- cursor: pointer;
208
- transition: background-color 0.3s ease;
209
- }
210
- .stButton>button:hover {
211
- background-color: #45a049;
212
- }
213
- .output-container {
214
- border: 2px solid #2196F3;
215
- border-radius: 8px;
216
- padding: 15px;
217
- margin: 15px 0;
218
- background-color: #f1f1f1;
219
- }
220
- .progress-container {
221
- border: 2px solid #2196F3;
222
- border-radius: 8px;
223
- padding: 15px;
224
- margin: 15px 0;
225
- background-color: #e3f2fd;
226
- }
227
- .sidebar {
228
- background-color: #ffffff; /* Sidebar background color */
229
- padding: 1em;
230
- }
231
- .footer {
232
- background-color: #4CAF50;
233
- color: white;
234
- text-align: center;
235
- padding: 1em;
236
- position: fixed;
237
- bottom: 0;
238
- width: 100%;
239
- border-top: 2px solid #ffffff;
240
- }
241
- </style>
242
- """,
243
- unsafe_allow_html=True
244
- )
245
 
246
- # Show welcome message with an icon for 3-4 seconds
247
- welcome_message = st.empty()
248
- with welcome_message.container():
249
- st.markdown("""
250
- <div style="
251
- text-align: center;
252
- padding: 20px;
253
- background-color: #4CAF50;
254
- color: white;
255
- border-radius: 8px;
256
- font-size: 24px;
257
- ">
258
- <i class="fa fa-smile-o" aria-hidden="true" style="font-size: 40px;"></i> Welcome to TechPrep!
259
- </div>
260
- """, unsafe_allow_html=True)
261
- time.sleep(4) # Wait for 4 seconds
262
- welcome_message.empty() # Remove the welcome message
263
-
264
- # Sidebar for additional links
265
- with st.sidebar:
266
- st.title("Menu")
267
- st.markdown("<h3>About Us</h3><p>We help you prepare for job interviews with simulated questions and feedback.</p>", unsafe_allow_html=True)
268
- st.markdown("<h3>Sponsored By</h3><p>Your trusted career preparation partner.</p>", unsafe_allow_html=True)
269
- st.markdown("<h3>Contact Us</h3><p>For support, email us at <a href='mailto:support@example.com'>support@example.com</a>.</p>", unsafe_allow_html=True)
270
-
271
- st.title("💼 TechPrep")
272
-
273
- model_choice = st.selectbox("Select AI Model", ["Gemini", "OpenAI"], key="select_model")
274
- role = st.selectbox("Select Role", ["Software Developer", "Data Analyst", "Marketing Manager", "Project Manager", "UX Designer"], key="select_role")
275
- question_type = st.selectbox("Select Question Type", ["Behavioral", "Technical", "Situational", "Case Study", "Problem Solving"], key="select_question_type")
276
- num_questions = st.slider("Number of Questions", 1, 10, key="slider_num_questions")
277
- difficulty = st.selectbox("Select Difficulty Level", ["Easy", "Medium", "Hard"], key="select_difficulty")
278
-
279
- st.header("📝 Generate Interview Questions")
280
- if st.button("Generate Questions", key="generate_questions"):
281
- with st.spinner("Generating questions..."):
282
- questions = generate_questions(model_choice, role, question_type, num_questions, difficulty)
283
- st.markdown(style_output("Questions Generated:", "#4CAF50"), unsafe_allow_html=True)
284
- st.write(questions)
285
- progress_data["questions_solved"][question_type] += num_questions
286
-
287
- st.header("🗣️ Provide Feedback")
288
- answer = st.text_area("Submit Your Answer", key="text_area_answer")
289
- if st.button("Submit Answer", key="submit_answer"):
290
- if not answer:
291
- st.error("Please enter an answer to receive feedback.")
292
- else:
293
- with st.spinner("Providing feedback..."):
294
- feedback = provide_feedback(model_choice, answer)
295
- st.markdown(style_output("Feedback Received:", "#FF5722"), unsafe_allow_html=True)
296
- st.write(feedback)
297
- progress_data["feedback_provided"] += 1
298
-
299
- st.header("💡 Interview Tips")
300
- if st.button("Get Tips", key="get_tips"):
301
- with st.spinner("Fetching tips..."):
302
- tips = get_tips(model_choice, role)
303
- st.markdown(style_output("Tips Received:", "#2196F3"), unsafe_allow_html=True)
304
- st.write(tips)
305
- progress_data["tips_retrieved"] += 1
306
-
307
- st.header("📅 Schedule Mock Interview")
308
- schedule_mock_interview()
309
-
310
- st.header("📈 Progress and Resources")
311
- col1, col2 = st.columns(2)
312
- with col1:
313
- track_progress()
314
- with col2:
315
- connect_resources()
316
-
317
- # Footer
318
- st.markdown("""
319
- <div class="footer">
320
- <p>&copy; 2024 TechPrep. All rights reserved.</p>
321
- </div>
322
- """, unsafe_allow_html=True)
323
 
 
1
  import streamlit as st
2
  import openai
3
  from langchain_google_genai import ChatGoogleGenerativeAI
4
+ from langchain_groq import ChatGroqGenerativeAI # Assuming a similar module exists 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"] # Assume you have an API key for Groq
12
 
13
  # Initialize OpenAI
14
  openai.api_key = OPENAI_API_KEY
15
 
16
+ # Initialize Groq
17
+ groq_llm = ChatGroqGenerativeAI(model="groq-pro", groq_api_key=GROQ_API_KEY)
18
+
19
  # In-memory storage for progress tracking
20
  progress_data = {
21
  "questions_solved": {
 
31
  return ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_API_KEY)
32
  elif model_choice == "OpenAI":
33
  return None
34
+ elif model_choice == "Groq":
35
+ return groq_llm
36
  else:
37
  raise ValueError("Unsupported model choice.")
38
 
 
47
  prompt=prompt,
48
  max_tokens=150
49
  )
50
+ return response.choices[0].text.strip().split('\n')
51
  elif model_choice == "Gemini":
52
  llm = get_llm(model_choice)
53
  response = llm.invoke(prompt)
54
+ return response.content.split('\n')
55
+ elif model_choice == "Groq":
56
+ llm = get_llm(model_choice)
57
+ response = llm.invoke(prompt)
58
+ return response.content.split('\n')
59
  else:
60
  raise ValueError("Unsupported model choice.")
61
 
 
72
  llm = get_llm(model_choice)
73
  response = llm.invoke(prompt)
74
  return response.content
75
+ elif model_choice == "Groq":
76
+ llm = get_llm(model_choice)
77
+ response = llm.invoke(prompt)
78
+ return response.content
79
  else:
80
  raise ValueError("Unsupported model choice.")
81
 
 
92
  llm = get_llm(model_choice)
93
  response = llm.invoke(prompt)
94
  return response.content
95
+ elif model_choice == "Groq":
96
+ llm = get_llm(model_choice)
97
+ response = llm.invoke(prompt)
98
+ return response.content
99
  else:
100
  raise ValueError("Unsupported model choice.")
101
 
 
204
  st.success("Thank you for contacting us! We will get back to you soon.")
205
 
206
  def style_output(text, color):
207
+ return f'<div class="output-container"><span style="color: {color}; font-weight: bold;">{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209