Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,71 @@
|
|
1 |
-
import streamlit as st
|
2 |
import os
|
|
|
3 |
from groq import Groq
|
4 |
|
5 |
# Function to get recommendations from Groq AI based on user input
|
6 |
def get_opportunities(user_interests, user_skills, user_location):
|
7 |
-
#
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
#
|
11 |
response = client.chat.completions.create(
|
12 |
-
messages=[{
|
13 |
-
|
14 |
-
"content": f"Find me opportunities like scholarships, internships, online courses, and career advice based on my interests: {user_interests}, skills: {user_skills}, and location: {user_location}"
|
15 |
-
}],
|
16 |
-
model="llama-3.3-70b-versatile", # You can adjust the model if needed
|
17 |
)
|
18 |
|
19 |
return response.choices[0].message.content
|
20 |
|
|
|
21 |
# Streamlit App Interface
|
|
|
22 |
st.title("AI-Powered Opportunity Finder for Youth")
|
23 |
|
24 |
-
#
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
# Button to fetch opportunities
|
30 |
-
if st.button("Find Opportunities"):
|
31 |
if interests and skills and location:
|
32 |
-
|
33 |
-
|
|
|
34 |
|
35 |
# Display the opportunities
|
36 |
-
|
37 |
-
|
38 |
else:
|
39 |
-
st.error("Please fill all fields.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import streamlit as st
|
3 |
from groq import Groq
|
4 |
|
5 |
# Function to get recommendations from Groq AI based on user input
|
6 |
def get_opportunities(user_interests, user_skills, user_location):
|
7 |
+
# Fetch the API key from the environment variable
|
8 |
+
api_key = os.environ.get("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")
|
9 |
+
|
10 |
+
if not api_key:
|
11 |
+
raise ValueError("API key is missing. Make sure to set the GROQ_API_KEY environment variable.")
|
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 |
+
|
28 |
# Streamlit App Interface
|
29 |
+
st.set_page_config(page_title="AI-Powered Opportunity Finder", page_icon=":bulb:", layout="wide")
|
30 |
st.title("AI-Powered Opportunity Finder for Youth")
|
31 |
|
32 |
+
# Custom CSS for improving the UI
|
33 |
+
st.markdown("""
|
34 |
+
<style>
|
35 |
+
.css-1v0mbdj {padding-top: 30px; font-size: 1.5rem;}
|
36 |
+
.css-1wa3m6h {padding: 10px; background-color: #f0f0f5;}
|
37 |
+
.css-1w4t6pm {border: 1px solid #ccc; padding: 10px; background-color: #fff;}
|
38 |
+
.css-1f4y1re {font-size: 1.2rem;}
|
39 |
+
</style>
|
40 |
+
""", unsafe_allow_html=True)
|
41 |
+
|
42 |
+
# Sidebar for input fields
|
43 |
+
st.sidebar.header("Provide your details to find opportunities")
|
44 |
+
|
45 |
+
# Collect user input for interests, skills, and location in the sidebar
|
46 |
+
interests = st.sidebar.text_input("Your Interests (e.g., AI, Robotics, Software Engineering):")
|
47 |
+
skills = st.sidebar.text_input("Your Skills (e.g., Python, Data Science, Web Development):")
|
48 |
+
location = st.sidebar.text_input("Your Location (e.g., Gujrat, Pakistan):")
|
49 |
+
|
50 |
+
# Container to display results
|
51 |
+
results_container = st.container()
|
52 |
|
53 |
# Button to fetch opportunities
|
54 |
+
if st.sidebar.button("Find Opportunities"):
|
55 |
if interests and skills and location:
|
56 |
+
with st.spinner("Fetching opportunities..."):
|
57 |
+
# Fetch recommendations using the Groq API
|
58 |
+
opportunities = get_opportunities(interests, skills, location)
|
59 |
|
60 |
# Display the opportunities
|
61 |
+
results_container.subheader("Recommended Opportunities")
|
62 |
+
results_container.write(opportunities)
|
63 |
else:
|
64 |
+
st.sidebar.error("Please fill all fields.")
|
65 |
+
|
66 |
+
# Add a footer with contact info
|
67 |
+
st.markdown("""
|
68 |
+
<footer style="text-align:center; padding: 20px; font-size: 1rem; background-color: #f0f0f5;">
|
69 |
+
<p>Powered by Groq and Streamlit | Contact: support@example.com</p>
|
70 |
+
</footer>
|
71 |
+
""", unsafe_allow_html=True)
|