File size: 6,324 Bytes
d773c30 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | #--------------- NEW Design CODE-------------------------#
import streamlit as st
import google.generativeai as genai
import fitz
import docx
import pandas as pd
from streamlit_autorefresh import st_autorefresh
# --- PAGE CONFIG ---
st.set_page_config(page_title="Tech Career Coach", layout="wide")
# --- Wake Up Mode---- #
st_autorefresh(interval=10 * 60 * 1000, limit=None, key="auto_refresh")
# --- SIDEBAR NAVIGATION ---
st.sidebar.title("π Navigation")
menu = st.sidebar.radio("Go to", ["Chatbot", "Resume Review", "Mentor Match", "Learning Path"])
# --- GEMINI CONFIG ---
api_key = st.secrets["GEMINI_API_KEY"]
genai.configure(api_key=api_key)
model = genai.GenerativeModel("gemini-1.5-flash")
# --- SESSION STATE ---
if "messages" not in st.session_state:
st.session_state["messages"] = []
# --- PROMPT FUNCTION ---
def ask_single_prompt(prompt_text):
try:
response = model.generate_content(prompt_text)
return response.text
except Exception as e:
st.error(f"β Error: {str(e)}")
return None
# --- CHATBOT PAGE ---
if menu == "Chatbot":
st.title("π¬ Tech Career Coach Chatbot")
st.caption("Ask about careers, mentorship, or learning paths.")
for msg in st.session_state["messages"]:
who = "π§" if msg["role"] == "user" else "π€"
st.markdown(f"{who}: **{msg['parts']}**")
user_input = st.chat_input("Type your question...")
if user_input:
st.session_state["messages"].append({"role": "user", "parts": user_input})
try:
response = model.generate_content(st.session_state["messages"])
st.session_state["messages"].append({"role": "model", "parts": response.text})
st.rerun()
except Exception as e:
st.error(f"β Error: {str(e)}")
# --- RESUME REVIEW PAGE ---
elif menu == "Resume Review":
st.title("π Resume Reviewer")
uploaded_file = st.file_uploader("Upload your resume (PDF, DOCX, or TXT)", type=["pdf", "docx", "txt"])
def extract_text_from_file(uploaded_file):
file_type = uploaded_file.name.split('.')[-1].lower()
if file_type == "txt":
return uploaded_file.read().decode("utf-8")
elif file_type == "pdf":
pdf = fitz.open(stream=uploaded_file.read(), filetype="pdf")
return "".join([page.get_text() for page in pdf])
elif file_type == "docx":
doc = docx.Document(uploaded_file)
return "\n".join([para.text for para in doc.paragraphs])
return "Unsupported file type."
if uploaded_file:
extracted_text = extract_text_from_file(uploaded_file)
st.markdown("**: Uploaded resume for review.**")
reply = ask_single_prompt(f"Please review this resume:{extracted_text}")
if reply:
st.markdown(f"π€: {reply}")
# --- MENTOR MATCH PAGE ---
elif menu == "Mentor Match":
st.title("Mentor Match")
st.markdown("Find mentors based on your interests, preferences, and location.")
df = pd.read_csv("mentors.csv")
with st.container():
col1, col2, col3 = st.columns(3)
field = col1.selectbox("π― Field of interest", sorted(df["field"].unique()))
gender = col2.selectbox("π» Preferred gender", ["Any", "Female", "Male"])
location = col3.selectbox("π Preferred location", ["Any"] + sorted(df["location"].unique()))
# Filter logic
filtered = df[df["field"] == field]
if gender != "Any":
filtered = filtered[filtered["gender"] == gender]
if location != "Any":
filtered = filtered[filtered["location"] == location]
st.divider()
st.subheader("β¨ Top Mentor Recommendations")
if not filtered.empty:
for _, mentor in filtered.head(3).iterrows():
# st.markdown(f"""
# <div style='padding: 1rem; border: 1px solid #DDD; border-radius: 10px; margin-bottom: 1rem; background-color: #f9f9f9;'>
# <h4 style="margin-bottom: 0.3rem; color: black;">{mentor['name']}</h4>
# <p style="margin: 0.2rem 0;">
# <strong>π Location:</strong> {mentor['location']} |
# <strong>πΌ Field:</strong> {mentor['field']} |
# <strong>π» Gender:</strong> {mentor['gender']}
# </p>
# <p style="margin: 0.2rem 0;">
# <strong>π§ Email:</strong> <code>{mentor['email']}</code> |
# <strong>π Experience:</strong> {mentor['experience']} years
# </p>
# </div>
# """, unsafe_allow_html=True)
st.markdown(f"""
<div style='padding: 1rem; border: 1px solid #DDD; border-radius: 10px; margin-bottom: 1rem; background-color: #f9f9f9; color: black;'>
<h4 style="margin-bottom: 0.3rem; color: inherit;">{mentor['name']}</h4>
<p style="margin: 0.2rem 0;">
<strong>π Location:</strong> {mentor['location']} |
<strong>πΌ Field:</strong> {mentor['field']} |
<strong>π» Gender:</strong> {mentor['gender']}
</p>
<p style="margin: 0.2rem 0;">
<strong>π§ Email:</strong> <code>{mentor['email']}</code> |
<strong>π Experience:</strong> {mentor['experience']} years
</p>
</div>
""", unsafe_allow_html=True)
else:
st.warning("No mentors match your filters. Try adjusting the criteria.")
# --- LEARNING PATH PAGE ---
elif menu == "Learning Path":
st.title("π Personalized Learning Path")
domain = st.selectbox("Choose a career track:", [
"Frontend Development", "Data Science", "Cloud Engineering",
"Cybersecurity", "Product Management", "AI/ML",
"UX Design", "Backend Development", "Full Stack Development", "Data Engineering"
])
if st.button("Suggest Learning Path"):
prompt = f"Suggest a beginner-to-intermediate learning path using freeCodeCamp or Coursera for someone interested in becoming a {domain}. Include key skills and timeline."
reply = ask_single_prompt(prompt)
if reply:
st.markdown(f"π€: {reply}") |