Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,150 +1,144 @@
|
|
1 |
import streamlit as st
|
2 |
import requests
|
3 |
-
from sklearn.feature_extraction.text import TfidfVectorizer
|
4 |
-
from sklearn.metrics.pairwise import cosine_similarity
|
5 |
-
from transformers import MarianMTModel, MarianTokenizer
|
6 |
-
import sentencepiece
|
7 |
|
8 |
# Set up the Streamlit page
|
9 |
st.title("AI Opportunity Finder for Youth")
|
10 |
st.write("Find Scholarships, Internships, Online Courses, and more!")
|
11 |
|
12 |
-
#
|
|
|
|
|
|
|
|
|
13 |
def get_scholarships(location, interests):
|
14 |
-
url = "
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
if response.status_code == 200:
|
18 |
-
|
19 |
-
return [{"title":
|
20 |
else:
|
21 |
return []
|
22 |
|
23 |
-
# Function to
|
24 |
def get_internships():
|
25 |
-
url = "
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
if response.status_code == 200:
|
29 |
-
|
30 |
-
return [{"jobtitle":
|
31 |
else:
|
32 |
return []
|
33 |
|
34 |
-
# Function to recommend opportunities
|
35 |
-
def recommend_opportunities(user_interests, user_skills,
|
36 |
-
# Combine user
|
37 |
-
user_profile =
|
38 |
|
39 |
-
#
|
40 |
-
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
45 |
|
46 |
-
|
47 |
-
cosine_sim = cosine_similarity(tfidf_matrix[-1], tfidf_matrix[:-1])
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
# Function to load MarianMT translation model
|
56 |
-
def load_translation_model(target_language):
|
57 |
-
model_name = f'Helsinki-NLP/opus-mt-en-{target_language}'
|
58 |
-
tokenizer = MarianTokenizer.from_pretrained(model_name)
|
59 |
-
model = MarianMTModel.from_pretrained(model_name)
|
60 |
-
return model, tokenizer
|
61 |
-
|
62 |
-
# Function to translate text using MarianMT
|
63 |
-
def translate_text(text, target_language):
|
64 |
-
try:
|
65 |
-
model, tokenizer = load_translation_model(target_language)
|
66 |
-
|
67 |
-
# Tokenize and translate text
|
68 |
-
tokens = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
69 |
-
translated = model.generate(**tokens)
|
70 |
-
translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
|
71 |
-
|
72 |
-
return translated_text
|
73 |
-
except Exception as e:
|
74 |
-
return f"Error during translation: {str(e)}"
|
75 |
|
76 |
-
# User
|
77 |
st.sidebar.header("User Profile")
|
78 |
location = st.sidebar.text_input("Location", "Pakistan") # Default to 'Pakistan'
|
79 |
skills = st.sidebar.text_input("Skills (e.g., Python, Marketing)")
|
80 |
interests = st.sidebar.text_input("Interests (e.g., Technology, Science)")
|
81 |
|
82 |
-
# Fetch
|
83 |
scholarships = get_scholarships(location, interests)
|
|
|
84 |
|
85 |
-
# Display
|
86 |
if scholarships:
|
87 |
st.write("Scholarships found:")
|
88 |
for scholarship in scholarships:
|
89 |
-
st.write(f"Title
|
90 |
-
st.write(f"Description
|
91 |
-
st.write(f"Eligibility
|
92 |
st.write("---")
|
93 |
else:
|
94 |
st.write("No scholarships found based on your criteria.")
|
95 |
|
96 |
-
#
|
97 |
-
internships = get_internships()
|
98 |
-
|
99 |
-
# Display internships if available
|
100 |
if internships:
|
101 |
st.write("Internships found:")
|
102 |
for internship in internships:
|
103 |
-
st.write(f"Title
|
104 |
-
st.write(f"Company
|
105 |
-
st.write(f"Location
|
106 |
-
st.write(f"Snippet
|
107 |
st.write("---")
|
108 |
else:
|
109 |
-
st.write("No internships found.")
|
110 |
|
111 |
-
# AI-based
|
112 |
if st.sidebar.button("Get AI Recommendations"):
|
113 |
-
|
114 |
-
all_opportunities = scholarships + internships
|
115 |
-
|
116 |
-
# Get AI recommendations based on user input
|
117 |
-
recommended_opportunities = recommend_opportunities(interests, skills, all_opportunities)
|
118 |
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
126 |
|
127 |
-
# Language selection
|
128 |
languages = {
|
129 |
-
'English': '
|
130 |
-
'German': '
|
131 |
-
'French': '
|
132 |
-
'Spanish': '
|
133 |
-
'Italian': '
|
134 |
-
'Portuguese': '
|
135 |
-
'Chinese': '
|
136 |
-
'Arabic': '
|
137 |
-
'Russian': '
|
138 |
-
'Japanese': '
|
139 |
-
'Korean': '
|
140 |
-
'Urdu': '
|
141 |
}
|
142 |
|
143 |
# Dropdown for language selection
|
144 |
selected_language = st.selectbox("Select Language", list(languages.keys()))
|
145 |
|
146 |
-
# Translate
|
|
|
|
|
|
|
|
|
|
|
147 |
if selected_language != 'English':
|
148 |
-
# Translate the title of the app or a sample text
|
149 |
translated_text = translate_text("Hello, welcome to AI Opportunity Finder!", languages[selected_language])
|
150 |
st.write(f"Translated Text ({selected_language}): {translated_text}")
|
|
|
1 |
import streamlit as st
|
2 |
import requests
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# Set up the Streamlit page
|
5 |
st.title("AI Opportunity Finder for Youth")
|
6 |
st.write("Find Scholarships, Internships, Online Courses, and more!")
|
7 |
|
8 |
+
# Groq API URL and Authentication
|
9 |
+
GROQ_API_URL = "https://api.groq.ai"
|
10 |
+
API_KEY = "YOUR_GROQ_API_KEY" # Replace with your actual Groq API Key
|
11 |
+
|
12 |
+
# Function to fetch data from Groq API for scholarships
|
13 |
def get_scholarships(location, interests):
|
14 |
+
url = f"{GROQ_API_URL}/scholarships"
|
15 |
+
headers = {
|
16 |
+
'Authorization': f'Bearer {API_KEY}',
|
17 |
+
'Content-Type': 'application/json'
|
18 |
+
}
|
19 |
+
params = {"location": location, "interests": interests}
|
20 |
+
|
21 |
+
response = requests.get(url, headers=headers, params=params)
|
22 |
|
23 |
if response.status_code == 200:
|
24 |
+
scholarships = response.json()
|
25 |
+
return [{"title": scholarship['title'], "description": scholarship['description'], "eligibility": scholarship['eligibility']} for scholarship in scholarships]
|
26 |
else:
|
27 |
return []
|
28 |
|
29 |
+
# Function to fetch data from Groq API for internships
|
30 |
def get_internships():
|
31 |
+
url = f"{GROQ_API_URL}/internships"
|
32 |
+
headers = {
|
33 |
+
'Authorization': f'Bearer {API_KEY}',
|
34 |
+
'Content-Type': 'application/json'
|
35 |
+
}
|
36 |
+
|
37 |
+
response = requests.get(url, headers=headers)
|
38 |
|
39 |
if response.status_code == 200:
|
40 |
+
internships = response.json()
|
41 |
+
return [{"jobtitle": internship['jobtitle'], "company": internship['company'], "location": internship['location'], "snippet": internship['description']} for internship in internships]
|
42 |
else:
|
43 |
return []
|
44 |
|
45 |
+
# Function to recommend opportunities using Groq's recommendation system
|
46 |
+
def recommend_opportunities(user_interests, user_skills, scholarships, internships):
|
47 |
+
# Combine user interests and skills into a profile for recommendation
|
48 |
+
user_profile = f"{user_interests} {user_skills}"
|
49 |
|
50 |
+
# API request to get recommendations (assumed Groq API endpoint)
|
51 |
+
url = f"{GROQ_API_URL}/recommendations"
|
52 |
+
headers = {
|
53 |
+
'Authorization': f'Bearer {API_KEY}',
|
54 |
+
'Content-Type': 'application/json'
|
55 |
+
}
|
56 |
|
57 |
+
data = {
|
58 |
+
"profile": user_profile,
|
59 |
+
"opportunities": scholarships + internships
|
60 |
+
}
|
61 |
|
62 |
+
response = requests.post(url, json=data, headers=headers)
|
|
|
63 |
|
64 |
+
if response.status_code == 200:
|
65 |
+
recommended_opportunities = response.json()
|
66 |
+
return recommended_opportunities
|
67 |
+
else:
|
68 |
+
return []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
+
# Streamlit Sidebar: User Profile Input
|
71 |
st.sidebar.header("User Profile")
|
72 |
location = st.sidebar.text_input("Location", "Pakistan") # Default to 'Pakistan'
|
73 |
skills = st.sidebar.text_input("Skills (e.g., Python, Marketing)")
|
74 |
interests = st.sidebar.text_input("Interests (e.g., Technology, Science)")
|
75 |
|
76 |
+
# Fetch Scholarships and Internships
|
77 |
scholarships = get_scholarships(location, interests)
|
78 |
+
internships = get_internships()
|
79 |
|
80 |
+
# Display Scholarships if available
|
81 |
if scholarships:
|
82 |
st.write("Scholarships found:")
|
83 |
for scholarship in scholarships:
|
84 |
+
st.write(f"**Title:** {scholarship['title']}")
|
85 |
+
st.write(f"**Description:** {scholarship['description']}")
|
86 |
+
st.write(f"**Eligibility:** {scholarship['eligibility']}")
|
87 |
st.write("---")
|
88 |
else:
|
89 |
st.write("No scholarships found based on your criteria.")
|
90 |
|
91 |
+
# Display Internships if available
|
|
|
|
|
|
|
92 |
if internships:
|
93 |
st.write("Internships found:")
|
94 |
for internship in internships:
|
95 |
+
st.write(f"**Title:** {internship['jobtitle']}")
|
96 |
+
st.write(f"**Company:** {internship['company']}")
|
97 |
+
st.write(f"**Location:** {internship['location']}")
|
98 |
+
st.write(f"**Snippet:** {internship['snippet']}")
|
99 |
st.write("---")
|
100 |
else:
|
101 |
+
st.write("No internships found based on your criteria.")
|
102 |
|
103 |
+
# AI-based Recommendations for Opportunities
|
104 |
if st.sidebar.button("Get AI Recommendations"):
|
105 |
+
recommended_opportunities = recommend_opportunities(interests, skills, scholarships, internships)
|
|
|
|
|
|
|
|
|
106 |
|
107 |
+
if recommended_opportunities:
|
108 |
+
st.write("Recommended Opportunities based on your profile:")
|
109 |
+
for opportunity in recommended_opportunities:
|
110 |
+
st.write(f"**Title:** {opportunity['title']}")
|
111 |
+
st.write(f"**Description:** {opportunity['description']}")
|
112 |
+
st.write(f"**Eligibility:** {opportunity.get('eligibility', 'Not available')}")
|
113 |
+
st.write("---")
|
114 |
+
else:
|
115 |
+
st.write("No AI recommendations found.")
|
116 |
|
117 |
+
# Language selection for translation (optional)
|
118 |
languages = {
|
119 |
+
'English': 'English',
|
120 |
+
'German': 'German',
|
121 |
+
'French': 'French',
|
122 |
+
'Spanish': 'Spanish',
|
123 |
+
'Italian': 'Italian',
|
124 |
+
'Portuguese': 'Portuguese',
|
125 |
+
'Chinese': 'Chinese',
|
126 |
+
'Arabic': 'Arabic',
|
127 |
+
'Russian': 'Russian',
|
128 |
+
'Japanese': 'Japanese',
|
129 |
+
'Korean': 'Korean',
|
130 |
+
'Urdu': 'Urdu'
|
131 |
}
|
132 |
|
133 |
# Dropdown for language selection
|
134 |
selected_language = st.selectbox("Select Language", list(languages.keys()))
|
135 |
|
136 |
+
# Translate text (Optional)
|
137 |
+
def translate_text(text, target_language):
|
138 |
+
# Example translation logic (replace with actual API call if necessary)
|
139 |
+
return f"Translated {text} to {target_language}"
|
140 |
+
|
141 |
+
# Display the translated text (if selected language is not English)
|
142 |
if selected_language != 'English':
|
|
|
143 |
translated_text = translate_text("Hello, welcome to AI Opportunity Finder!", languages[selected_language])
|
144 |
st.write(f"Translated Text ({selected_language}): {translated_text}")
|