Spaces:
No application file
No application file
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,126 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import gradio as gr
|
| 3 |
-
from groq import Groq
|
| 4 |
-
from googletrans import Translator
|
| 5 |
-
|
| 6 |
-
# Function to get recommendations from Groq AI based on user input
|
| 7 |
-
def get_opportunities(user_interests, user_skills, user_location):
|
| 8 |
-
api_key = "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" # Replace with your actual API key
|
| 9 |
-
|
| 10 |
-
if not api_key:
|
| 11 |
-
raise ValueError("API key is missing.")
|
| 12 |
-
|
| 13 |
-
# Initialize the Groq client with the API key
|
| 14 |
-
client = Groq(api_key=api_key)
|
| 15 |
-
|
| 16 |
-
# Construct the query
|
| 17 |
-
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."
|
| 18 |
-
|
| 19 |
-
# Request to Groq API
|
| 20 |
-
response = client.chat.completions.create(
|
| 21 |
-
messages=[{"role": "user", "content": query}],
|
| 22 |
-
model="llama-3.3-70b-versatile",
|
| 23 |
-
)
|
| 24 |
-
|
| 25 |
-
return response.choices[0].message.content
|
| 26 |
-
|
| 27 |
-
# Function to translate text into the selected language
|
| 28 |
-
def translate_text(text, target_language):
|
| 29 |
-
translator = Translator()
|
| 30 |
-
translated = translator.translate(text, dest=target_language)
|
| 31 |
-
return translated.text
|
| 32 |
-
|
| 33 |
-
# Function to get chatbot response
|
| 34 |
-
def get_chatbot_response(user_message):
|
| 35 |
-
api_key = "your_groq_api_key" # Replace with your actual API key
|
| 36 |
-
|
| 37 |
-
if not api_key:
|
| 38 |
-
raise ValueError("API key is missing.")
|
| 39 |
-
|
| 40 |
-
# Initialize the Groq client with the API key
|
| 41 |
-
client = Groq(api_key=api_key)
|
| 42 |
-
|
| 43 |
-
# Request to Groq API for chatbot response
|
| 44 |
-
response = client.chat.completions.create(
|
| 45 |
-
messages=[{"role": "user", "content": user_message}],
|
| 46 |
-
model="llama-3.3-70b-versatile",
|
| 47 |
-
)
|
| 48 |
-
|
| 49 |
-
return response.choices[0].message.content
|
| 50 |
-
|
| 51 |
-
# Gradio interface
|
| 52 |
-
with gr.Blocks(css="""
|
| 53 |
-
.gradio-container {
|
| 54 |
-
background-color: #f0f0f5;
|
| 55 |
-
color: #333;
|
| 56 |
-
font-family: 'Roboto', sans-serif;
|
| 57 |
-
padding: 20px;
|
| 58 |
-
border-radius: 10px;
|
| 59 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 60 |
-
}
|
| 61 |
-
.gradio-container .button {
|
| 62 |
-
background-color: #007bff;
|
| 63 |
-
color: white;
|
| 64 |
-
padding: 12px;
|
| 65 |
-
font-size: 16px;
|
| 66 |
-
border-radius: 10px;
|
| 67 |
-
border: none;
|
| 68 |
-
}
|
| 69 |
-
.gradio-container .button:hover {
|
| 70 |
-
background-color: #0056b3;
|
| 71 |
-
}
|
| 72 |
-
.gradio-container .textbox {
|
| 73 |
-
font-size: 16px;
|
| 74 |
-
padding: 12px;
|
| 75 |
-
border-radius: 10px;
|
| 76 |
-
border: 1px solid #ccc;
|
| 77 |
-
}
|
| 78 |
-
""") as demo:
|
| 79 |
-
gr.Markdown("""
|
| 80 |
-
<h1 style="text-align:center;">AI-Powered Opportunity Finder for Youth</h1>
|
| 81 |
-
<p style="text-align:center;">Find scholarships, internships, online courses, and career advice based on your interests, skills, and location.</p>
|
| 82 |
-
""")
|
| 83 |
-
|
| 84 |
-
# Sidebar for input fields
|
| 85 |
-
with gr.Column():
|
| 86 |
-
gr.Markdown("### Provide your details to find opportunities")
|
| 87 |
-
|
| 88 |
-
interests = gr.Textbox(label="Your Interests (e.g., AI, Robotics, Software Engineering):")
|
| 89 |
-
skills = gr.Textbox(label="Your Skills (e.g., Python, Data Science, Web Development):")
|
| 90 |
-
location = gr.Textbox(label="Your Location (e.g., Gujrat, Pakistan):")
|
| 91 |
-
|
| 92 |
-
languages = gr.Dropdown(
|
| 93 |
-
label="Select your preferred language:",
|
| 94 |
-
choices=["English", "Spanish", "French", "German", "Italian", "Chinese", "Japanese", "Urdu"],
|
| 95 |
-
value="English"
|
| 96 |
-
)
|
| 97 |
-
|
| 98 |
-
find_button = gr.Button("Find Opportunities")
|
| 99 |
-
|
| 100 |
-
# Chatbot Section
|
| 101 |
-
with gr.Column():
|
| 102 |
-
gr.Markdown("### AI Chatbot")
|
| 103 |
-
user_message = gr.Textbox(label="Ask anything to the chatbot:", lines=2)
|
| 104 |
-
chatbot_output = gr.Textbox(label="Chatbot Response:", interactive=False)
|
| 105 |
-
|
| 106 |
-
# Function to handle finding opportunities
|
| 107 |
-
def find_opportunities_and_chat(interests, skills, location, language, user_message):
|
| 108 |
-
# Fetch opportunities
|
| 109 |
-
opportunities = get_opportunities(interests, skills, location)
|
| 110 |
-
translated_opportunities = translate_text(opportunities, language)
|
| 111 |
-
|
| 112 |
-
# Get chatbot response
|
| 113 |
-
chatbot_response = get_chatbot_response(user_message) if user_message else "Ask me anything!"
|
| 114 |
-
|
| 115 |
-
return translated_opportunities, chatbot_response
|
| 116 |
-
|
| 117 |
-
# Connect the button to the function
|
| 118 |
-
find_button.click(
|
| 119 |
-
find_opportunities_and_chat,
|
| 120 |
-
inputs=[interests, skills, location, languages, user_message],
|
| 121 |
-
outputs=[gr.Textbox(label="Recommended Opportunities"), chatbot_output]
|
| 122 |
-
)
|
| 123 |
-
|
| 124 |
-
# Launch the Gradio app
|
| 125 |
-
if __name__ == "__main__":
|
| 126 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|