import streamlit as st from datetime import datetime, date import os # Ensure the groq package is available try: from groq import Groq except ImportError: st.error("❌ The 'groq' package is not installed. Please add it to requirements.txt.") st.stop() # Function to calculate age def calculate_age(birthdate_str): birthdate = datetime.strptime(birthdate_str, "%Y-%m-%d").date() today = date.today() years = today.year - birthdate.year months = today.month - birthdate.month days = today.day - birthdate.day if days < 0: months -= 1 previous_month = today.month - 1 or 12 previous_year = today.year if today.month > 1 else today.year - 1 last_day_previous_month = (date(previous_year, previous_month + 1, 1) - date(previous_year, previous_month, 1)).days days += last_day_previous_month if months < 0: years -= 1 months += 12 return years, months, days # Function to get suggestions from Groq def get_career_business_ideas(name, degree, country, age): api_key = os.environ.get("GROQ_API_KEY") if not api_key: return "❌ GROQ_API_KEY is not set. Please add it in the Hugging Face 'Secrets'." try: client = Groq(api_key=api_key) prompt = ( f"User Info:\n" f"Name: {name}\n" f"Education: {degree}\n" f"Country: {country}\n" f"Age: {age} years old\n\n" f"Based on this information, suggest the most suitable career paths and business ideas " f"that align with their background and local opportunities in {country}." ) chat_completion = client.chat.completions.create( messages=[{"role": "user", "content": prompt}], model="llama-3.3-70b-versatile", stream=False, ) return chat_completion.choices[0].message.content except Exception as e: return f"❌ Error while contacting Groq API: {str(e)}" # Streamlit UI st.set_page_config(page_title="🎓 Age & Career Advisor", layout="centered") st.title("🎓 Age & Career Advisor") with st.form("user_form"): name = st.text_input("Full Name") degree = st.selectbox("Highest Degree Obtained", ["High School", "Bachelor's", "Master's", "PhD", "Other"]) country = st.text_input("Country of Origin") birthdate = st.date_input("Date of Birth", min_value=date(1925, 1, 1), max_value=date.today()) submitted = st.form_submit_button("Submit") if submitted: if name and country: years, months, days = calculate_age(str(birthdate)) st.success(f"🕒 {name}, your age is {years} years, {months} months, and {days} days.") with st.spinner("💡 Generating career and business suggestions..."): suggestions = get_career_business_ideas(name, degree, country, years) st.subheader("💼 Career & Business Ideas") st.write(suggestions) else: st.warning("Please enter all required fields (Name and Country).")