Spaces:
Running
Running
import asyncio | |
import os | |
import streamlit as st | |
from googletrans import Translator | |
from groq import Groq | |
# Initialize the Groq API client | |
client = Groq(api_key="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") | |
# Async function for translation | |
async def translate_text(text, target_language): | |
translator = Translator() | |
# Translate text asynchronously | |
translated = await translator.translate(text, dest=target_language) | |
return translated.text | |
# Fetch opportunities based on user input (interests, skills, location) | |
def get_opportunities(interests, skills, location): | |
# Placeholder for real opportunity fetching logic | |
# In your case, this would use Groq or another API to get dynamic data | |
return { | |
'scholarships': 'Here are some scholarship opportunities...', | |
'internships': 'Here are some internship opportunities...', | |
'courses': 'Here are some courses you can explore...' | |
} | |
# Async function to get translated opportunities | |
async def get_translated_opportunities(opportunities, selected_language): | |
translated_opportunities = {} | |
# Translate each opportunity | |
for opportunity_type, opportunity_list in opportunities.items(): | |
translated_opportunities[opportunity_type] = await translate_text(opportunity_list, selected_language) | |
return translated_opportunities | |
# Streamlit App Interface | |
def main(): | |
st.set_page_config(page_title="AI-Powered Opportunity Finder", page_icon=":bulb:", layout="wide") | |
st.title("AI-Powered Opportunity Finder for Youth") | |
# Custom CSS for improving the UI | |
st.markdown(""" | |
<style> | |
.css-1v0mbdj {padding-top: 30px; font-size: 1.5rem;} | |
.css-1wa3m6h {padding: 10px; background-color: #f0f0f5;} | |
.css-1w4t6pm {border: 1px solid #ccc; padding: 10px; background-color: #fff;} | |
.css-1f4y1re {font-size: 1.2rem;} | |
</style> | |
""", unsafe_allow_html=True) | |
# Sidebar for input fields | |
st.sidebar.header("Provide your details to find opportunities") | |
# Collect user input for interests, skills, and location in the sidebar | |
interests = st.sidebar.text_input("Your Interests (e.g., AI, Robotics, Software Engineering):") | |
skills = st.sidebar.text_input("Your Skills (e.g., Python, Data Science, Web Development):") | |
location = st.sidebar.text_input("Your Location (e.g., Gujrat, Pakistan):") | |
# Language selection | |
languages = { | |
"English": "English", | |
"Spanish": "Spanish", | |
"French": "French", | |
"German": "German", | |
"Italian": "Italian", | |
"Chinese": "Chinese", | |
"Japanese": "Japanese", | |
"Urdu": "Urdu" # Full word for Urdu | |
} | |
selected_language = st.sidebar.selectbox("Select your preferred language:", list(languages.keys())) | |
# Container to display results | |
results_container = st.container() | |
# Button to fetch opportunities | |
if st.sidebar.button("Find Opportunities"): | |
if interests and skills and location: | |
with st.spinner("Fetching opportunities..."): | |
# Fetch recommendations using the Groq API | |
opportunities = get_opportunities(interests, skills, location) | |
# Async translation of opportunities | |
translated_opportunities = asyncio.run(get_translated_opportunities(opportunities, languages[selected_language])) | |
# Display the opportunities | |
results_container.subheader(f"Recommended Opportunities in {selected_language}") | |
for opportunity_type, translated_text in translated_opportunities.items(): | |
results_container.markdown(f"**{opportunity_type.capitalize()}**: {translated_text}") | |
else: | |
st.sidebar.error("Please fill all fields.") | |
# Add a footer with contact info and clickable links | |
st.markdown(""" | |
<footer style="text-align:center; padding: 20px; font-size: 1rem; background-color: #f0f0f5;"> | |
<p>Powered by Groq, Google Translate, and Streamlit</p> | |
<p>For more opportunities, visit:</p> | |
<ul style="list-style-type:none; padding: 0;"> | |
<li><a href="https://www.groq.com" target="_blank">Groq - AI Solutions</a></li> | |
<li><a href="https://www.scholarships.com" target="_blank">Scholarships.com</a></li> | |
<li><a href="https://www.coursera.org" target="_blank">Coursera - Online Courses</a></li> | |
<li><a href="https://www.linkedin.com/jobs" target="_blank">LinkedIn Jobs</a></li> | |
</ul> | |
<p>Contact: [email protected]</p> | |
</footer> | |
""", unsafe_allow_html=True) | |
# Run the app | |
if __name__ == "__main__": | |
main() | |