AdithyaSNair commited on
Commit
0c0b5ad
·
verified ·
1 Parent(s): 30a7c0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -26
app.py CHANGED
@@ -10,6 +10,9 @@ import sqlite3
10
  from datetime import datetime, timedelta
11
  import re
12
  import os
 
 
 
13
 
14
  GROQ_API_KEY = st.secrets["GROQ_API_KEY"]
15
  RAPIDAPI_KEY = st.secrets["RAPIDAPI_KEY"]
@@ -313,9 +316,12 @@ def parse_duration(duration_str):
313
  except:
314
  return 0
315
 
 
 
 
316
 
317
  @st.cache_data(ttl=86400) # Cache results for 1 day
318
- def search_youtube_videos(query, max_results=3, video_duration="short", order="relevance"):
319
  """
320
  Searches YouTube for videos related to the query with additional filters.
321
 
@@ -363,6 +369,9 @@ def embed_youtube_videos(video_urls, topic):
363
  for url in video_urls:
364
  st.video(url)
365
 
 
 
 
366
 
367
  def init_db():
368
  """
@@ -469,6 +478,10 @@ def generate_learning_path(career_goal, current_skills):
469
  st.error(f"Error generating learning path: {e}")
470
  return ""
471
 
 
 
 
 
472
  def email_generator_page():
473
  st.header("Automated Email Generator")
474
 
@@ -765,7 +778,7 @@ def interview_preparation_module():
765
  st.header("Interview Preparation")
766
 
767
  st.write("""
768
- Prepare for your interviews with tailored mock questions, expert tips, and curated video resources.
769
  """)
770
 
771
  # Create two columns for input fields
@@ -780,33 +793,34 @@ def interview_preparation_module():
780
  st.error("Please enter both job title and company name.")
781
  return
782
  with st.spinner("Generating questions..."):
783
- # Example prompt to generate interview topics using LLM
784
  prompt = f"""
785
- Generate a list of 5 key topics that a candidate should prepare for an interview for the position of {job_title} at {company}. Each topic should be a concise phrase.
786
  """
 
787
  try:
788
- # Invoke the LLM to get topics
789
- topics = llm.invoke(prompt).content.strip().split('\n')
790
- topics = [topic.strip('- ').strip() for topic in topics if topic.strip()]
791
- st.subheader("Key Interview Topics:")
792
- for idx, topic in enumerate(topics, 1):
793
- st.markdown(f"{idx}. {topic}")
794
-
795
- st.subheader("Recommended YouTube Videos:")
796
- for topic in topics:
797
- video_urls = search_youtube_videos(query=topic, max_results=2)
798
- if video_urls:
799
- embed_youtube_videos(video_urls, topic)
800
- else:
801
- st.write(f"No videos found for **{topic}**.")
802
  except Exception as e:
803
- st.error(f"Error generating interview topics: {e}")
804
 
805
  def personalized_learning_paths_module():
806
  st.header("Personalized Learning Paths")
807
 
808
  st.write("""
809
- Receive tailored learning plans to help you acquire the skills needed for your desired career.
810
  """)
811
 
812
  # Create two columns for input fields
@@ -825,6 +839,27 @@ def personalized_learning_paths_module():
825
  if learning_path:
826
  st.subheader("Your Personalized Learning Path:")
827
  st.write(learning_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
828
  else:
829
  st.error("Failed to generate learning path.")
830
 
@@ -1117,6 +1152,9 @@ def chatbot_support_page():
1117
  else:
1118
  message(chat['message'], is_user=False, avatar_style="bottts")
1119
 
 
 
 
1120
 
1121
  def main_app():
1122
  # Apply a consistent theme or style
@@ -1135,13 +1173,23 @@ def main_app():
1135
  unsafe_allow_html=True
1136
  )
1137
 
1138
- # Sidebar Navigation
1139
  with st.sidebar:
1140
- selected = st.selectbox(
1141
- "Main Menu",
1142
- ["Email Generator", "Cover Letter Generator", "Resume Analysis", "Application Tracking",
1143
- "Interview Preparation", "Personalized Learning Paths", "Networking Opportunities",
1144
- "Salary Estimation", "Feedback", "Gamification", "Resource Library", "Success Stories", "Chatbot Support", "Help"]
 
 
 
 
 
 
 
 
 
 
1145
  )
1146
 
1147
  # Route to the selected page
 
10
  from datetime import datetime, timedelta
11
  import re
12
  import os
13
+ from streamlit_option_menu import option_menu
14
+ import fitz # PyMuPDF
15
+ from bs4 import BeautifulSoup
16
 
17
  GROQ_API_KEY = st.secrets["GROQ_API_KEY"]
18
  RAPIDAPI_KEY = st.secrets["RAPIDAPI_KEY"]
 
316
  except:
317
  return 0
318
 
319
+ # -------------------------------
320
+ # YouTube Data API Integration
321
+ # -------------------------------
322
 
323
  @st.cache_data(ttl=86400) # Cache results for 1 day
