Chatbot / app.py
saherPervaiz's picture
Update app.py
064ac70 verified
raw
history blame
2.98 kB
import os
import streamlit as st
from deep_translator import GoogleTranslator
from groq import Client # Assuming correct Groq API client import
# Ensure the API key is set
API_KEY = os.environ.get("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")
if not API_KEY:
st.error("API key is missing. Please set the GROQ_API_KEY environment variable.")
st.stop()
# Initialize the Groq client
client = Client(api_key=API_KEY)
# Streamlit App
st.set_page_config(page_title="AI-Powered Opportunity Finder", layout="wide")
st.title("AI-Powered Opportunity Finder for Youth")
# Sidebar for inputs
st.sidebar.header("Provide your details to find opportunities")
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):")
# Language selection for translation
languages = {
"English": "en",
"Spanish": "es",
"French": "fr",
"German": "de",
"Italian": "it",
"Chinese": "zh-cn",
"Japanese": "ja",
"Urdu": "ur",
}
selected_language = st.sidebar.selectbox("Select your preferred language:", list(languages.keys()))
# Main functionality
def fetch_opportunities(user_interests, user_skills, user_location):
query = (
f"Based on the user's interests in {user_interests}, skills in {user_skills}, "
f"and location of {user_location}, find scholarships, internships, online courses, and career advice."
)
try:
response = client.chat.completions.create(
messages=[{"role": "user", "content": query}],
model="llama-3.3-70b-versatile",
)
return response.choices[0].message.content
except Exception as e:
st.error(f"Error fetching opportunities: {e}")
return None
def translate_text(text, target_language):
try:
translator = GoogleTranslator(target=target_language)
return translator.translate(text)
except Exception as e:
st.error(f"Error translating text: {e}")
return text
# Button to fetch opportunities
if st.sidebar.button("Find Opportunities"):
if interests and skills and location:
with st.spinner("Fetching opportunities..."):
opportunities = fetch_opportunities(interests, skills, location)
if opportunities:
translated_opportunities = translate_text(opportunities, languages[selected_language])
st.subheader("Recommended Opportunities")
st.write(translated_opportunities)
else:
st.sidebar.error("Please fill in all fields.")
# Footer
st.markdown("""
<footer style="text-align:center; padding: 20px; font-size: 1rem; background-color: #f0f0f5;">
<p>Powered by Groq, Google Translator, and Streamlit</p>
<p>Contact: [email protected]</p>
</footer>
""", unsafe_allow_html=True)