Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,37 +9,31 @@ st.title("AI Opportunity Finder for Youth")
|
|
| 9 |
st.write("Find Scholarships, Internships, Online Courses, and more!")
|
| 10 |
|
| 11 |
# Function to get scholarships data from a mock API
|
| 12 |
-
def get_scholarships(
|
| 13 |
-
# Example:
|
| 14 |
-
url = "https://jsonplaceholder.typicode.com/posts" # Mock API
|
| 15 |
response = requests.get(url)
|
| 16 |
|
| 17 |
if response.status_code == 200:
|
| 18 |
-
|
| 19 |
-
posts = response.json()[:5]
|
| 20 |
-
# Construct scholarships list
|
| 21 |
return [{"title": f"Scholarship {i+1}", "description": post['body'], "eligibility": "Any student from any background."} for i, post in enumerate(posts)]
|
| 22 |
else:
|
| 23 |
return []
|
| 24 |
|
| 25 |
# Function to get internships data from a mock API
|
| 26 |
-
def get_internships():
|
| 27 |
-
# Example:
|
| 28 |
-
url = "https://jsonplaceholder.typicode.com/posts" # Mock API for testing
|
| 29 |
response = requests.get(url)
|
| 30 |
|
| 31 |
if response.status_code == 200:
|
| 32 |
-
# Return a list of mock internships
|
| 33 |
return [{"jobtitle": f"Internship {i+1}", "company": "Sample Company", "location": "Remote", "snippet": "Description of the internship."} for i in range(5)]
|
| 34 |
else:
|
| 35 |
return []
|
| 36 |
|
| 37 |
# Function to recommend opportunities based on user input
|
| 38 |
def recommend_opportunities(user_interests, user_skills, opportunities):
|
| 39 |
-
# Combine user profile into a single string
|
| 40 |
user_profile = [f"{user_interests} {user_skills}"]
|
| 41 |
-
|
| 42 |
-
# Create text data for opportunities based on description & eligibility
|
| 43 |
opportunities_text = [f"{opportunity['description']} {opportunity['eligibility']}" for opportunity in opportunities]
|
| 44 |
|
| 45 |
# Vectorize the text using TF-IDF
|
|
@@ -49,57 +43,54 @@ def recommend_opportunities(user_interests, user_skills, opportunities):
|
|
| 49 |
# Compute cosine similarity
|
| 50 |
cosine_sim = cosine_similarity(tfidf_matrix[-1], tfidf_matrix[:-1])
|
| 51 |
|
| 52 |
-
# Get the
|
| 53 |
recommendations = cosine_sim[0].argsort()[-5:][::-1]
|
| 54 |
|
| 55 |
-
# Return recommended opportunities
|
| 56 |
return [opportunities[i] for i in recommendations]
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
st.
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
# Fetch scholarships based on user input
|
| 65 |
-
scholarships = get_scholarships(location, interests)
|
| 66 |
-
|
| 67 |
-
# Display scholarships if available
|
| 68 |
-
if scholarships:
|
| 69 |
-
st.write("Scholarships found:")
|
| 70 |
-
for scholarship in scholarships:
|
| 71 |
-
st.write(f"Title: {scholarship['title']}")
|
| 72 |
-
st.write(f"Description: {scholarship['description']}")
|
| 73 |
-
st.write(f"Eligibility: {scholarship['eligibility']}")
|
| 74 |
-
st.write("---")
|
| 75 |
-
else:
|
| 76 |
-
st.write("No scholarships found based on your criteria.")
|
| 77 |
-
|
| 78 |
-
# Fetch internships based on user input
|
| 79 |
-
internships = get_internships()
|
| 80 |
|
| 81 |
-
|
| 82 |
-
if internships:
|
| 83 |
-
st.write("Internships found:")
|
| 84 |
-
for internship in internships:
|
| 85 |
-
st.write(f"Title: {internship['jobtitle']}")
|
| 86 |
-
st.write(f"Company: {internship['company']}")
|
| 87 |
-
st.write(f"Location: {internship['location']}")
|
| 88 |
-
st.write(f"Snippet: {internship['snippet']}")
|
| 89 |
-
st.write("---")
|
| 90 |
-
else:
|
| 91 |
-
st.write("No internships found.")
|
| 92 |
|
| 93 |
-
#
|
| 94 |
-
if
|
| 95 |
-
#
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
recommended_opportunities = recommend_opportunities(interests, skills, all_opportunities)
|
| 100 |
|
| 101 |
-
|
| 102 |
-
st.write("Recommended Opportunities based on your profile:")
|
| 103 |
for opportunity in recommended_opportunities:
|
| 104 |
st.write(f"Title: {opportunity['title']}")
|
| 105 |
st.write(f"Description: {opportunity['description']}")
|
|
|
|
| 9 |
st.write("Find Scholarships, Internships, Online Courses, and more!")
|
| 10 |
|
| 11 |
# Function to get scholarships data from a mock API
|
| 12 |
+
def get_scholarships(country, interests):
|
| 13 |
+
# Example: Replace with a real API URL (mocked for demonstration)
|
| 14 |
+
url = f"https://jsonplaceholder.typicode.com/posts" # Mock API
|
| 15 |
response = requests.get(url)
|
| 16 |
|
| 17 |
if response.status_code == 200:
|
| 18 |
+
posts = response.json()[:5] # Take only the first 5 posts as mock scholarships
|
|
|
|
|
|
|
| 19 |
return [{"title": f"Scholarship {i+1}", "description": post['body'], "eligibility": "Any student from any background."} for i, post in enumerate(posts)]
|
| 20 |
else:
|
| 21 |
return []
|
| 22 |
|
| 23 |
# Function to get internships data from a mock API
|
| 24 |
+
def get_internships(country):
|
| 25 |
+
# Example: Replace with a real API URL (mocked for demonstration)
|
| 26 |
+
url = f"https://jsonplaceholder.typicode.com/posts" # Mock API for testing
|
| 27 |
response = requests.get(url)
|
| 28 |
|
| 29 |
if response.status_code == 200:
|
|
|
|
| 30 |
return [{"jobtitle": f"Internship {i+1}", "company": "Sample Company", "location": "Remote", "snippet": "Description of the internship."} for i in range(5)]
|
| 31 |
else:
|
| 32 |
return []
|
| 33 |
|
| 34 |
# Function to recommend opportunities based on user input
|
| 35 |
def recommend_opportunities(user_interests, user_skills, opportunities):
|
|
|
|
| 36 |
user_profile = [f"{user_interests} {user_skills}"]
|
|
|
|
|
|
|
| 37 |
opportunities_text = [f"{opportunity['description']} {opportunity['eligibility']}" for opportunity in opportunities]
|
| 38 |
|
| 39 |
# Vectorize the text using TF-IDF
|
|
|
|
| 43 |
# Compute cosine similarity
|
| 44 |
cosine_sim = cosine_similarity(tfidf_matrix[-1], tfidf_matrix[:-1])
|
| 45 |
|
| 46 |
+
# Get the top 5 recommendations
|
| 47 |
recommendations = cosine_sim[0].argsort()[-5:][::-1]
|
| 48 |
|
|
|
|
| 49 |
return [opportunities[i] for i in recommendations]
|
| 50 |
|
| 51 |
+
# Form to gather user profile and country selection
|
| 52 |
+
with st.form(key='user_form'):
|
| 53 |
+
st.sidebar.header("User Profile")
|
| 54 |
+
location = st.selectbox("Select your Country", ["Pakistan", "USA", "Germany", "India", "UK", "Australia"]) # Add more countries as needed
|
| 55 |
+
skills = st.text_input("Skills (e.g., Python, Marketing)")
|
| 56 |
+
interests = st.text_input("Interests (e.g., Technology, Science)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
submit_button = st.form_submit_button("Find Opportunities")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
# Fetch data based on the user input
|
| 61 |
+
if submit_button:
|
| 62 |
+
# Fetch scholarships and internships based on the selected country and profile
|
| 63 |
+
scholarships = get_scholarships(location, interests)
|
| 64 |
+
internships = get_internships(location)
|
| 65 |
+
|
| 66 |
+
# Display Scholarships
|
| 67 |
+
if scholarships:
|
| 68 |
+
st.write("Scholarships found:")
|
| 69 |
+
for scholarship in scholarships:
|
| 70 |
+
st.write(f"Title: {scholarship['title']}")
|
| 71 |
+
st.write(f"Description: {scholarship['description']}")
|
| 72 |
+
st.write(f"Eligibility: {scholarship['eligibility']}")
|
| 73 |
+
st.write("---")
|
| 74 |
+
else:
|
| 75 |
+
st.write("No scholarships found for the selected country.")
|
| 76 |
|
| 77 |
+
# Display Internships
|
| 78 |
+
if internships:
|
| 79 |
+
st.write("Internships found:")
|
| 80 |
+
for internship in internships:
|
| 81 |
+
st.write(f"Title: {internship['jobtitle']}")
|
| 82 |
+
st.write(f"Company: {internship['company']}")
|
| 83 |
+
st.write(f"Location: {internship['location']}")
|
| 84 |
+
st.write(f"Snippet: {internship['snippet']}")
|
| 85 |
+
st.write("---")
|
| 86 |
+
else:
|
| 87 |
+
st.write("No internships found for the selected country.")
|
| 88 |
+
|
| 89 |
+
# AI Recommendations based on interests and skills
|
| 90 |
+
all_opportunities = scholarships + internships
|
| 91 |
recommended_opportunities = recommend_opportunities(interests, skills, all_opportunities)
|
| 92 |
|
| 93 |
+
st.write("AI-based Recommended Opportunities based on your profile:")
|
|
|
|
| 94 |
for opportunity in recommended_opportunities:
|
| 95 |
st.write(f"Title: {opportunity['title']}")
|
| 96 |
st.write(f"Description: {opportunity['description']}")
|