Update app.py
Browse files
app.py
CHANGED
@@ -1,94 +1,111 @@
|
|
1 |
import streamlit as st
|
2 |
-
from datasets import load_dataset
|
3 |
from transformers import pipeline
|
4 |
-
import
|
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 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
# Intelligent Q&A Session
|
44 |
st.header("Intelligent Q&A Session")
|
45 |
-
if "
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
for job in
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
for course in
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
if course_recommendations:
|
82 |
-
st.subheader("Recommended Courses")
|
83 |
-
st.write("Here are some courses related to your interests:")
|
84 |
-
for title, url in course_recommendations[:5]: # Show top 5 courses
|
85 |
-
st.write(f"- [{title}]({url})")
|
86 |
-
else:
|
87 |
-
st.write("No specific courses found matching your interests.")
|
88 |
-
|
89 |
-
# University Recommendations
|
90 |
-
st.header("Top Universities")
|
91 |
-
universities_url = "https://www.4icu.org/top-universities-world/"
|
92 |
-
st.write(f"[View Top Universities Rankings]({universities_url})")
|
93 |
-
|
94 |
-
st.write("Thank you for using the Career Counseling Application!")
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from transformers import pipeline
|
3 |
+
from datasets import load_dataset
|
4 |
+
import signal
|
5 |
+
|
6 |
+
# Timeout and Exception Handling
|
7 |
+
class TimeoutException(Exception):
|
8 |
+
pass
|
9 |
+
|
10 |
+
def timeout_handler(signum, frame):
|
11 |
+
raise TimeoutException("Operation timed out!")
|
12 |
+
|
13 |
+
# Set a timeout handler
|
14 |
+
signal.signal(signal.SIGALRM, timeout_handler)
|
15 |
+
|
16 |
+
# Caching function for the model to avoid reloading
|
17 |
+
@st.cache_resource
|
18 |
+
def load_qa_model():
|
19 |
+
with st.spinner("Loading question-answering model..."):
|
20 |
+
try:
|
21 |
+
signal.alarm(30) # Set a 30-second timeout for model loading
|
22 |
+
model = pipeline("question-answering", model="distilbert-base-uncased") # Smaller model for faster loading
|
23 |
+
signal.alarm(0) # Cancel the alarm if loaded successfully
|
24 |
+
st.success("Model loaded successfully!")
|
25 |
+
return model
|
26 |
+
except TimeoutException:
|
27 |
+
st.error("Model loading timed out. Please try again later.")
|
28 |
+
return None
|
29 |
+
|
30 |
+
# Load QA Model
|
31 |
+
qa_pipeline = load_qa_model()
|
32 |
+
|
33 |
+
# Caching function for loading datasets
|
34 |
+
@st.cache_data
|
35 |
+
def load_job_dataset():
|
36 |
+
with st.spinner("Loading job dataset..."):
|
37 |
+
return load_dataset("lukebarousse/data_jobs", split="train[:100]") # Smaller sample for faster loading
|
38 |
+
|
39 |
+
def load_course_dataset():
|
40 |
+
with st.spinner("Loading course dataset..."):
|
41 |
+
return load_dataset("azrai99/coursera-course-dataset", split="train[:50]") # Smaller sample for testing
|
42 |
+
|
43 |
+
# Load datasets
|
44 |
+
job_dataset = load_job_dataset()
|
45 |
+
course_dataset = load_course_dataset()
|
46 |
+
|
47 |
+
# Helper function for question generation
|
48 |
+
def generate_questions(profile_data):
|
49 |
+
questions = [
|
50 |
+
f"What skills do you have in {profile_data.get('tech_skills', 'technology')}?",
|
51 |
+
"What are your preferred working conditions?",
|
52 |
+
"What motivates you in a job?",
|
53 |
+
"Are you interested in work-from-home opportunities?",
|
54 |
+
"Do you have a preference for job location?",
|
55 |
+
"Are you open to roles requiring a degree?",
|
56 |
+
"Do you have a preferred organization size?",
|
57 |
+
"What are your expected salary requirements?",
|
58 |
+
"What challenges do you enjoy solving?",
|
59 |
+
"Do you have experience with any specific programming languages or tools?"
|
60 |
+
]
|
61 |
+
return questions
|
62 |
+
|
63 |
+
# Streamlit Interface
|
64 |
+
st.title("Career and Course Recommendations App")
|
65 |
+
|
66 |
+
# Profile Setup Section
|
67 |
+
st.header("Profile Setup")
|
68 |
+
profile_data = {}
|
69 |
+
profile_data["name"] = st.text_input("Your Name")
|
70 |
+
profile_data["tech_skills"] = st.text_input("Technical Skills (comma-separated)")
|
71 |
+
profile_data["preferred_location"] = st.text_input("Preferred Location")
|
72 |
+
profile_data["work_preference"] = st.selectbox("Work Preference", ["On-site", "Remote", "Hybrid"])
|
73 |
|
74 |
# Intelligent Q&A Session
|
75 |
st.header("Intelligent Q&A Session")
|
76 |
+
if st.button("Start Q&A Session"):
|
77 |
+
questions = generate_questions(profile_data)
|
78 |
+
answers = []
|
79 |
+
for i, question in enumerate(questions):
|
80 |
+
answer = st.text_input(f"Q{i+1}: {question}")
|
81 |
+
answers.append(answer)
|
82 |
+
|
83 |
+
profile_data["answers"] = answers
|
84 |
+
st.success("Q&A Session Completed!")
|
85 |
+
|
86 |
+
# Career Recommendations Based on Profile
|
87 |
+
st.header("Career Recommendations")
|
88 |
+
if qa_pipeline and "tech_skills" in profile_data:
|
89 |
+
job_recommendations = [
|
90 |
+
job["job_title"]
|
91 |
+
for job in job_dataset
|
92 |
+
if "job_skills" in job and any(skill.lower() in job["job_skills"].lower() for skill in profile_data["tech_skills"].split(","))
|
93 |
+
]
|
94 |
+
st.write("Recommended Jobs:")
|
95 |
+
for job in job_recommendations[:5]: # Limit to 5 recommendations
|
96 |
+
st.write(f"- {job}")
|
97 |
+
|
98 |
+
# Course Recommendations Based on Profile
|
99 |
+
st.header("Course Recommendations")
|
100 |
+
if qa_pipeline and "tech_skills" in profile_data:
|
101 |
+
course_recommendations = [
|
102 |
+
course["Title"]
|
103 |
+
for course in course_dataset
|
104 |
+
if "Skills" in course and any(skill.lower() in course["Skills"].lower() for skill in profile_data["tech_skills"].split(","))
|
105 |
+
]
|
106 |
+
st.write("Recommended Courses:")
|
107 |
+
for course in course_recommendations[:5]: # Limit to 5 recommendations
|
108 |
+
st.write(f"- {course}")
|
109 |
+
|
110 |
+
# Debugging: Log Profile Data
|
111 |
+
st.write("Profile Data:", profile_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|