File size: 4,095 Bytes
49e3224
 
417ac0c
ebe3257
49e3224
ebe3257
 
49e3224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
884344e
 
 
 
 
 
 
 
 
49e3224
 
 
 
 
 
 
 
 
 
 
 
3add62e
 
 
 
 
49e3224
 
 
 
3add62e
49e3224
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import threading
import time  # Simulate a long task for demonstration
from transformers import pipeline
from datasets import load_dataset
import streamlit as st

# Load datasets
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"]

# Function to handle long-running tasks with timeout
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]

# Load QA pipeline for Q&A session
qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")

# Streamlit UI
st.title("Intelligent Career & Course Recommendation System")

# Profile setup
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.")

# Q&A session after profile setup
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:
            # Filter context based on interests or skills
            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])  # Creating a context from relevant job descriptions
            if context:
                answer = run_with_timeout(qa_pipeline, timeout=10, question=question, context=context)  # Using a longer timeout
                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.")

# Job and course recommendations based on interests and skills
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(",")]
    
    # Job Recommendations
    st.write("### Job Recommendations:")
    for job in jobs_dataset:
        job_skills = job.get("job_skills", [])
        if job_skills is not None:  # Check if job_skills is not None
            job_skills = [skill.lower() for skill in job_skills]  # Lowercase the 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']}")
    
    # Course Recommendations
    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']})")