MansoorSarookh commited on
Commit
f9ab1fa
·
verified ·
1 Parent(s): 0fddc1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -120
app.py CHANGED
@@ -1,73 +1,3 @@
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,34 +11,21 @@ if "profile_data" in st.session_state and "question_index" in st.session_state:
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
- # Single-click submit button logic
85
- if "submitted" not in st.session_state:
86
- st.session_state.submitted = False
87
-
88
- if st.button("Submit Answer", key=f"submit{st.session_state.question_index}") and not st.session_state.submitted:
89
  if answer:
90
  st.session_state.answers[question] = answer
91
  st.session_state.question_index += 1
92
- st.session_state.submitted = True
93
- st.session_state.updated = True
94
- st.query_params = {"updated": "true"}
95
  else:
96
  st.warning("Please enter an answer before submitting.")
97
- else:
98
- st.session_state.submitted = False
99
 
100
  # Check if all questions are answered and show the "Generate Response" button
101
  if st.session_state.question_index == total_questions:
102
  st.success("All questions have been answered. Click below to generate your recommendations.")
103
-
104
- # Single-click generate response button logic
105
- if "generate_response_clicked" not in st.session_state:
106
- st.session_state.generate_response_clicked = False
107
-
108
- if st.button("Generate Response") and not st.session_state.generate_response_clicked:
109
- st.session_state.generate_response_clicked = True
110
-
111
- # Save all answers in the profile data
112
  st.session_state.profile_data.update(st.session_state.answers)
113
 
114
  # Career and Job Recommendations Section
@@ -187,35 +104,10 @@ if "profile_data" in st.session_state and "question_index" in st.session_state:
187
 
188
  if course_recommendations:
189
  st.write("Here are the top 5 courses related to your interests:")
190
- for course in course_recommendations[:5]: # Limit to top 5 course recommendations
191
- st.write(f"- [{course['name']}]({course['url']})")
192
-
193
- else:
194
- st.write("No specific course recommendations found matching your profile. Here are some general recommendations:")
195
- general_courses = [
196
- {"name": "Introduction to Machine Learning", "url": "https://www.coursera.org/learn/machine-learning"},
197
- {"name": "Python for Data Science", "url": "https://www.coursera.org/learn/python-data-science"},
198
- {"name": "Data Structures and Algorithms", "url": "https://www.coursera.org/learn/data-structures-algorithms"},
199
- {"name": "Business Analytics", "url": "https://www.coursera.org/learn/business-analytics"},
200
- {"name": "Digital Marketing Fundamentals", "url": "https://www.coursera.org/learn/digital-marketing"}
201
- ]
202
- for course in general_courses:
203
- st.write(f"- [{course['name']}]({course['url']})")
204
-
205
- # University Suggestions Section
206
- st.header("Top Universities")
207
- with st.spinner("Finding universities that align with your profile..."):
208
- time.sleep(2) # Simulate processing time
209
- university_recommendations = ds_custom_universities.head(5) # Limit to top 5 universities
210
-
211
- if not university_recommendations.empty:
212
- st.write("Based on your interests, here are some universities to consider:")
213
- for _, row in university_recommendations.iterrows():
214
- st.write(f"- {row['University Name']} ({row['Country']}) - {row['World Rank']}")
215
- else:
216
- st.write("No specific university recommendations found. Check out the global top universities:")
217
- st.write(f"[Global Top Universities]({universities_url})")
218
-
219
- # End of code
220
 
221
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
  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, disabled after clicking
15
+ if st.button("Submit Answer", key=f"submit{st.session_state.question_index}", disabled=st.session_state.get("submitted", False)):
 
 
 
16
  if answer:
17
  st.session_state.answers[question] = answer
18
  st.session_state.question_index += 1
19
+ st.session_state.submitted = True # Lock the submit button after clicking
20
+ st.experimental_rerun() # Refresh the page to unlock the button for the next question
 
21
  else:
22
  st.warning("Please enter an answer before submitting.")
 
 
23
 
24
  # Check if all questions are answered and show the "Generate Response" button
25
  if st.session_state.question_index == total_questions:
26
  st.success("All questions have been answered. Click below to generate your recommendations.")
27
+ if st.button("Generate Response", disabled=st.session_state.get("generated_response", False)):
28
+ st.session_state.generated_response = True # Lock the generate response button
 
 
 
 
 
 
 
29
  st.session_state.profile_data.update(st.session_state.answers)
30
 
31
  # Career and Job Recommendations Section
 
104
 
105
  if course_recommendations:
106
  st.write("Here are the top 5 courses related to your interests:")
107
+ for course in course_recommendations[:5]: # Limit to top 5 course recommendations
108
+ st.write(f"- [{course[0]}]({course[1]})")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
+ # University Recommendations Section
111
+ st.header("Top Universities")
112
+ st.write("For further education, you can explore the top universities worldwide:")
113
+ st.write(f"[View Top Universities Rankings]({universities_url})")