File size: 4,072 Bytes
26ce7c2
 
 
 
 
 
dd70a62
2038bb2
dd70a62
 
26ce7c2
dd70a62
 
 
 
26ce7c2
 
dd70a62
 
26ce7c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd70a62
 
 
 
 
 
 
 
 
 
 
26ce7c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import streamlit as st
from groq import Groq
from googletrans import Translator
import asyncio

# Initialize the Groq client
client = Groq(api_key="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")

# Function to get recommendations from Groq API based on user input
def get_opportunities(user_query):
    # Create a chat completion request
    chat_completion = client.chat.completions.create(
        messages=[{"role": "user", "content": user_query}],
        model="llama-3.3-70b-versatile"
    )
    
    # Return the response content
    return chat_completion.choices[0].message.content

# Function to translate text into the selected language (async version)
async def translate_text(text, target_language):
    translator = Translator()
    translated = await translator.translate(text, dest=target_language)
    return translated.text

# Streamlit App Interface
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("Ask the AI Chatbot for Opportunities")

# Language selection
languages = {
    "English": "English",
    "Spanish": "Spanish",
    "French": "French",
    "German": "German",
    "Italian": "Italian",
    "Chinese": "Chinese",
    "Japanese": "Japanese",
    "Urdu": "Urdu"
}

selected_language = st.sidebar.selectbox("Select your preferred language:", list(languages.keys()))

# Chat history
if "messages" not in st.session_state:
    st.session_state.messages = []

# Display chat history
for message in st.session_state.messages:
    if message["role"] == "user":
        st.markdown(f"**You:** {message['content']}")
    else:
        st.markdown(f"**AI:** {message['content']}")

# Input box for user query
user_query = st.text_input("Ask me about scholarships, internships, or online courses:")

# Button to send message to chatbot
if st.button("Send"):
    if user_query:
        # Append user query to chat history
        st.session_state.messages.append({"role": "user", "content": user_query})
        
        with st.spinner("Fetching opportunities..."):
            try:
                # Get the opportunity details based on user query
                opportunities = get_opportunities(user_query)
                
                # Run the async translate function and get the translated text
                translated_opportunities = asyncio.run(translate_text(opportunities, languages[selected_language]))
                
                # Append AI response to chat history
                st.session_state.messages.append({"role": "ai", "content": translated_opportunities})
            except Exception as e:
                st.error(f"Error: {e}")
        
        # Scroll to the latest message
        st.experimental_rerun()
    else:
        st.error("Please enter a query.")

# 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)