File size: 4,781 Bytes
26ce7c2
1b0456d
e95727f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b0456d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e95727f
1b0456d
 
 
e95727f
1b0456d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e95727f
1b0456d
e95727f
1b0456d
 
 
 
 
 
e95727f
1b0456d
 
 
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
import os
import gradio as gr
from groq import Groq
from googletrans import Translator
import asyncio

# Function to get recommendations from Groq AI based on user input
def get_opportunities(user_interests, user_skills, user_location):
    # Fetch the API key from the environment variable
    api_key = "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"
    
    if not api_key:
        raise ValueError("API key is missing. Make sure to set the GROQ_API_KEY environment variable.")
    
    # Initialize the Groq client with the API key
    client = Groq(api_key=api_key)
    
    # Construct the query
    query = f"Based on the user's interests in {user_interests}, skills in {user_skills}, and location of {user_location}, find scholarships, internships, online courses, and career advice suitable for them."
    
    # Request to Groq API
    response = client.chat.completions.create(
        messages=[{"role": "user", "content": query}],
        model="llama-3.3-70b-versatile",
    )
    
    return response.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

# Function to get chatbot response
def get_chatbot_response(user_message):
    # Fetch the API key from the environment variable
    api_key = "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"
    
    if not api_key:
        raise ValueError("API key is missing. Make sure to set the GROQ_API_KEY environment variable.")
    
    # Initialize the Groq client with the API key
    client = Groq(api_key=api_key)
    
    # Request to Groq API for chatbot response
    response = client.chat.completions.create(
        messages=[{"role": "user", "content": user_message}],
        model="llama-3.3-70b-versatile",
    )
    
    return response.choices[0].message.content

# Gradio interface
with gr.Blocks(css="""
    .gradio-container {
        background-color: #f0f0f5;
        color: #333;
        font-family: 'Roboto', sans-serif;
        padding: 20px;
        border-radius: 10px;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }
    .gradio-container .button {
        background-color: #007bff;
        color: white;
        padding: 12px;
        font-size: 16px;
        border-radius: 10px;
        border: none;
    }
    .gradio-container .button:hover {
        background-color: #0056b3;
    }
    .gradio-container .textbox {
        font-size: 16px;
        padding: 12px;
        border-radius: 10px;
        border: 1px solid #ccc;
    }
""") as demo:
    gr.Markdown("""
        <h1 style="text-align:center;">AI-Powered Opportunity Finder for Youth</h1>
        <p style="text-align:center;">Find scholarships, internships, online courses, and career advice based on your interests, skills, and location.</p>
    """)
    
    # Sidebar for input fields
    with gr.Column():
        gr.Markdown("### Provide your details to find opportunities")

        interests = gr.Textbox(label="Your Interests (e.g., AI, Robotics, Software Engineering):")
        skills = gr.Textbox(label="Your Skills (e.g., Python, Data Science, Web Development):")
        location = gr.Textbox(label="Your Location (e.g., Gujrat, Pakistan):")

        languages = gr.Dropdown(
            label="Select your preferred language:",
            choices=["English", "Spanish", "French", "German", "Italian", "Chinese", "Japanese", "Urdu"],
            value="English"
        )
        
        find_button = gr.Button("Find Opportunities")
    
    # Chatbot Section
    with gr.Column():
        gr.Markdown("### AI Chatbot")
        user_message = gr.Textbox(label="Ask anything to the chatbot:", lines=2)
        chatbot_output = gr.Textbox(label="Chatbot Response:", interactive=False)
    
    # Function to handle finding opportunities
    def find_opportunities_and_chat(interests, skills, location, language, user_message):
        # Fetch opportunities
        opportunities = get_opportunities(interests, skills, location)
        translated_opportunities = asyncio.run(translate_text(opportunities, language))
        
        # Get chatbot response
        chatbot_response = get_chatbot_response(user_message) if user_message else "Ask me anything!"
        
        return translated_opportunities, chatbot_response

    # Connect the button to the function
    find_button.click(
        find_opportunities_and_chat,
        inputs=[interests, skills, location, languages, user_message],
        outputs=[gr.Textbox(label="Recommended Opportunities"), chatbot_output]
    )

# Launch the Gradio app
if __name__ == "__main__":
    demo.launch()