324
+ def search_youtube_videos(query, max_results=3, video_duration="long", order="relevance"):
325
  """
326
  Searches YouTube for videos related to the query with additional filters.
327
 
 
369
  for url in video_urls:
370
  st.video(url)
371
 
372
+ # -------------------------------
373
+ # Database Functions
374
+ # -------------------------------
375
 
376
  def init_db():
377
  """
 
478
  st.error(f"Error generating learning path: {e}")
479
  return ""
480
 
481
+ # -------------------------------
482
+ # Page Functions
483
+ # -------------------------------
484
+
485
  def email_generator_page():
486
  st.header("Automated Email Generator")
487
 
 
778
  st.header("Interview Preparation")
779
 
780
  st.write("""
781
+ Prepare for your interviews with tailored mock questions and expert answers.
782
  """)
783
 
784
  # Create two columns for input fields
 
793
  st.error("Please enter both job title and company name.")
794
  return
795
  with st.spinner("Generating questions..."):
796
+ # Prompt to generate 50 interview questions with answers
797
  prompt = f"""
798
+ Generate a list of 50 interview questions along with their answers for the position of {job_title} at {company}. Each question should be followed by a concise and professional answer.
799
  """
800
+
801
  try:
802
+ # Invoke the LLM to get questions and answers
803
+ qa_text = llm.invoke(prompt).content.strip()
804
+ # Split into question-answer pairs
805
+ qa_pairs = qa_text.split('\n\n')
806
+ st.subheader("Mock Interview Questions and Answers:")
807
+ for idx, qa in enumerate(qa_pairs, 1):
808
+ if qa.strip():
809
+ parts = qa.split('\n', 1)
810
+ if len(parts) == 2:
811
+ question = parts[0].strip()
812
+ answer = parts[1].strip()
813
+ st.markdown(f"**Q{idx}: {question}**")
814
+ st.markdown(f"**A:** {answer}")
815
+ st.write("---")
816
  except Exception as e:
817
+ st.error(f"Error generating interview questions: {e}")
818
 
819
  def personalized_learning_paths_module():
820
  st.header("Personalized Learning Paths")
821
 
822
  st.write("""
823
+ Receive tailored learning plans to help you acquire the skills needed for your desired career, complemented with curated video resources.
824
  """)
825
 
826
  # Create two columns for input fields
 
839
  if learning_path:
840
  st.subheader("Your Personalized Learning Path:")
841
  st.write(learning_path)
842
+
843
+ # Assuming the learning path is divided into modules/subparts separated by newlines or numbering
844
+ # We'll extract subparts and embed YouTube videos for each
845
+ # Example format:
846
+ # 1. Module One
847
+ # 2. Module Two
848
+ # etc.
849
+
850
+ # Split learning path into modules
851
+ modules = re.split(r'\d+\.\s+', learning_path)
852
+ modules = [module.strip() for module in modules if module.strip()]
853
+
854
+ st.subheader("Recommended YouTube Videos for Each Module:")
855
+ for module in modules:
856
+ # Search for long videos related to the module
857
+ video_urls = search_youtube_videos(query=module, max_results=2, video_duration="long")
858
+ if video_urls:
859
+ st.markdown(f"### {module}")
860
+ embed_youtube_videos(video_urls, module)
861
+ else:
862
+ st.write(f"No videos found for **{module}**.")
863
  else:
864
  st.error("Failed to generate learning path.")
865
 
 
1152
  else:
1153
  message(chat['message'], is_user=False, avatar_style="bottts")
1154
 
1155
+ # -------------------------------
1156
+ # Main App Function
1157
+ # -------------------------------
1158
 
1159
  def main_app():
1160
  # Apply a consistent theme or style
 
1173
  unsafe_allow_html=True
1174
  )
1175
 
1176
+ # Sidebar Navigation using streamlit_option_menu
1177
  with st.sidebar:
1178
+ selected = option_menu(
1179
+ menu_title="Main Menu",
1180
+ options=["Email Generator", "Cover Letter Generator", "Resume Analysis", "Application Tracking",
1181
+ "Interview Preparation", "Personalized Learning Paths", "Networking Opportunities",
1182
+ "Salary Estimation", "Feedback", "Gamification", "Resource Library", "Success Stories", "Chatbot Support", "Help"],
1183
+ icons=["envelope", "file-earmark-text", "file-person", "briefcase", "gear",
1184
+ "book", "people", "currency-dollar", "chat-left-text", "trophy", "collection", "star", "chat", "question-circle"],
1185
+ menu_icon="cast",
1186
+ default_index=0,
1187
+ styles={
1188
+ "container": {"padding": "5!important", "background-color": "#2e7bcf"},
1189
+ "icon": {"color": "white", "font-size": "18px"},
1190
+ "nav-link": {"font-size": "16px", "text-align": "left", "margin": "0px", "--hover-color": "#6b9eff"},
1191
+ "nav-link-selected": {"background-color": "#1e5aab"},
1192
+ }
1193
  )
1194
 
1195
  # Route to the selected page