wahab5763 commited on
Commit
ef6aff2
·
verified ·
1 Parent(s): 621e1cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +111 -86
app.py CHANGED
@@ -1,30 +1,19 @@
1
  import streamlit as st
2
  import pandas as pd
3
- from datasets import load_dataset
4
  from transformers import pipeline
5
  import time
6
 
7
- # Constants
8
- universities_url = "https://www.4icu.org/top-universities-world/"
9
-
10
- # Load job and course datasets
11
- def load_custom_datasets():
12
- job_data = pd.read_csv("job_data.csv") # Ensure this file exists in the same directory
13
- course_data = pd.read_csv("courses_data.csv") # Ensure this file exists in the same directory
14
- return job_data, course_data
15
-
16
- job_data, course_data = load_custom_datasets()
17
-
18
- # Load datasets with caching to optimize performance
19
  @st.cache_resource
20
- def load_datasets():
21
- ds_jobs = load_dataset("lukebarousse/data_jobs")
22
- ds_courses = load_dataset("azrai99/coursera-course-dataset")
23
- return ds_jobs, ds_courses
24
-
25
- ds_jobs, ds_courses = load_datasets()
26
 
27
- # Initialize the pipeline with caching
 
 
 
28
  @st.cache_resource
29
  def load_pipeline():
30
  return pipeline("text2text-generation", model="google/flan-t5-large")
@@ -37,33 +26,23 @@ st.subheader("Build Your Profile and Discover Tailored Career Recommendations")
37
 
38
  # Sidebar for Profile Setup
39
  st.sidebar.header("Profile Setup")
40
-
41
- # Dropdown for educational background with major domains
42
- major_domains = [
43
  "Computer Science", "Engineering", "Business Administration", "Life Sciences",
44
  "Social Sciences", "Arts and Humanities", "Mathematics", "Physical Sciences",
45
  "Law", "Education", "Medical Sciences", "Other"
46
- ]
47
- educational_background = st.sidebar.selectbox("Educational Background", major_domains)
48
-
49
  interests = st.sidebar.text_input("Interests (e.g., AI, Data Science, Engineering)")
50
  tech_skills = st.sidebar.text_area("Technical Skills (e.g., Python, SQL, Machine Learning)")
51
  soft_skills = st.sidebar.text_area("Soft Skills (e.g., Communication, Teamwork)")
52
 
53
- # Check if all fields are filled
54
  def are_profile_fields_filled():
55
- return all([
56
- educational_background,
57
- interests.strip(),
58
- tech_skills.strip(),
59
- soft_skills.strip()
60
- ])
61
-
62
- # Save profile data for session-based recommendations
63
  if st.sidebar.button("Save Profile"):
64
  if are_profile_fields_filled():
65
  with st.spinner('Saving your profile...'):
