AI / app.py
saherPervaiz's picture
Update app.py
c86c447 verified
raw
history blame
2.83 kB
import os
import streamlit as st
from groq import Groq
# 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
# 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("Provide your details to find opportunities")
# Collect user input for interests, skills, and location in the sidebar
interests = st.sidebar.text_input("Your Interests (e.g., AI, Robotics, Software Engineering):")
skills = st.sidebar.text_input("Your Skills (e.g., Python, Data Science, Web Development):")
location = st.sidebar.text_input("Your Location (e.g., Gujrat, Pakistan):")
# Container to display results
results_container = st.container()
# Button to fetch opportunities
if st.sidebar.button("Find Opportunities"):
if interests and skills and location:
with st.spinner("Fetching opportunities..."):
# Fetch recommendations using the Groq API
opportunities = get_opportunities(interests, skills, location)
# Display the opportunities
results_container.subheader("Recommended Opportunities")
results_container.write(opportunities)
else:
st.sidebar.error("Please fill all fields.")
# Add a footer with contact info
st.markdown("""
<footer style="text-align:center; padding: 20px; font-size: 1rem; background-color: #f0f0f5;">
<p>Powered by Groq and Streamlit | Contact: support@example.com</p>
</footer>
""", unsafe_allow_html=True)