File size: 2,850 Bytes
a1f8e73
9688ff7
 
 
 
a1f8e73
9688ff7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a1f8e73
9688ff7
 
 
 
 
a1f8e73
9688ff7
 
 
 
 
 
 
 
 
 
 
 
a1f8e73
9688ff7
 
 
 
 
 
 
 
 
 
 
 
 
 
a1f8e73
9688ff7
 
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
import gradio as gr
import os
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

# Chatbot interface function
def chatbot(input_text, interests, skills, location, language):
    if interests and skills and location:
        # Fetch recommendations using the Groq API
        opportunities = get_opportunities(interests, skills, location)
        
        # Run the async translate function and get the translated text
        translated_opportunities = asyncio.run(translate_text(opportunities, language))
        
        return translated_opportunities
    else:
        return "Please fill all fields: Interests, Skills, and Location."

# Gradio interface components
with gr.Blocks() as demo:
    gr.Markdown("# AI-Powered Opportunity Finder for Youth")
    
    with gr.Row():
        interests = gr.Textbox(label="Your Interests (e.g., AI, Robotics, Software Engineering):", placeholder="Enter your interests here...")
        skills = gr.Textbox(label="Your Skills (e.g., Python, Data Science, Web Development):", placeholder="Enter your skills here...")
        location = gr.Textbox(label="Your Location (e.g., Gujrat, Pakistan):", placeholder="Enter your location here...")
    
    language = gr.Dropdown(label="Select your preferred language:", choices=["English", "Spanish", "French", "German", "Italian", "Chinese", "Japanese", "Urdu"], value="English")
    
    with gr.Chatbot() as chatbot_output:
        submit_button = gr.Button("Find Opportunities")
        submit_button.click(chatbot, inputs=[gr.Textbox(), interests, skills, location, language], outputs=chatbot_output)

# Launch the app
demo.launch()