tahirsher commited on
Commit
ebe3257
·
verified ·
1 Parent(s): 17d076a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +106 -89
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 time
5
-
6
- # Display app title
7
- st.title("Career Counseling Application")
8
- st.subheader("Build Your Profile and Discover Tailored Career Recommendations")
9
-
10
- # Loading Spinner for Initial Data and Model Loading
11
- with st.spinner("Loading datasets and model... please wait"):
12
- # Load datasets and handle any potential loading issues
13
- try:
14
- ds_natural_questions = load_dataset("google-research-datasets/natural_questions", split="train[:10%]")
15
- ds_open_questions = load_dataset("launch/open_question_type", split="train[:10%]")
16
- ds_question_generator = load_dataset("iarfmoose/question_generator", split="train[:10%]")
17
- ds_jobs = load_dataset("lukebarousse/data_jobs", split="train[:10%]")
18
- ds_courses = load_dataset("azrai99/coursera-course-dataset", split="train[:10%]")
19
-
20
- # Initialize a small, efficient pipeline for question answering
21
- qa_pipeline = pipeline("text2text-generation", model="google/flan-t5-small")
22
- except Exception as e:
23
- st.error(f"Error loading resources: {e}")
24
- st.stop()
25
-
26
- st.sidebar.header("Profile Setup")
27
- educational_background = st.sidebar.text_input("Educational Background (e.g., Degree, Major)")
28
- interests = st.sidebar.text_input("Interests (e.g., AI, Data Science, Engineering)")
29
- tech_skills = st.sidebar.text_area("Technical Skills (e.g., Python, SQL, Machine Learning)")
30
- soft_skills = st.sidebar.text_area("Soft Skills (e.g., Communication, Teamwork)")
31
-
32
- profile_data = {
33
- "educational_background": educational_background,
34
- "interests": interests,
35
- "tech_skills": tech_skills,
36
- "soft_skills": soft_skills
37
- }
38
-
39
- if st.sidebar.button("Save Profile"):
40
- st.session_state.profile_data = profile_data
41
- st.sidebar.success("Profile saved successfully!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
  # Intelligent Q&A Session
44
  st.header("Intelligent Q&A Session")
45
- if "profile_data" in st.session_state:
46
- st.write("Answer the following career-related questions based on your profile:")
47
- questions = [q['question'] for q in ds_open_questions['question'][:10]]
48
- responses = []
49
-
50
- for question in questions:
51
- st.write(f"Q: {question}")
52
- answer = qa_pipeline(question)[0]["generated_text"]
53
- responses.append(answer)
54
- st.write(f"A: {answer}")
55
- time.sleep(0.5) # To simulate time delay and avoid overwhelming the interface
56
-
57
- # Career Recommendations Section
58
- st.header("Career and Job Recommendations")
59
- job_recommendations = []
60
- for job in ds_jobs:
61
- job_skills = job.get("job_skills", "")
62
- if any(skill.lower() in job_skills.lower() for skill in tech_skills.split(",")):
63
- job_recommendations.append(job["job_title"])
64
-
65
- if job_recommendations:
66
- st.subheader("Job Recommendations")
67
- st.write("Based on your profile, here are some potential job roles:")
68
- for job in job_recommendations[:5]: # Show top 5 job recommendations
69
- st.write("- ", job)
70
- else:
71
- st.write("No specific job recommendations found matching your profile.")
72
-
73
- # Course Suggestions Section
74
- st.header("Course Suggestions")
75
- course_recommendations = []
76
- for course in ds_courses:
77
- course_skills = course.get("Skills", "")
78
- if any(interest.lower() in course_skills.lower() for interest in interests.split(",")):
79
- course_recommendations.append((course["Title"], course["course_url"]))
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)