|
import threading |
|
import time |
|
from transformers import pipeline |
|
from datasets import load_dataset |
|
import streamlit as st |
|
|
|
|
|
jobs_dataset = load_dataset("lukebarousse/data_jobs")["train"] |
|
universities_url = "https://www.4icu.org/top-universities-world/" |
|
courses_dataset = load_dataset("azrai99/coursera-course-dataset")["train"] |
|
|
|
|
|
def run_with_timeout(target_func, timeout, *args, **kwargs): |
|
result = [None] |
|
exception = [None] |
|
|
|
def wrapper(): |
|
try: |
|
result[0] = target_func(*args, **kwargs) |
|
except Exception as e: |
|
exception[0] = e |
|
|
|
thread = threading.Thread(target=wrapper) |
|
thread.start() |
|
thread.join(timeout=timeout) |
|
|
|
if thread.is_alive(): |
|
st.warning("The operation timed out. Please try again.") |
|
return None |
|
if exception[0]: |
|
raise exception[0] |
|
return result[0] |
|
|
|
|
|
qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad") |
|
|
|
|
|
st.title("Intelligent Career & Course Recommendation System") |
|
|
|
|
|
st.subheader("Profile Setup") |
|
profile_data = { |
|
"name": st.text_input("Enter your name"), |
|
"interests": st.text_input("List your interests (comma-separated)"), |
|
"tech_skills": st.text_input("List your technical skills (comma-separated)"), |
|
} |
|
|
|
if st.button("Save Profile"): |
|
if profile_data["name"] and profile_data["interests"] and profile_data["tech_skills"]: |
|
st.session_state.profile_data = profile_data |
|
st.success("Profile saved successfully!") |
|
else: |
|
st.warning("Please fill in all fields.") |
|
|
|
|
|
if "profile_data" in st.session_state: |
|
st.subheader("Q&A Session") |
|
question = st.text_input("Ask a question about your career or courses:") |
|
|
|
if st.button("Submit Question"): |
|
if question: |
|
|
|
relevant_jobs = [job for job in jobs_dataset if any(interest in job["job_title"].lower() for interest in [i.strip().lower() for i in st.session_state.profile_data["interests"].split(",")])] |
|
context = " ".join([job["job_description"] for job in relevant_jobs if "job_description" in job]) |
|
if context: |
|
answer = run_with_timeout(qa_pipeline, timeout=10, question=question, context=context) |
|
if answer: |
|
st.write(f"Answer: {answer['answer']}") |
|
else: |
|
st.warning("No relevant jobs found to answer your question.") |
|
else: |
|
st.warning("Please enter a question.") |
|
|
|
|
|
if "profile_data" in st.session_state: |
|
st.subheader("Career and Course Recommendations") |
|
interests = [interest.strip().lower() for interest in st.session_state.profile_data["interests"].split(",")] |
|
tech_skills = [skill.strip().lower() for skill in st.session_state.profile_data["tech_skills"].split(",")] |
|
|
|
|
|
st.write("### Job Recommendations:") |
|
for job in jobs_dataset: |
|
job_skills = job.get("job_skills", []) |
|
if job_skills is not None: |
|
job_skills = [skill.lower() for skill in job_skills] |
|
if any(skill in job_skills for skill in tech_skills): |
|
st.write(f"- **{job['job_title']}** at {job['company_name']}, Location: {job['job_location']}") |
|
|
|
|
|
st.write("### Course Recommendations:") |
|
for course in courses_dataset: |
|
course_skills = [skill.lower() for skill in course["Skills"]] if course["Skills"] is not None else [] |
|
if any(interest in course["Title"].lower() for interest in interests): |
|
st.write(f"- **{course['Title']}** by {course['Organization']}. [Link to course]({course['course_url']})") |
|
|