Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,15 +5,6 @@ import requests
|
|
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 = "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"
|
11 |
-
import requests
|
12 |
-
|
13 |
-
# Set up the Streamlit page
|
14 |
-
st.title("AI Opportunity Finder for Youth")
|
15 |
-
st.write("Find Scholarships, Internships, Online Courses, and more!")
|
16 |
-
|
17 |
# Groq API URL and Authentication
|
18 |
GROQ_API_URL = "https://api.groq.ai"
|
19 |
API_KEY = "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" # Replace with your actual Groq API Key
|
@@ -142,141 +133,6 @@ languages = {
|
|
142 |
# Dropdown for language selection
|
143 |
selected_language = st.selectbox("Select Language", list(languages.keys()))
|
144 |
|
145 |
-
# Translate text (Optional)
|
146 |
-
def translate_text(text, target_language):
|
147 |
-
# Example translation logic (replace with actual API call if necessary)
|
148 |
-
return f"Translated {text} to {target_language}"
|
149 |
-
|
150 |
-
# Display the translated text (if selected language is not English)
|
151 |
-
if selected_language != 'English':
|
152 |
-
translated_text = translate_text("Hello, welcome to AI Opportunity Finder!", languages[selected_language])
|
153 |
-
st.write(f"Translated Text ({selected_language}): {translated_text}")
|
154 |
-
" # Replace with your actual Groq API Key
|
155 |
-
|
156 |
-
# Function to fetch data from Groq API for scholarships
|
157 |
-
def get_scholarships(location, interests):
|
158 |
-
url = f"{GROQ_API_URL}/scholarships"
|
159 |
-
headers = {
|
160 |
-
'Authorization': f'Bearer {API_KEY}',
|
161 |
-
'Content-Type': 'application/json'
|
162 |
-
}
|
163 |
-
params = {"location": location, "interests": interests}
|
164 |
-
|
165 |
-
response = requests.get(url, headers=headers, params=params)
|
166 |
-
|
167 |
-
if response.status_code == 200:
|
168 |
-
scholarships = response.json()
|
169 |
-
return [{"title": scholarship['title'], "description": scholarship['description'], "eligibility": scholarship['eligibility']} for scholarship in scholarships]
|
170 |
-
else:
|
171 |
-
return []
|
172 |
-
|
173 |
-
# Function to fetch data from Groq API for internships
|
174 |
-
def get_internships():
|
175 |
-
url = f"{GROQ_API_URL}/internships"
|
176 |
-
headers = {
|
177 |
-
'Authorization': f'Bearer {API_KEY}',
|
178 |
-
'Content-Type': 'application/json'
|
179 |
-
}
|
180 |
-
|
181 |
-
response = requests.get(url, headers=headers)
|
182 |
-
|
183 |
-
if response.status_code == 200:
|
184 |
-
internships = response.json()
|
185 |
-
return [{"jobtitle": internship['jobtitle'], "company": internship['company'], "location": internship['location'], "snippet": internship['description']} for internship in internships]
|
186 |
-
else:
|
187 |
-
return []
|
188 |
-
|
189 |
-
# Function to recommend opportunities using Groq's recommendation system
|
190 |
-
def recommend_opportunities(user_interests, user_skills, scholarships, internships):
|
191 |
-
# Combine user interests and skills into a profile for recommendation
|
192 |
-
user_profile = f"{user_interests} {user_skills}"
|
193 |
-
|
194 |
-
# API request to get recommendations (assumed Groq API endpoint)
|
195 |
-
url = f"{GROQ_API_URL}/recommendations"
|
196 |
-
headers = {
|
197 |
-
'Authorization': f'Bearer {API_KEY}',
|
198 |
-
'Content-Type': 'application/json'
|
199 |
-
}
|
200 |
-
|
201 |
-
data = {
|
202 |
-
"profile": user_profile,
|
203 |
-
"opportunities": scholarships + internships
|
204 |
-
}
|
205 |
-
|
206 |
-
response = requests.post(url, json=data, headers=headers)
|
207 |
-
|
208 |
-
if response.status_code == 200:
|
209 |
-
recommended_opportunities = response.json()
|
210 |
-
return recommended_opportunities
|
211 |
-
else:
|
212 |
-
return []
|
213 |
-
|
214 |
-
# Streamlit Sidebar: User Profile Input
|
215 |
-
st.sidebar.header("User Profile")
|
216 |
-
location = st.sidebar.text_input("Location", "Pakistan") # Default to 'Pakistan'
|
217 |
-
skills = st.sidebar.text_input("Skills (e.g., Python, Marketing)")
|
218 |
-
interests = st.sidebar.text_input("Interests (e.g., Technology, Science)")
|
219 |
-
|
220 |
-
# Fetch Scholarships and Internships
|
221 |
-
scholarships = get_scholarships(location, interests)
|
222 |
-
internships = get_internships()
|
223 |
-
|
224 |
-
# Display Scholarships if available
|
225 |
-
if scholarships:
|
226 |
-
st.write("Scholarships found:")
|
227 |
-
for scholarship in scholarships:
|
228 |
-
st.write(f"**Title:** {scholarship['title']}")
|
229 |
-
st.write(f"**Description:** {scholarship['description']}")
|
230 |
-
st.write(f"**Eligibility:** {scholarship['eligibility']}")
|
231 |
-
st.write("---")
|
232 |
-
else:
|
233 |
-
st.write("No scholarships found based on your criteria.")
|
234 |
-
|
235 |
-
# Display Internships if available
|
236 |
-
if internships:
|
237 |
-
st.write("Internships found:")
|
238 |
-
for internship in internships:
|
239 |
-
st.write(f"**Title:** {internship['jobtitle']}")
|
240 |
-
st.write(f"**Company:** {internship['company']}")
|
241 |
-
st.write(f"**Location:** {internship['location']}")
|
242 |
-
st.write(f"**Snippet:** {internship['snippet']}")
|
243 |
-
st.write("---")
|
244 |
-
else:
|
245 |
-
st.write("No internships found based on your criteria.")
|
246 |
-
|
247 |
-
# AI-based Recommendations for Opportunities
|
248 |
-
if st.sidebar.button("Get AI Recommendations"):
|
249 |
-
recommended_opportunities = recommend_opportunities(interests, skills, scholarships, internships)
|
250 |
-
|
251 |
-
if recommended_opportunities:
|
252 |
-
st.write("Recommended Opportunities based on your profile:")
|
253 |
-
for opportunity in recommended_opportunities:
|
254 |
-
st.write(f"**Title:** {opportunity['title']}")
|
255 |
-
st.write(f"**Description:** {opportunity['description']}")
|
256 |
-
st.write(f"**Eligibility:** {opportunity.get('eligibility', 'Not available')}")
|
257 |
-
st.write("---")
|
258 |
-
else:
|
259 |
-
st.write("No AI recommendations found.")
|
260 |
-
|
261 |
-
# Language selection for translation (optional)
|
262 |
-
languages = {
|
263 |
-
'English': 'English',
|
264 |
-
'German': 'German',
|
265 |
-
'French': 'French',
|
266 |
-
'Spanish': 'Spanish',
|
267 |
-
'Italian': 'Italian',
|
268 |
-
'Portuguese': 'Portuguese',
|
269 |
-
'Chinese': 'Chinese',
|
270 |
-
'Arabic': 'Arabic',
|
271 |
-
'Russian': 'Russian',
|
272 |
-
'Japanese': 'Japanese',
|
273 |
-
'Korean': 'Korean',
|
274 |
-
'Urdu': 'Urdu'
|
275 |
-
}
|
276 |
-
|
277 |
-
# Dropdown for language selection
|
278 |
-
selected_language = st.selectbox("Select Language", list(languages.keys()))
|
279 |
-
|
280 |
# Translate text (Optional)
|
281 |
def translate_text(text, target_language):
|
282 |
# Example translation logic (replace with actual API call if necessary)
|
|
|
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 = "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" # Replace with your actual Groq API Key
|
|
|
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)
|