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