66
- time.sleep(2) # Simulate processing time
67
  st.session_state.profile_data = {
68
  "educational_background": educational_background,
69
  "interests": interests,
@@ -76,16 +55,14 @@ if st.sidebar.button("Save Profile"):
76
  st.session_state.show_additional_question_buttons = True # Show buttons after profile save
77
  st.sidebar.success("Profile saved successfully!")
78
 
79
- # Trick to force a rerun by updating a dummy session state value
80
  st.session_state.rerun_trigger = not st.session_state.get("rerun_trigger", False)
81
-
82
  else:
83
  st.sidebar.error("Please fill in all the fields before saving your profile.")
84
 
85
- # Show buttons to ask additional questions or skip
86
  if "show_additional_question_buttons" in st.session_state:
87
  if st.session_state.show_additional_question_buttons:
88
- st.write("Would you like to answer more questions to get more tailored recommendations?")
89
  col1, col2 = st.columns(2)
90
  with col1:
91
  if st.button("Yes, ask me more questions"):
@@ -98,57 +75,105 @@ if "show_additional_question_buttons" in st.session_state:
98
  st.session_state.show_additional_question_buttons = False # Hide buttons after click
99
  st.session_state.rerun_trigger = not st.session_state.get("rerun_trigger", False) # Trigger rerun
100
 
101
- # Matching logic for job recommendations
102
- def recommend_jobs(user_profile, job_data):
103
- recommended_jobs = []
104
-
105
- for _, job in job_data.iterrows():
106
- if (user_profile["educational_background"].lower() in job["Description"].lower() or
107
- any(skill.lower() in job["Skills Required"].lower() for skill in user_profile["tech_skills"].split(", ")) or
108
- any(interest.lower() in job["Description"].lower() for interest in user_profile["interests"].split(", "))):
109
- recommended_jobs.append(job["Job Title"])
110
-
111
- return list(set(recommended_jobs))
112
-
113
- # Matching logic for course recommendations
114
- def recommend_courses(user_profile, course_data):
115
- recommended_courses = []
116
-
117
- for _, course in course_data.iterrows():
118
- if any(interest.lower() in course["Course Name"].lower() for interest in user_profile["interests"].split(", ")):
119
- recommended_courses.append((course["Course Name"], course["Links"]))
120
-
121
- return list({course for course in recommended_courses}) # Remove duplicates
122
-
123
- # Display recommendations if the user chooses to skip or after answering questions
124
- if "profile_data" in st.session_state and st.session_state.get("ask_additional_questions") == False:
125
- user_profile = st.session_state.profile_data
126
-
127
- st.header("Generating Recommendations")
128
- with st.spinner('Generating recommendations...'):
129
- time.sleep(2) # Simulate processing time
130
-
131
- job_recommendations = recommend_jobs(user_profile, job_data)
132
- course_recommendations = recommend_courses(user_profile, course_data)
133
 
134
- st.subheader("Job Recommendations")
135
- if job_recommendations:
136
- for job in job_recommendations[:5]:
137
- st.write("- ", job)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  else:
139
- st.write("No specific job recommendations found matching your profile. Consider broadening your skills or interests.")
 
 
 
 
 
 
 
 
 
140
 
141
- st.subheader("Recommended Courses")
142
- if course_recommendations:
143
- for course in course_recommendations[:5]:
144
- st.write(f"- [{course[0]}]({course[1]})")
145
- else:
146
- st.write("No specific course recommendations found. Consider exploring learning paths related to your interests.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
 
148
  # University Recommendations Section
149
  st.header("Top Universities")
150
  st.write("For further education, you can explore the top universities worldwide:")
151
- st.write(f"[View Top Universities Rankings]({universities_url})")
152
 
153
- # Conclusion
154
- st.write("Thank you for using the Career Counseling Application!")
 
1
  import streamlit as st
2
  import pandas as pd
 
3
  from transformers import pipeline
4
  import time
5
 
6
+ # Load datasets from CSV files
 
 
 
 
 
 
 
 
 
 
 
7
  @st.cache_resource
8
+ def load_csv_datasets():
9
+ jobs_data = pd.read_csv("job_data.csv")
10
+ courses_data = pd.read_csv("courses_data.csv")
11
+ return jobs_data, courses_data
 
 
12
 
13
+ jobs_data, courses_data = load_csv_datasets()
14
+ # Constants
15
+ universities_url = "https://www.4icu.org/top-universities-world/"
16
+ # Initialize the text generation pipeline
17
  @st.cache_resource
18
  def load_pipeline():
19
  return pipeline("text2text-generation", model="google/flan-t5-large")
 
26
 
27
  # Sidebar for Profile Setup
28
  st.sidebar.header("Profile Setup")
29
+ educational_background = st.sidebar.selectbox("Educational Background", [
 
 
30
  "Computer Science", "Engineering", "Business Administration", "Life Sciences",
31
  "Social Sciences", "Arts and Humanities", "Mathematics", "Physical Sciences",
32
  "Law", "Education", "Medical Sciences", "Other"
33
+ ])
 
 
34
  interests = st.sidebar.text_input("Interests (e.g., AI, Data Science, Engineering)")
35
  tech_skills = st.sidebar.text_area("Technical Skills (e.g., Python, SQL, Machine Learning)")
36
  soft_skills = st.sidebar.text_area("Soft Skills (e.g., Communication, Teamwork)")
37
 
38
+ # Profile validation and saving
39
  def are_profile_fields_filled():
40
+ return all([educational_background, interests.strip(), tech_skills.strip(), soft_skills.strip()])
41
+
 
 
 
 
 
 
42
  if st.sidebar.button("Save Profile"):
43
  if are_profile_fields_filled():
44
  with st.spinner('Saving your profile...'):
45
+ time.sleep(2)
46
  st.session_state.profile_data = {
47
  "educational_background": educational_background,
48
  "interests": interests,
 
55
  st.session_state.show_additional_question_buttons = True # Show buttons after profile save
56
  st.sidebar.success("Profile saved successfully!")
57
 
58
+ # Force a rerun by updating a dummy session state value
59
  st.session_state.rerun_trigger = not st.session_state.get("rerun_trigger", False)
 
60
  else:
61
  st.sidebar.error("Please fill in all the fields before saving your profile.")
62
 
63
+ # Button actions
64
  if "show_additional_question_buttons" in st.session_state:
65
  if st.session_state.show_additional_question_buttons:
 
66
  col1, col2 = st.columns(2)
67
  with col1:
68
  if st.button("Yes, ask me more questions"):
 
75
  st.session_state.show_additional_question_buttons = False # Hide buttons after click
76
  st.session_state.rerun_trigger = not st.session_state.get("rerun_trigger", False) # Trigger rerun
77
 
78
+ # Additional questions for more tailored recommendations
79
+ additional_questions = [
80
+ "What subjects do you enjoy learning about the most, and why?",
81
+ "What activities or hobbies do you find most engaging and meaningful outside of school?",
82
+ "Can you describe a perfect day in your dream career? What tasks would you be doing?",
83
+ "Are you more inclined towards working independently or as part of a team?",
84
+ "Do you prefer structured schedules or flexibility in your work?",
85
+ "What values are most important to you in a career (e.g., creativity, stability, helping others)?",
86
+ "How important is financial stability to you in your future career?",
87
+ "Are you interested in pursuing a career that involves working with people, technology, or the environment?",
88
+ "Would you prefer a career with a clear progression path or one with more entrepreneurial freedom?",
89
+ "What problems or challenges do you want to solve or address through your career?"
90
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
+ # Display dynamic questions or proceed to generating recommendations
93
+ if "profile_data" in st.session_state:
94
+ if st.session_state.get("ask_additional_questions") is True:
95
+ total_questions = len(additional_questions)
96
+ if "question_index" not in st.session_state:
97
+ st.session_state.question_index = 0
98
+
99
+ if st.session_state.question_index < total_questions:
100
+ question = additional_questions[st.session_state.question_index]
101
+ answer = st.text_input(question, key=f"q{st.session_state.question_index}")
102
+
103
+ # Display progress bar
104
+ progress = (st.session_state.question_index + 1) / total_questions
105
+ st.progress(progress)
106
+
107
+ if st.button("Submit Answer", key=f"submit{st.session_state.question_index}"):
108
+ if answer:
109
+ st.session_state.answers[question] = answer
110
+ st.session_state.question_index += 1
111
+ st.session_state.rerun_trigger = not st.session_state.get("rerun_trigger", False) # Trigger rerun
112
+ else:
113
+ st.warning("Please enter an answer before submitting.")
114
  else:
115
+ st.success("All questions have been answered. Click below to generate your recommendations.")
116
+ if st.button("Generate Response"):
117
+ st.session_state.profile_data.update(st.session_state.answers)
118
+ st.session_state.ask_additional_questions = False
119
+ st.session_state.rerun_trigger = not st.session_state.get("rerun_trigger", False) # Trigger rerun
120
+ elif st.session_state.get("ask_additional_questions") is False:
121
+ # Directly generate recommendations
122
+ st.header("Generating Recommendations")
123
+ with st.spinner('Generating recommendations...'):
124
+ time.sleep(2) # Simulate processing time
125
 
126
+ # Extracting user profile data
127
+ profile = st.session_state.profile_data
128
+ user_tech_skills = set(skill.strip().lower() for skill in profile["tech_skills"].split(","))
129
+ user_interests = set(interest.strip().lower() for interest in profile["interests"].split(","))
130
+
131
+ # Job Recommendations using RAG technique
132
+ job_recommendations = jobs_data[jobs_data['Skills Required'].apply(
133
+ lambda skills: any(skill in skills.lower() for skill in user_tech_skills)
134
+ )]
135
+
136
+ # Course Recommendations using RAG technique
137
+ course_recommendations = courses_data[courses_data['Course Name'].apply(
138
+ lambda name: any(interest in name.lower() for interest in user_interests)
139
+ )]
140
+
141
+ # Display Job Recommendations
142
+ st.subheader("Job Recommendations")
143
+ if not job_recommendations.empty:
144
+ for _, row in job_recommendations.head(5).iterrows():
145
+ st.write(f"- **{row['Job Title']}**: {row['Description']}")
146
+ else:
147
+ st.write("No specific job recommendations found matching your profile.")
148
+
149
+ # Display Course Recommendations
150
+ st.subheader("Recommended Courses")
151
+ if not course_recommendations.empty:
152
+ for _, row in course_recommendations.head(5).iterrows():
153
+ st.write(f"- [{row['Course Name']}]({row['Links']})")
154
+ else:
155
+ st.write("No specific course recommendations found matching your interests.")
156
+ st.write("Here are some general course recommendations aligned with your profile:")
157
+
158
+ # Suggest 3 fallback courses aligned with the user's educational background or technical skills
159
+ fallback_courses = courses_data[
160
+ courses_data['Course Name'].apply(
161
+ lambda name: any(
162
+ word in name.lower() for word in profile["educational_background"].lower().split() +
163
+ [skill.lower() for skill in profile["tech_skills"].split(",")]
164
+ )
165
+ )
166
+ ]
167
+
168
+ if not fallback_courses.empty:
169
+ for _, row in fallback_courses.head(3).iterrows():
170
+ st.write(f"- [{row['Course Name']}]({row['Links']})")
171
+ else:
172
+ st.write("Consider exploring courses in fields related to your educational background or technical skills.")
173
 
174
  # University Recommendations Section
175
  st.header("Top Universities")
176
  st.write("For further education, you can explore the top universities worldwide:")
177
+ st.write(f"[View Top Universities Rankings]({universities_url})")
178
 
179
+ st.write("Thank you for using the Career Counseling Application with RAG!")