Spaces:
Running
Running
import asyncio | |
import streamlit as st | |
from googletrans import Translator | |
from groq import Groq | |
import os | |
# 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 | |
# Main Streamlit UI code | |
def main(): | |
st.title("Opportunity Finder for Youth") | |
# User input for interests, skills, and location | |
interests = st.text_input("Enter your interests (e.g., technology, science)") | |
skills = st.text_input("Enter your skills (e.g., coding, research)") | |
location = st.text_input("Enter your location (e.g., Lahore, Pakistan)") | |
# Dropdown to select language | |
language_options = { | |
"English": "English", | |
"Spanish": "Spanish", | |
"French": "French", | |
"German": "German", | |
"Italian": "Italian", | |
"Chinese": "Chinese", | |
"Japanese": "Japanese", | |
"Urdu": "Urdu" # Full word for Urdu | |
} | |
selected_language = st.selectbox("Select your language", list(language_options.keys())) | |
# Fetch opportunities based on user input | |
if st.button("Find Opportunities"): | |
if interests and skills and location: | |
opportunities = get_opportunities(interests, skills, location) | |
# Async translation of opportunities | |
translated_opportunities = asyncio.run(get_translated_opportunities(opportunities, language_options[selected_language])) | |
# Display translated opportunities | |
st.subheader(f"Opportunities in {selected_language}:") | |
for opportunity_type, translated_text in translated_opportunities.items(): | |
st.markdown(f"**{opportunity_type.capitalize()}**: {translated_text}") | |
else: | |
st.error("Please fill out all fields (interests, skills, location) to get recommendations.") | |
# Run the app | |
if __name__ == "__main__": | |
main() | |