File size: 2,952 Bytes
8c40a7c
851c6af
fd6e650
851c6af
 
ab78615
851c6af
3990d00
f0837ca
851c6af
 
fd6e650
851c6af
 
fd6e650
dc944de
851c6af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0837ca
851c6af
dc944de
851c6af
 
 
dc944de
851c6af
 
 
 
dc944de
851c6af
 
fd6e650
 
 
 
 
 
 
 
 
 
851c6af
f0837ca
851c6af
 
 
dc944de
 
851c6af
 
 
 
 
 
 
 
 
 
 
 
 
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
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()