Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
from langchain_groq import ChatGroq
|
@@ -12,21 +14,30 @@ from streamlit_option_menu import option_menu
|
|
12 |
import fitz # PyMuPDF
|
13 |
from bs4 import BeautifulSoup
|
14 |
|
|
|
|
|
|
|
15 |
|
16 |
GROQ_API_KEY = st.secrets["GROQ_API_KEY"]
|
17 |
RAPIDAPI_KEY = st.secrets["RAPIDAPI_KEY"]
|
18 |
YOUTUBE_API_KEY = st.secrets["YOUTUBE_API_KEY"]
|
19 |
-
ADZUNA_APP_ID = st.secrets["ADZUNA_APP_ID"]
|
20 |
-
ADZUNA_APP_KEY = st.secrets["ADZUNA_APP_KEY"]
|
21 |
THE_MUSE_API_KEY = st.secrets.get("THE_MUSE_API_KEY", "")
|
22 |
BLS_API_KEY = st.secrets.get("BLS_API_KEY", "")
|
23 |
|
|
|
|
|
|
|
|
|
24 |
llm = ChatGroq(
|
25 |
temperature=0,
|
26 |
groq_api_key=GROQ_API_KEY,
|
27 |
model_name="llama-3.1-70b-versatile"
|
28 |
)
|
29 |
|
|
|
|
|
|
|
|
|
30 |
@st.cache_data(ttl=3600)
|
31 |
def extract_text_from_pdf(pdf_file):
|
32 |
"""
|
@@ -348,49 +359,15 @@ def fetch_muse_jobs_api(job_title, location=None, category=None, max_results=50)
|
|
348 |
st.error(f"Error fetching jobs from The Muse: {e}")
|
349 |
return []
|
350 |
|
351 |
-
# Adzuna API Integration
|
352 |
-
@st.cache_data(ttl=86400) # Cache results for 1 day
|
353 |
-
def fetch_adzuna_jobs_api(job_title, location="india", category=None, max_results=50):
|
354 |
-
"""
|
355 |
-
Fetches job listings from Adzuna API based on user preferences.
|
356 |
-
|
357 |
-
Args:
|
358 |
-
job_title (str): The job title to search for.
|
359 |
-
location (str, optional): The job location. Defaults to "india".
|
360 |
-
category (str, optional): The job category. Defaults to None.
|
361 |
-
max_results (int, optional): Maximum number of jobs to fetch. Defaults to 50.
|
362 |
-
|
363 |
-
Returns:
|
364 |
-
list: A list of job dictionaries.
|
365 |
-
"""
|
366 |
-
base_url = f"https://api.adzuna.com/v1/api/jobs/{location}/search/1"
|
367 |
-
params = {
|
368 |
-
"app_id": ADZUNA_APP_ID,
|
369 |
-
"app_key": ADZUNA_APP_KEY,
|
370 |
-
"what": job_title,
|
371 |
-
"results_per_page": max_results,
|
372 |
-
"content-type": "application/json"
|
373 |
-
}
|
374 |
-
if category:
|
375 |
-
params["category"] = category
|
376 |
-
try:
|
377 |
-
response = requests.get(base_url, params=params)
|
378 |
-
response.raise_for_status()
|
379 |
-
jobs = response.json().get("results", [])
|
380 |
-
return jobs
|
381 |
-
except requests.exceptions.RequestException as e:
|
382 |
-
st.error(f"Error fetching jobs from Adzuna: {e}")
|
383 |
-
return []
|
384 |
-
|
385 |
# Indeed API Integration
|
386 |
@st.cache_data(ttl=86400) # Cache results for 1 day
|
387 |
-
def fetch_indeed_jobs_api(job_title,
|
388 |
"""
|
389 |
Fetches job listings from Indeed API based on user preferences.
|
390 |
|
391 |
Args:
|
392 |
job_title (str): The job title to search for (e.g., "Front end developer").
|
393 |
-
|
394 |
sort (str, optional): Sorting parameter (e.g., "-1" for relevance). Defaults to "-1".
|
395 |
page_size (int, optional): Number of results per page. Defaults to 50.
|
396 |
|
@@ -403,7 +380,7 @@ def fetch_indeed_jobs_api(job_title, country="CA", sort="-1", page_size=50):
|
|
403 |
encoded_job_title = re.sub(r'\s+', '+', job_title.strip())
|
404 |
|
405 |
querystring = {
|
406 |
-
"country":
|
407 |
"sort": sort,
|
408 |
"page_size": str(page_size),
|
409 |
"title": encoded_job_title # Assuming the API accepts a 'title' parameter for job titles
|
@@ -470,7 +447,7 @@ def recommend_indeed_jobs(user_skills, user_preferences):
|
|
470 |
|
471 |
def recommend_jobs(user_skills, user_preferences):
|
472 |
"""
|
473 |
-
Recommends jobs based on user skills and preferences from Remotive, The Muse,
|
474 |
|
475 |
Args:
|
476 |
user_skills (list): List of user's skills.
|
@@ -485,14 +462,11 @@ def recommend_jobs(user_skills, user_preferences):
|
|
485 |
# Fetch from The Muse
|
486 |
muse_jobs = fetch_muse_jobs_api(user_preferences.get("job_title", ""), user_preferences.get("location"), user_preferences.get("category"))
|
487 |
|
488 |
-
# Fetch from Adzuna
|
489 |
-
adzuna_jobs = fetch_adzuna_jobs_api(user_preferences.get("job_title", ""), user_preferences.get("location", "india"), user_preferences.get("category"))
|
490 |
-
|
491 |
# Fetch from Indeed
|
492 |
indeed_jobs = recommend_indeed_jobs(user_skills, user_preferences)
|
493 |
|
494 |
# Combine all job listings
|
495 |
-
combined_jobs = remotive_jobs + muse_jobs +
|
496 |
|
497 |
# Remove duplicates based on job URL
|
498 |
unique_jobs = {}
|
@@ -737,32 +711,7 @@ def embed_youtube_videos(video_urls, module_name):
|
|
737 |
# Job Recommendations and BLS Integration
|
738 |
# -------------------------------
|
739 |
|
740 |
-
|
741 |
-
st.header("📈 Labor Market Insights")
|
742 |
-
|
743 |
-
st.write("""
|
744 |
-
Gain valuable insights into the current labor market trends, employment rates, and industry growth to make informed career decisions.
|
745 |
-
""")
|
746 |
-
|
747 |
-
# Define BLS Series IDs based on desired data
|
748 |
-
# Example: Unemployment rate (Series ID: LNS14000000)
|
749 |
-
# Reference: https://www.bls.gov/web/laus/laumstrk.htm
|
750 |
-
unemployment_series_id = "LNS14000000" # Unemployment Rate
|
751 |
-
employment_series_id = "CEU0000000001" # Total Employment
|
752 |
-
|
753 |
-
# Display Unemployment Rate
|
754 |
-
display_bls_data(unemployment_series_id, "Unemployment Rate (%)")
|
755 |
-
|
756 |
-
# Display Total Employment
|
757 |
-
display_bls_data(employment_series_id, "Total Employment")
|
758 |
-
|
759 |
-
# Additional Insights
|
760 |
-
st.subheader("💡 Additional Insights")
|
761 |
-
st.write("""
|
762 |
-
- **Industry Growth:** Understanding which industries are growing can help you target your job search effectively.
|
763 |
-
- **Salary Trends:** Keeping an eye on salary trends ensures that you negotiate effectively and align your expectations.
|
764 |
-
- **Geographical Demand:** Some regions may have higher demand for certain roles, guiding your location preferences.
|
765 |
-
""")
|
766 |
|
767 |
# -------------------------------
|
768 |
# Page Functions
|
@@ -1125,7 +1074,7 @@ def job_recommendations_module():
|
|
1125 |
}
|
1126 |
|
1127 |
with st.spinner("🔄 Fetching job recommendations..."):
|
1128 |
-
# Fetch recommendations from all APIs
|
1129 |
recommended_jobs = recommend_jobs(user_skills, user_preferences)
|
1130 |
|
1131 |
if recommended_jobs:
|
@@ -1541,5 +1490,6 @@ def main_app():
|
|
1541 |
elif selected == "Help":
|
1542 |
help_page()
|
1543 |
|
|
|
1544 |
if __name__ == "__main__":
|
1545 |
main_app()
|
|
|
1 |
+
# app.py
|
2 |
+
|
3 |
import streamlit as st
|
4 |
import requests
|
5 |
from langchain_groq import ChatGroq
|
|
|
14 |
import fitz # PyMuPDF
|
15 |
from bs4 import BeautifulSoup
|
16 |
|
17 |
+
# -------------------------------
|
18 |
+
# API Key Retrieval
|
19 |
+
# -------------------------------
|
20 |
|
21 |
GROQ_API_KEY = st.secrets["GROQ_API_KEY"]
|
22 |
RAPIDAPI_KEY = st.secrets["RAPIDAPI_KEY"]
|
23 |
YOUTUBE_API_KEY = st.secrets["YOUTUBE_API_KEY"]
|
|
|
|
|
24 |
THE_MUSE_API_KEY = st.secrets.get("THE_MUSE_API_KEY", "")
|
25 |
BLS_API_KEY = st.secrets.get("BLS_API_KEY", "")
|
26 |
|
27 |
+
# -------------------------------
|
28 |
+
# Initialize Language Model
|
29 |
+
# -------------------------------
|
30 |
+
|
31 |
llm = ChatGroq(
|
32 |
temperature=0,
|
33 |
groq_api_key=GROQ_API_KEY,
|
34 |
model_name="llama-3.1-70b-versatile"
|
35 |
)
|
36 |
|
37 |
+
# -------------------------------
|
38 |
+
# Function Definitions
|
39 |
+
# -------------------------------
|
40 |
+
|
41 |
@st.cache_data(ttl=3600)
|
42 |
def extract_text_from_pdf(pdf_file):
|
43 |
"""
|
|
|
359 |
st.error(f"Error fetching jobs from The Muse: {e}")
|
360 |
return []
|
361 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
# Indeed API Integration
|
363 |
@st.cache_data(ttl=86400) # Cache results for 1 day
|
364 |
+
def fetch_indeed_jobs_api(job_title, location="CA", sort="-1", page_size=50):
|
365 |
"""
|
366 |
Fetches job listings from Indeed API based on user preferences.
|
367 |
|
368 |
Args:
|
369 |
job_title (str): The job title to search for (e.g., "Front end developer").
|
370 |
+
location (str, optional): The country code (e.g., "CA" for Canada). Defaults to "CA".
|
371 |
sort (str, optional): Sorting parameter (e.g., "-1" for relevance). Defaults to "-1".
|
372 |
page_size (int, optional): Number of results per page. Defaults to 50.
|
373 |
|
|
|
380 |
encoded_job_title = re.sub(r'\s+', '+', job_title.strip())
|
381 |
|
382 |
querystring = {
|
383 |
+
"country": location,
|
384 |
"sort": sort,
|
385 |
"page_size": str(page_size),
|
386 |
"title": encoded_job_title # Assuming the API accepts a 'title' parameter for job titles
|
|
|
447 |
|
448 |
def recommend_jobs(user_skills, user_preferences):
|
449 |
"""
|
450 |
+
Recommends jobs based on user skills and preferences from Remotive, The Muse, and Indeed APIs.
|
451 |
|
452 |
Args:
|
453 |
user_skills (list): List of user's skills.
|
|
|
462 |
# Fetch from The Muse
|
463 |
muse_jobs = fetch_muse_jobs_api(user_preferences.get("job_title", ""), user_preferences.get("location"), user_preferences.get("category"))
|
464 |
|
|
|
|
|
|
|
465 |
# Fetch from Indeed
|
466 |
indeed_jobs = recommend_indeed_jobs(user_skills, user_preferences)
|
467 |
|
468 |
# Combine all job listings
|
469 |
+
combined_jobs = remotive_jobs + muse_jobs + indeed_jobs
|
470 |
|
471 |
# Remove duplicates based on job URL
|
472 |
unique_jobs = {}
|
|
|
711 |
# Job Recommendations and BLS Integration
|
712 |
# -------------------------------
|
713 |
|
714 |
+
# Removed Adzuna-related functions as per request
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
715 |
|
716 |
# -------------------------------
|
717 |
# Page Functions
|
|
|
1074 |
}
|
1075 |
|
1076 |
with st.spinner("🔄 Fetching job recommendations..."):
|
1077 |
+
# Fetch recommendations from all APIs (Remotive, The Muse, Indeed)
|
1078 |
recommended_jobs = recommend_jobs(user_skills, user_preferences)
|
1079 |
|
1080 |
if recommended_jobs:
|
|
|
1490 |
elif selected == "Help":
|
1491 |
help_page()
|
1492 |
|
1493 |
+
|
1494 |
if __name__ == "__main__":
|
1495 |
main_app()
|