File size: 5,915 Bytes
ab78615
 
 
 
2ceeaba
5a4ed29
ab78615
 
 
 
 
5a4ed29
 
 
 
ab78615
5a4ed29
 
 
ab78615
5a4ed29
ab78615
5a4ed29
 
 
 
 
 
 
 
ab78615
5a4ed29
ab78615
5a4ed29
ab78615
5a4ed29
ab78615
5a4ed29
 
 
ab78615
 
 
 
 
 
 
 
5a4ed29
ab78615
 
5a4ed29
ab78615
 
5a4ed29
 
 
 
 
 
ab78615
5a4ed29
 
 
 
 
 
 
 
 
 
 
 
 
ab78615
5a4ed29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d6f26da
5a4ed29
 
ab78615
 
5a4ed29
 
ab78615
5a4ed29
 
 
ab78615
5a4ed29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import streamlit as st
import requests
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
from transformers import MarianMTModel, MarianTokenizer
import sentencepiece

# 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(location, interests):
    url = "https://jsonplaceholder.typicode.com/posts"  # Mock API for testing
    response = requests.get(url)
    
    if response.status_code == 200:
        # Return a list of mock scholarships
        return [{"title": f"Scholarship {i+1}", "description": post['body'], "eligibility": "Any student from any background."} for i, post in enumerate(response.json())[:5]]
    else:
        return []

# Function to get internships data from a mock API
def get_internships():
    url = "https://jsonplaceholder.typicode.com/posts"  # Mock API for testing
    response = requests.get(url)
    
    if response.status_code == 200:
        # Return a list of mock internships
        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):
    # Combine user profile into a single string
    user_profile = [f"{user_interests} {user_skills}"]
    
    # Create text data for opportunities based on description & eligibility
    opportunities_text = [f"{opportunity['description']} {opportunity['eligibility']}" 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 indices of the top 5 recommended opportunities
    recommendations = cosine_sim[0].argsort()[-5:][::-1]
    
    # Return recommended opportunities
    return [opportunities[i] for i in recommendations]

# Function to load MarianMT translation model
def load_translation_model(target_language):
    model_name = f'Helsinki-NLP/opus-mt-en-{target_language}'
    tokenizer = MarianTokenizer.from_pretrained(model_name)
    model = MarianMTModel.from_pretrained(model_name)
    return model, tokenizer

# Function to translate text using MarianMT
def translate_text(text, target_language):
    try:
        model, tokenizer = load_translation_model(target_language)
        
        # Tokenize and translate text
        tokens = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
        translated = model.generate(**tokens)
        translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
        
        return translated_text
    except Exception as e:
        return f"Error during translation: {str(e)}"

# User input for profile
st.sidebar.header("User Profile")
location = st.sidebar.text_input("Location", "Pakistan")  # Default to 'Pakistan'
skills = st.sidebar.text_input("Skills (e.g., Python, Marketing)")
interests = st.sidebar.text_input("Interests (e.g., Technology, Science)")

# Fetch scholarships based on user input
scholarships = get_scholarships(location, interests)

# Display scholarships if available
if scholarships:
    st.write("Scholarships found:")
    for scholarship in scholarships:
        st.write(f"Title: {scholarship['title']}")
        st.write(f"Description: {scholarship['description']}")
        st.write(f"Eligibility: {scholarship['eligibility']}")
        st.write("---")
else:
    st.write("No scholarships found based on your criteria.")

# Fetch internships based on user input
internships = get_internships()

# Display internships if available
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.")

# AI-based recommendations for opportunities
if st.sidebar.button("Get AI Recommendations"):
    # Combine scholarships and internships for recommendations
    all_opportunities = scholarships + internships
    
    # Get AI recommendations based on user input
    recommended_opportunities = recommend_opportunities(interests, skills, all_opportunities)
    
    # Display recommended opportunities
    st.write("Recommended Opportunities based on your profile:")
    for opportunity in recommended_opportunities:
        st.write(f"Title: {opportunity['title']}")
        st.write(f"Description: {opportunity['description']}")
        st.write(f"Eligibility: {opportunity.get('eligibility', 'Not available')}")
        st.write("---")

# Language selection
languages = {
    'English': 'english',
    'German': 'deutch',
    'French': 'french',
    'Spanish': 'spanish',
    'Italian': 'italian',
    'Portuguese': 'portugese',
    'Chinese': 'chinese',
    'Arabic': 'arabic',
    'Russian': 'russian',
    'Japanese': 'japanese',
    'Korean': 'korean',
    'Urdu': 'urdu'
}

# Dropdown for language selection
selected_language = st.selectbox("Select Language", list(languages.keys()))

# Translate the opportunity description based on the selected language
if selected_language != 'English':
    # Translate the title of the app or a sample text
    translated_text = translate_text("Hello, welcome to AI Opportunity Finder!", languages[selected_language])
    st.write(f"Translated Text ({selected_language}): {translated_text}")