Spaces:
Running
Running
import streamlit as st | |
import requests | |
import pandas as pd | |
from sklearn.feature_extraction.text import TfidfVectorizer | |
from sklearn.metrics.pairwise import cosine_similarity | |
# Set up the Streamlit page | |
st.title("AI Opportunity Finder for Youth") | |
st.write("Find Scholarships, Internships, Online Courses, and more!") | |
# Function to get scholarships data from a mock API | |
def get_scholarships(country, interests): | |
# Example: Replace with a real API URL (mocked for demonstration) | |
url = f"https://jsonplaceholder.typicode.com/posts" # Mock API | |
response = requests.get(url) | |
if response.status_code == 200: | |
posts = response.json()[:5] # Take only the first 5 posts as mock scholarships | |
return [{"title": f"Scholarship {i+1}", "description": post.get('body', 'No description available'), "eligibility": "Any student from any background."} for i, post in enumerate(posts)] | |
else: | |
return [] | |
# Function to get internships data from a mock API | |
def get_internships(country): | |
# Example: Replace with a real API URL (mocked for demonstration) | |
url = f"https://jsonplaceholder.typicode.com/posts" # Mock API for testing | |
response = requests.get(url) | |
if response.status_code == 200: | |
return [{"jobtitle": f"Internship {i+1}", "company": "Sample Company", "location": "Remote", "snippet": "Description of the internship."} for i in range(5)] | |
else: | |
return [] | |
# Function to recommend opportunities based on user input | |
def recommend_opportunities(user_interests, user_skills, opportunities): | |
user_profile = [f"{user_interests} {user_skills}"] | |
opportunities_text = [f"{opportunity.get('description', 'No description available')} {opportunity.get('eligibility', 'No eligibility available')}" for opportunity in opportunities] | |
# Vectorize the text using TF-IDF | |
vectorizer = TfidfVectorizer(stop_words='english') | |
tfidf_matrix = vectorizer.fit_transform(opportunities_text + user_profile) | |
# Compute cosine similarity | |
cosine_sim = cosine_similarity(tfidf_matrix[-1], tfidf_matrix[:-1]) | |
# Get the top 5 recommendations | |
recommendations = cosine_sim[0].argsort()[-5:][::-1] | |
return [opportunities[i] for i in recommendations] | |
# Form to gather user profile and country selection | |
with st.form(key='user_form'): | |
st.sidebar.header("User Profile") | |
location = st.selectbox("Select your Country", ["Pakistan", "USA", "Germany", "India", "UK", "Australia"]) # Add more countries as needed | |
skills = st.text_input("Skills (e.g., Python, Marketing)") | |
interests = st.text_input("Interests (e.g., Technology, Science)") | |
submit_button = st.form_submit_button("Find Opportunities") | |
# Fetch data based on the user input | |
if submit_button: | |
# Fetch scholarships and internships based on the selected country and profile | |
scholarships = get_scholarships(location, interests) | |
internships = get_internships(location) | |
# Display Scholarships | |
if scholarships: | |
st.write("Scholarships found:") | |
for scholarship in scholarships: | |
st.write(f"Title: {scholarship['title']}") | |
st.write(f"Description: {scholarship.get('description', 'No description available')}") | |
st.write(f"Eligibility: {scholarship.get('eligibility', 'No eligibility available')}") | |
st.write("---") | |
else: | |
st.write("No scholarships found for the selected country.") | |
# Display Internships | |
if internships: | |
st.write("Internships found:") | |
for internship in internships: | |
st.write(f"Title: {internship['jobtitle']}") | |
st.write(f"Company: {internship['company']}") | |
st.write(f"Location: {internship['location']}") | |
st.write(f"Snippet: {internship['snippet']}") | |
st.write("---") | |
else: | |
st.write("No internships found for the selected country.") | |
# AI Recommendations based on interests and skills | |
all_opportunities = scholarships + internships | |
recommended_opportunities = recommend_opportunities(interests, skills, all_opportunities) | |
st.write("AI-based Recommended Opportunities based on your profile:") | |
for opportunity in recommended_opportunities: | |
st.write(f"Title: {opportunity['title']}") | |
st.write(f"Description: {opportunity.get('description', 'No description available')}") | |
st.write(f"Eligibility: {opportunity.get('eligibility', 'Not available')}") | |
st.write("---") | |