Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# Display questions one by one after the profile is saved
|
2 |
if "profile_data" in st.session_state and "question_index" in st.session_state:
|
3 |
total_questions = len(additional_questions)
|
@@ -11,33 +81,24 @@ if "profile_data" in st.session_state and "question_index" in st.session_state:
|
|
11 |
question = additional_questions[st.session_state.question_index]
|
12 |
answer = st.text_input(question, key=f"q{st.session_state.question_index}")
|
13 |
|
14 |
-
# Submit button for each question
|
15 |
-
|
16 |
-
if submit_button and not st.session_state.get("submitted", False):
|
17 |
if answer:
|
18 |
st.session_state.answers[question] = answer
|
19 |
st.session_state.question_index += 1
|
20 |
-
|
21 |
-
st.
|
|
|
22 |
else:
|
23 |
st.warning("Please enter an answer before submitting.")
|
24 |
-
st.session_state["submitted"] = False # Allow re-click if no answer is provided
|
25 |
-
|
26 |
-
# Reset the submission flag after the page refreshes
|
27 |
-
if "submitted" in st.session_state:
|
28 |
-
del st.session_state["submitted"]
|
29 |
|
30 |
# Check if all questions are answered and show the "Generate Response" button
|
31 |
if st.session_state.question_index == total_questions:
|
32 |
st.success("All questions have been answered. Click below to generate your recommendations.")
|
33 |
-
|
34 |
-
if generate_button and not st.session_state.get("generated", False):
|
35 |
# Save all answers in the profile data
|
36 |
st.session_state.profile_data.update(st.session_state.answers)
|
37 |
|
38 |
-
# Set generated flag to prevent double-click on the "Generate Response" button
|
39 |
-
st.session_state["generated"] = True
|
40 |
-
|
41 |
# Career and Job Recommendations Section
|
42 |
st.header("Job Recommendations")
|
43 |
with st.spinner('Generating job recommendations...'):
|
@@ -92,41 +153,35 @@ if "profile_data" in st.session_state and "question_index" in st.session_state:
|
|
92 |
"url": row.get("Links", "#")
|
93 |
})
|
94 |
|
95 |
-
# Remove duplicates from course recommendations
|
96 |
course_recommendations = list({(course["name"], course["url"]) for course in course_recommendations})
|
97 |
|
98 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
if course_recommendations:
|
100 |
st.write("Here are the top 5 courses related to your interests:")
|
101 |
for course in course_recommendations[:5]: # Limit to top 5 course recommendations
|
102 |
st.write(f"- [{course[0]}]({course[1]})")
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
{"name": "Python for Data Science", "url": "https://www.coursera.org/learn/python-data-science"},
|
109 |
-
{"name": "Data Structures and Algorithms", "url": "https://www.coursera.org/learn/data-structures-algorithms"},
|
110 |
-
{"name": "Business Analytics", "url": "https://www.coursera.org/learn/business-analytics"},
|
111 |
-
{"name": "Digital Marketing Fundamentals", "url": "https://www.coursera.org/learn/digital-marketing"}
|
112 |
-
]
|
113 |
-
for course in general_courses:
|
114 |
-
st.write(f"- [{course['name']}]({course['url']})")
|
115 |
-
|
116 |
-
# University Suggestions Section
|
117 |
-
st.header("Top Universities")
|
118 |
-
with st.spinner("Finding universities that align with your profile..."):
|
119 |
-
time.sleep(2) # Simulate processing time
|
120 |
-
university_recommendations = ds_custom_universities.head(5) # Limit to top 5 universities
|
121 |
-
|
122 |
-
if not university_recommendations.empty:
|
123 |
-
st.write("Based on your interests, here are some universities to consider:")
|
124 |
-
for _, row in university_recommendations.iterrows():
|
125 |
-
st.write(f"- {row['University Name']} ({row['Country']}) - {row['World Rank']}")
|
126 |
-
else:
|
127 |
-
st.write("No specific university recommendations found. Check out the global top universities:")
|
128 |
-
st.write(f"[Global Top Universities]({universities_url})")
|
129 |
|
130 |
-
|
131 |
-
|
132 |
-
del st.session_state["generated"]
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from datasets import load_dataset
|
3 |
+
import pandas as pd
|
4 |
+
from transformers import pipeline
|
5 |
+
import time
|
6 |
+
|
7 |
+
# Constants
|
8 |
+
universities_url = "https://www.4icu.org/top-universities-world/"
|
9 |
+
|
10 |
+
# Load datasets with caching to optimize performance
|
11 |
+
@st.cache_resource
|
12 |
+
def load_datasets():
|
13 |
+
ds_jobs = load_dataset("lukebarousse/data_jobs")
|
14 |
+
ds_courses = load_dataset("azrai99/coursera-course-dataset")
|
15 |
+
ds_custom_courses = pd.read_csv("final_cleaned_merged_coursera_courses.csv")
|
16 |
+
ds_custom_jobs = pd.read_csv("merged_data_science_jobs.csv")
|
17 |
+
ds_custom_universities = pd.read_csv("merged_university_data_cleaned (1).csv")
|
18 |
+
return ds_jobs, ds_courses, ds_custom_courses, ds_custom_jobs, ds_custom_universities
|
19 |
+
|
20 |
+
ds_jobs, ds_courses, ds_custom_courses, ds_custom_jobs, ds_custom_universities = load_datasets()
|
21 |
+
|
22 |
+
# Initialize the pipeline with caching, using an accessible model like 'google/flan-t5-large'
|
23 |
+
@st.cache_resource
|
24 |
+
def load_pipeline():
|
25 |
+
return pipeline("text2text-generation", model="google/flan-t5-large")
|
26 |
+
|
27 |
+
qa_pipeline = load_pipeline()
|
28 |
+
|
29 |
+
# Streamlit App Interface
|
30 |
+
st.title("Career Counseling Application")
|
31 |
+
st.subheader("Build Your Profile and Discover Tailored Career Recommendations")
|
32 |
+
|
33 |
+
# Sidebar for Profile Setup
|
34 |
+
st.sidebar.header("Profile Setup")
|
35 |
+
educational_background = st.sidebar.text_input("Educational Background (e.g., Degree, Major)")
|
36 |
+
interests = st.sidebar.text_input("Interests (e.g., AI, Data Science, Engineering)")
|
37 |
+
tech_skills = st.sidebar.text_area("Technical Skills (e.g., Python, SQL, Machine Learning)")
|
38 |
+
soft_skills = st.sidebar.text_area("Soft Skills (e.g., Communication, Teamwork)")
|
39 |
+
|
40 |
+
# Save profile data for session-based recommendations
|
41 |
+
if st.sidebar.button("Save Profile"):
|
42 |
+
with st.spinner('Saving your profile...'):
|
43 |
+
time.sleep(2) # Simulate processing time
|
44 |
+
st.session_state.profile_data = {
|
45 |
+
"educational_background": educational_background,
|
46 |
+
"interests": interests,
|
47 |
+
"tech_skills": tech_skills,
|
48 |
+
"soft_skills": soft_skills
|
49 |
+
}
|
50 |
+
st.session_state.question_index = 0 # Initialize question index
|
51 |
+
st.session_state.answers = {} # Initialize dictionary for answers
|
52 |
+
st.session_state.submitted = False # Track if an answer was just submitted
|
53 |
+
st.sidebar.success("Profile saved successfully!")
|
54 |
+
|
55 |
+
st.write("To provide more personalized job and course recommendations, please answer the following questions one by one:")
|
56 |
+
|
57 |
+
# Additional questions for more tailored recommendations
|
58 |
+
additional_questions = [
|
59 |
+
"What industry do you prefer working in (e.g., healthcare, finance, tech)?",
|
60 |
+
"What type of job role are you most interested in (e.g., research, management, development)?",
|
61 |
+
"Are you looking for remote, hybrid, or on-site opportunities?",
|
62 |
+
"Do you have any certifications or licenses related to your field?",
|
63 |
+
"What level of experience do you have (e.g., entry-level, mid-level, senior)?",
|
64 |
+
"What languages are you proficient in, apart from English (if any)?",
|
65 |
+
"Do you prefer working for startups, mid-sized companies, or large corporations?",
|
66 |
+
"What is your preferred learning style for courses (e.g., video tutorials, interactive projects, reading material)?",
|
67 |
+
"Are you open to relocation? If yes, to which cities or regions?",
|
68 |
+
"Do you have a preference for job roles in specific countries or regions?"
|
69 |
+
]
|
70 |
+
|
71 |
# Display questions one by one after the profile is saved
|
72 |
if "profile_data" in st.session_state and "question_index" in st.session_state:
|
73 |
total_questions = len(additional_questions)
|
|
|
81 |
question = additional_questions[st.session_state.question_index]
|
82 |
answer = st.text_input(question, key=f"q{st.session_state.question_index}")
|
83 |
|
84 |
+
# Submit button for each question
|
85 |
+
if st.button("Submit Answer", key=f"submit{st.session_state.question_index}"):
|
|
|
86 |
if answer:
|
87 |
st.session_state.answers[question] = answer
|
88 |
st.session_state.question_index += 1
|
89 |
+
# Trigger page refresh using st.session_state change
|
90 |
+
st.session_state.updated = True # Indicate that a change has occurred
|
91 |
+
st.query_params = {"updated": "true"} # Update query params to indicate change
|
92 |
else:
|
93 |
st.warning("Please enter an answer before submitting.")
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
# Check if all questions are answered and show the "Generate Response" button
|
96 |
if st.session_state.question_index == total_questions:
|
97 |
st.success("All questions have been answered. Click below to generate your recommendations.")
|
98 |
+
if st.button("Generate Response"):
|
|
|
99 |
# Save all answers in the profile data
|
100 |
st.session_state.profile_data.update(st.session_state.answers)
|
101 |
|
|
|
|
|
|
|
102 |
# Career and Job Recommendations Section
|
103 |
st.header("Job Recommendations")
|
104 |
with st.spinner('Generating job recommendations...'):
|
|
|
153 |
"url": row.get("Links", "#")
|
154 |
})
|
155 |
|
156 |
+
# Remove duplicates from course recommendations by converting to a set of tuples and back to a list
|
157 |
course_recommendations = list({(course["name"], course["url"]) for course in course_recommendations})
|
158 |
|
159 |
+
# If there are fewer than 5 exact matches, add nearly related courses
|
160 |
+
if len(course_recommendations) < 5:
|
161 |
+
for course in ds_courses["train"]:
|
162 |
+
if len(course_recommendations) >= 5:
|
163 |
+
break
|
164 |
+
if any(skill.lower() in course.get("Course Name", "").lower() for skill in st.session_state.profile_data["tech_skills"].split(",")):
|
165 |
+
course_recommendations.append((course.get("Course Name", "Unknown Course Title"), course.get("Links", "#")))
|
166 |
+
|
167 |
+
for _, row in ds_custom_courses.iterrows():
|
168 |
+
if len(course_recommendations) >= 5:
|
169 |
+
break
|
170 |
+
if any(skill.lower() in row["Course Name"].lower() for skill in st.session_state.profile_data["tech_skills"].split(",")):
|
171 |
+
course_recommendations.append((row["Course Name"], row.get("Links", "#")))
|
172 |
+
|
173 |
+
# Remove duplicates again after adding nearly related courses
|
174 |
+
course_recommendations = list({(name, url) for name, url in course_recommendations})
|
175 |
+
|
176 |
if course_recommendations:
|
177 |
st.write("Here are the top 5 courses related to your interests:")
|
178 |
for course in course_recommendations[:5]: # Limit to top 5 course recommendations
|
179 |
st.write(f"- [{course[0]}]({course[1]})")
|
180 |
|
181 |
+
# University Recommendations Section
|
182 |
+
st.header("Top Universities")
|
183 |
+
st.write("For further education, you can explore the top universities worldwide:")
|
184 |
+
st.write(f"[View Top Universities Rankings]({universities_url})")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
|
186 |
+
# Conclusion
|
187 |
+
st.write("Thank you for using the Career Counseling Application!")
|
|