Spaces:
Running
Running
File size: 5,367 Bytes
ab78615 51d8377 55557c6 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 |
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}")
|