wahab5763's picture
Create app.py
d2fb654 verified
raw
history blame
4.76 kB
import streamlit as st
import pandas as pd
from datasets import load_dataset
from transformers import pipeline
# Constants
universities_url = "https://www.4icu.org/top-universities-world/"
# Load datasets with caching to optimize performance
@st.cache_resource
def load_datasets():
ds_jobs = load_dataset("lukebarousse/data_jobs")
ds_courses = load_dataset("azrai99/coursera-course-dataset")
ds_custom_courses = pd.read_csv("final_cleaned_merged_coursera_courses.csv")
ds_custom_jobs = pd.read_csv("merged_data_science_jobs.csv")
ds_custom_universities = pd.read_csv("merged_university_data_cleaned (1).csv")
return ds_jobs, ds_courses, ds_custom_courses, ds_custom_jobs, ds_custom_universities
ds_jobs, ds_courses, ds_custom_courses, ds_custom_jobs, ds_custom_universities = load_datasets()
# Initialize the pipeline with caching, using an accessible model like 'google/flan-t5-large'
@st.cache_resource
def load_pipeline():
return pipeline("text2text-generation", model="google/flan-t5-large")
qa_pipeline = load_pipeline()
# Streamlit App Interface
st.title("Career Counseling Application")
st.subheader("Build Your Profile and Discover Tailored Career Recommendations")
# Sidebar for Profile Setup
st.sidebar.header("Profile Setup")
educational_background = st.sidebar.text_input("Educational Background (e.g., Degree, Major)")
interests = st.sidebar.text_input("Interests (e.g., AI, Data Science, Engineering)")
tech_skills = st.sidebar.text_area("Technical Skills (e.g., Python, SQL, Machine Learning)")
soft_skills = st.sidebar.text_area("Soft Skills (e.g., Communication, Teamwork)")
# Save profile data for session-based recommendations
if st.sidebar.button("Save Profile"):
st.session_state.profile_data = {
"educational_background": educational_background,
"interests": interests,
"tech_skills": tech_skills,
"soft_skills": soft_skills
}
st.sidebar.success("Profile saved successfully!")
# Intelligent Q&A Section
st.header("Intelligent Q&A")
question = st.text_input("Ask a career-related question:")
if question:
answer = qa_pipeline(question)[0]["generated_text"]
st.write("Answer:", answer)
# Career and Job Recommendations Section
st.header("Career and Job Recommendations")
if "profile_data" in st.session_state:
job_recommendations = []
for job in ds_jobs["train"]:
job_skills = job.get("job_skills", "") or ""
if any(skill.lower() in job_skills.lower() for skill in st.session_state.profile_data["tech_skills"].split(",")):
job_recommendations.append(job.get("job_title_short", "Unknown Job Title"))
for _, job in ds_custom_jobs.iterrows():
job_skills = job.get("skills", "") or ""
if any(skill.lower() in job_skills.lower() for skill in st.session_state.profile_data["tech_skills"].split(",")):
job_recommendations.append(job.get("job_title", "Unknown Job Title"))
if job_recommendations:
st.subheader("Job Recommendations")
st.write("Based on your profile, here are some potential job roles:")
for job in job_recommendations[:5]: # Limit to top 5 job recommendations
st.write("- ", job)
else:
st.write("No specific job recommendations found matching your profile.")
# Course Suggestions Section
st.header("Course Suggestions")
if "profile_data" in st.session_state:
course_recommendations = [
course.get("Title", "Unknown Course Title") for course in ds_courses["train"]
if any(interest.lower() in course.get("Title", "").lower() for interest in st.session_state.profile_data["interests"].split(","))
]
course_recommendations.extend([
row["course_title"] for _, row in ds_custom_courses.iterrows()
if any(interest.lower() in row["course_title"].lower() for interest in st.session_state.profile_data["interests"].split(","))
])
if course_recommendations:
st.subheader("Recommended Courses")
st.write("Here are some courses related to your interests:")
for course in course_recommendations[:5]: # Limit to top 5 course recommendations
st.write("- ", course)
else:
st.write("No specific courses found matching your interests.")
# University Recommendations Section
st.header("Top Universities")
st.write("For further education, you can explore the top universities worldwide:")
st.write(f"[View Top Universities Rankings]({universities_url})")
st.subheader("Custom University Data")
if not ds_custom_universities.empty:
st.write("Here are some recommended universities based on custom data:")
st.dataframe(ds_custom_universities.head())
# Conclusion
st.write("Thank you for using the Career Counseling Application!")