Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import os | |
| import openai | |
| from docx import Document | |
| from docx.shared import Pt | |
| # === Page Setup === | |
| st.set_page_config(page_title="π Smart Career Advisor", layout="centered") | |
| # === Groq API Key Setup === | |
| openai.api_key = os.getenv("GROQ_API_KEY") # Set this in Hugging Face > Settings > Secrets | |
| MODEL = "llama3-70b-8192" | |
| # === Query Function === | |
| def query_groq(prompt): | |
| try: | |
| response = openai.ChatCompletion.create( | |
| model=MODEL, | |
| messages=[{"role": "user", "content": prompt}] | |
| ) | |
| return response.choices[0].message["content"] | |
| except Exception as e: | |
| return f"β Error: {str(e)}" | |
| # === Word Export Function === | |
| def generate_doc(user_name, content): | |
| doc = Document() | |
| heading = doc.add_heading(user_name, level=1) | |
| heading.alignment = 1 # center | |
| style = doc.styles['Normal'] | |
| font = style.font | |
| font.name = 'Arial' | |
| font.size = Pt(11) | |
| for section in content.split('\n\n'): | |
| if section.strip(): | |
| doc.add_paragraph(section.strip()) | |
| filename = f"{user_name.replace(' ', '_')}_Career_Report.docx" | |
| doc.save(filename) | |
| return filename | |
| # === Sidebar Inputs === | |
| with st.sidebar: | |
| st.image("https://img.icons8.com/fluency/96/graduation-cap.png", width=100) | |
| st.title("π§ User Profile") | |
| user_name = st.text_input("π€ Full Name") | |
| education = st.selectbox("π Education Level", ["Matric", "Intermediate", "Bachelor", "Master", "M.Phil", "PhD"]) | |
| major = st.text_input("π Field of Study / Major") | |
| interests = st.multiselect("π― Interests", [ | |
| "Technology", "Arts", "Business", "Education", "Healthcare", "Design", "Public Service" | |
| ]) | |
| work_style = st.radio("π’ Preferred Work Style", ["Remote", "Field-based", "Office", "Freelance"]) | |
| goal = st.selectbox("π Career Goal", ["High Income", "Flexibility", "Social Impact", "Research"]) | |
| skills = st.text_area("π οΈ Skills or Strengths", placeholder="e.g., leadership, coding, communication") | |
| industry = st.text_input("π Preferred Industry (optional)") | |
| submit = st.button("π Generate Career Report") | |
| # === Main Title === | |
| st.markdown("<h1 style='text-align:center; color:#4B8BBE;'>π Smart Career Advisor</h1>", unsafe_allow_html=True) | |
| st.markdown("<p style='text-align:center;'>Get personalized career suggestions using GenAI</p>", unsafe_allow_html=True) | |
| # === Main Logic === | |
| if submit and user_name and interests: | |
| st.info("π Processing your profile. Please wait...") | |
| user_profile = f""" | |
| Name: {user_name} | |
| Education: {education} | |
| Major: {major} | |
| Interests: {', '.join(interests)} | |
| Work Style: {work_style} | |
| Career Goal: {goal} | |
| Skills: {skills} | |
| Preferred Industry: {industry} | |
| """ | |
| prompt = f""" | |
| You are a professional career counselor. Based on this user profile, generate a career guidance report in 5 sections: | |
| 1. Suggested Career Paths | |
| 2. Common Job Roles or Occupations | |
| 3. Required Skills or Certifications | |
| 4. Recommended Learning Resources (online courses, platforms) | |
| 5. Tips to Get Started | |
| User Profile: | |
| {user_profile} | |
| """ | |
| response = query_groq(prompt) | |
| # === Display Results === | |
| st.success("β Career Report Generated!") | |
| for section in response.split('\n\n'): | |
| if section.strip(): | |
| with st.expander(section.strip().split('\n')[0]): | |
| st.markdown(section.strip()) | |
| # === Word File Download === | |
| file_path = generate_doc(user_name, response) | |
| with open(file_path, "rb") as file: | |
| st.download_button( | |
| label="β¬οΈ Download Report as MS Word", | |
| data=file, | |
| file_name=file_path, | |
| mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document" | |
| ) | |
| # === Footer Developer Info === | |
| st.markdown("---") | |
| st.markdown("**π¨βπ» Developed by Najaf Ali Sharqi**") | |
| st.markdown(""" | |
| **About the Developer:** | |
| Najaf Ali Sharqi is an experienced educationist and AI integration specialist with a passion for building inclusive, smart applications for educators and students in low-resource settings. | |
| He specializes in curriculum development, GenAI tools, and digital innovation in the education sector. | |
| """) | |