Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,39 +5,18 @@ from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
|
| 5 |
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
|
| 6 |
|
| 7 |
# Load Hugging Face API Token
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
os.environ["HF_TOKEN"]= os.getenv("HF")
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
# model = HuggingFaceEndpoint(
|
| 14 |
-
# repo_id="deepseek-ai/DeepSeek-R1",
|
| 15 |
-
# provider="nebius",
|
| 16 |
-
# temperature=0.6,
|
| 17 |
-
# max_new_tokens=200,
|
| 18 |
-
# task="conversational"
|
| 19 |
-
# )
|
| 20 |
-
|
| 21 |
-
# # Wrap it into ChatHuggingFace interface
|
| 22 |
-
# llama_model = ChatHuggingFace(
|
| 23 |
-
# llm=model,
|
| 24 |
-
# repo_id="deepseek-ai/DeepSeek-R1",
|
| 25 |
-
# provider="nebius",
|
| 26 |
-
# temperature=0.6,
|
| 27 |
-
# max_new_tokens=200,
|
| 28 |
-
# task="conversational"
|
| 29 |
-
# )
|
| 30 |
-
|
| 31 |
-
|
| 32 |
model = HuggingFaceEndpoint(
|
| 33 |
repo_id="meta-llama/Llama-3.2-3B-Instruct",
|
| 34 |
provider="nebius",
|
| 35 |
temperature=0.6,
|
| 36 |
-
max_new_tokens=300,
|
| 37 |
task="conversational"
|
| 38 |
)
|
| 39 |
|
| 40 |
-
# Wrap it into ChatHuggingFace interface
|
| 41 |
llama_model = ChatHuggingFace(
|
| 42 |
llm=model,
|
| 43 |
repo_id="meta-llama/Llama-3.2-3B-Instruct",
|
|
@@ -50,8 +29,7 @@ llama_model = ChatHuggingFace(
|
|
| 50 |
# Initialize session message history
|
| 51 |
if "message_history" not in st.session_state:
|
| 52 |
st.session_state.message_history = [
|
| 53 |
-
SystemMessage(
|
| 54 |
-
content="""
|
| 55 |
You are an expert career advisor specializing in analyzing job descriptions and providing actionable insights to help job seekers tailor their resumes and skills for maximum impact.
|
| 56 |
|
| 57 |
Given a Job Description, extract and present the following sections using markdown formatting:
|
|
@@ -69,28 +47,58 @@ Recommend mini projects or learning paths to strengthen the candidate’s profil
|
|
| 69 |
Provide practical and specific tips to improve the candidate's resume, using bullet points.
|
| 70 |
|
| 71 |
Use **bold headings** for each section and markdown bullet points (`- `). Write in a professional yet friendly tone. Be concise, clear, and focused on actionable advice.
|
| 72 |
-
"""
|
| 73 |
-
)
|
| 74 |
]
|
| 75 |
|
| 76 |
-
#
|
| 77 |
-
st.
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
if jd_input.strip():
|
| 83 |
-
with st.spinner("Analyzing..."):
|
| 84 |
-
# Add user message to memory
|
| 85 |
st.session_state.message_history.append(HumanMessage(content=jd_input))
|
| 86 |
|
| 87 |
-
# Call model with full conversation context
|
| 88 |
try:
|
| 89 |
response = llama_model.invoke(st.session_state.message_history)
|
| 90 |
-
# Save and display response
|
| 91 |
st.session_state.message_history.append(AIMessage(content=response.content))
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
except Exception as e:
|
| 94 |
st.error(f"❌ Error occurred: {e}")
|
| 95 |
else:
|
| 96 |
-
st.warning("Please
|
|
|
|
| 5 |
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
|
| 6 |
|
| 7 |
# Load Hugging Face API Token
|
| 8 |
+
os.environ["HUGGINGFACEHUB_API_KEY"] = os.getenv("HF")
|
| 9 |
+
os.environ["HF_TOKEN"] = os.getenv("HF")
|
| 10 |
|
| 11 |
+
# Initialize model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
model = HuggingFaceEndpoint(
|
| 13 |
repo_id="meta-llama/Llama-3.2-3B-Instruct",
|
| 14 |
provider="nebius",
|
| 15 |
temperature=0.6,
|
| 16 |
+
max_new_tokens=300,
|
| 17 |
task="conversational"
|
| 18 |
)
|
| 19 |
|
|
|
|
| 20 |
llama_model = ChatHuggingFace(
|
| 21 |
llm=model,
|
| 22 |
repo_id="meta-llama/Llama-3.2-3B-Instruct",
|
|
|
|
| 29 |
# Initialize session message history
|
| 30 |
if "message_history" not in st.session_state:
|
| 31 |
st.session_state.message_history = [
|
| 32 |
+
SystemMessage(content="""
|
|
|
|
| 33 |
You are an expert career advisor specializing in analyzing job descriptions and providing actionable insights to help job seekers tailor their resumes and skills for maximum impact.
|
| 34 |
|
| 35 |
Given a Job Description, extract and present the following sections using markdown formatting:
|
|
|
|
| 47 |
Provide practical and specific tips to improve the candidate's resume, using bullet points.
|
| 48 |
|
| 49 |
Use **bold headings** for each section and markdown bullet points (`- `). Write in a professional yet friendly tone. Be concise, clear, and focused on actionable advice.
|
| 50 |
+
""")
|
|
|
|
| 51 |
]
|
| 52 |
|
| 53 |
+
# --- PAGE CONFIG ---
|
| 54 |
+
st.set_page_config(page_title="Smart JD Analyzer", page_icon="🧠", layout="wide")
|
| 55 |
+
|
| 56 |
+
# --- STYLING ---
|
| 57 |
+
st.markdown("""
|
| 58 |
+
<style>
|
| 59 |
+
.main-title { font-size: 36px; font-weight: bold; color: #4a7cfc; margin-bottom: 10px; }
|
| 60 |
+
.subtitle { font-size: 18px; color: #777777; margin-bottom: 30px; }
|
| 61 |
+
.textarea-style textarea {
|
| 62 |
+
border-radius: 10px;
|
| 63 |
+
padding: 20px;
|
| 64 |
+
font-size: 16px;
|
| 65 |
+
}
|
| 66 |
+
.output-container {
|
| 67 |
+
background-color: #f4f8ff;
|
| 68 |
+
border-radius: 10px;
|
| 69 |
+
padding: 25px;
|
| 70 |
+
margin-top: 20px;
|
| 71 |
+
box-shadow: 0 4px 8px rgba(0,0,0,0.05);
|
| 72 |
+
}
|
| 73 |
+
</style>
|
| 74 |
+
""", unsafe_allow_html=True)
|
| 75 |
+
|
| 76 |
+
# --- HEADER ---
|
| 77 |
+
st.markdown('<div class="main-title">🧠 Smart JD Analyzer</div>', unsafe_allow_html=True)
|
| 78 |
+
st.markdown('<div class="subtitle">Paste a job description to get technical skills, soft skills, mini-project ideas, and resume tips instantly!</div>', unsafe_allow_html=True)
|
| 79 |
+
|
| 80 |
+
# --- INPUT ---
|
| 81 |
+
jd_input = st.text_area("📄 Paste Job Description Below:", height=300, placeholder="Paste the full job description here...", key="jd_input", help="Paste any software/data-related JD here to analyze it.", label_visibility="visible")
|
| 82 |
+
|
| 83 |
+
# --- BUTTON ---
|
| 84 |
+
analyze = st.button("🔍 Analyze JD", use_container_width=True)
|
| 85 |
+
|
| 86 |
+
# --- RESPONSE ---
|
| 87 |
+
if analyze:
|
| 88 |
if jd_input.strip():
|
| 89 |
+
with st.spinner("Analyzing job description..."):
|
|
|
|
| 90 |
st.session_state.message_history.append(HumanMessage(content=jd_input))
|
| 91 |
|
|
|
|
| 92 |
try:
|
| 93 |
response = llama_model.invoke(st.session_state.message_history)
|
|
|
|
| 94 |
st.session_state.message_history.append(AIMessage(content=response.content))
|
| 95 |
+
|
| 96 |
+
with st.container():
|
| 97 |
+
st.markdown('<div class="output-container">', unsafe_allow_html=True)
|
| 98 |
+
st.markdown("### 📝 **Analysis Output**")
|
| 99 |
+
st.markdown(response.content, unsafe_allow_html=True)
|
| 100 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 101 |
except Exception as e:
|
| 102 |
st.error(f"❌ Error occurred: {e}")
|
| 103 |
else:
|
| 104 |
+
st.warning("⚠️ Please enter a valid job description before analyzing.")
|