Spaces:
Running
Running
import streamlit as st | |
import requests | |
# Set up the Streamlit page | |
st.title("AI Opportunity Finder for Youth") | |
st.write("Find Scholarships, Internships, Online Courses, and more!") | |
# Groq API URL and Authentication | |
GROQ_API_URL = "https://api.groq.ai" | |
API_KEY = "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" # Replace with your actual Groq API Key | |
# Function to fetch data from Groq API for scholarships | |
def get_scholarships(location, interests): | |
url = f"{GROQ_API_URL}/scholarships" | |
headers = { | |
'Authorization': f'Bearer {API_KEY}', | |
'Content-Type': 'application/json' | |
} | |
params = {"location": location, "interests": interests} | |
response = requests.get(url, headers=headers, params=params) | |
if response.status_code == 200: | |
scholarships = response.json() | |
return [{"title": scholarship['title'], "description": scholarship['description'], "eligibility": scholarship['eligibility']} for scholarship in scholarships] | |
else: | |
return [] | |
# Function to fetch data from Groq API for internships | |
def get_internships(): | |
url = f"{GROQ_API_URL}/internships" | |
headers = { | |
'Authorization': f'Bearer {API_KEY}', | |
'Content-Type': 'application/json' | |
} | |
response = requests.get(url, headers=headers) | |
if response.status_code == 200: | |
internships = response.json() | |
return [{"jobtitle": internship['jobtitle'], "company": internship['company'], "location": internship['location'], "snippet": internship['description']} for internship in internships] | |
else: | |
return [] | |
# Function to recommend opportunities using Groq's recommendation system | |
def recommend_opportunities(user_interests, user_skills, scholarships, internships): | |
# Combine user interests and skills into a profile for recommendation | |
user_profile = f"{user_interests} {user_skills}" | |
# API request to get recommendations (assumed Groq API endpoint) | |
url = f"{GROQ_API_URL}/recommendations" | |
headers = { | |
'Authorization': f'Bearer {API_KEY}', | |
'Content-Type': 'application/json' | |
} | |
data = { | |
"profile": user_profile, | |
"opportunities": scholarships + internships | |
} | |
response = requests.post(url, json=data, headers=headers) | |
if response.status_code == 200: | |
recommended_opportunities = response.json() | |
return recommended_opportunities | |
else: | |
return [] | |
# Streamlit Sidebar: User Profile Input | |
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 and Internships | |
scholarships = get_scholarships(location, interests) | |
internships = get_internships() | |
# 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.") | |
# 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 based on your criteria.") | |
# AI-based Recommendations for Opportunities | |
if st.sidebar.button("Get AI Recommendations"): | |
recommended_opportunities = recommend_opportunities(interests, skills, scholarships, internships) | |
if 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("---") | |
else: | |
st.write("No AI recommendations found.") | |
# Language selection for translation (optional) | |
languages = { | |
'English': 'en', | |
'German': 'German', | |
'French': 'French', | |
'Spanish': 'Spanish', | |
'Italian': 'Italian', | |
'Portuguese': 'Portuguese', | |
'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 text (Optional) | |
def translate_text(text, target_language): | |
# Example translation logic (replace with actual API call if necessary) | |
return f"Translated {text} to {target_language}" | |
# Display the translated text (if selected language is not English) | |
if selected_language != 'English': | |
translated_text = translate_text("Hello, welcome to AI Opportunity Finder!", languages[selected_language]) | |
st.write(f"Translated Text ({selected_language}): {translated_text}") | |