JD_Analyzer_AI / app.py
Yashvj123's picture
Update app.py
5e33ba4 verified
import streamlit as st
import os
from langchain_core.prompts import ChatPromptTemplate
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
os.environ["HUGGINGFACEHUB_API_KEY"] = os.getenv("HF")
os.environ["HF_TOKEN"] = os.getenv("HF")
model = HuggingFaceEndpoint(
repo_id="meta-llama/Llama-3.2-3B-Instruct",
provider="novita",
temperature=0.6,
max_new_tokens=300,
task="conversational"
)
llama_model = ChatHuggingFace(
llm=model,
repo_id="meta-llama/Llama-3.2-3B-Instruct",
provider="novita",
temperature=0.6,
max_new_tokens=300,
task="conversational"
)
# session message history
if "message_history" not in st.session_state:
st.session_state.message_history = [
SystemMessage(content="""
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.
Given a Job Description, extract and present the following sections using markdown formatting:
**1. Key Technical Skills**
List the main technical skills required using bullet points.
**2. Important Soft Skills**
List the soft skills emphasized by the employer using bullet points.
**3. Suggested Mini Projects**
Recommend mini projects or learning paths to strengthen the candidate’s profile, using bullet points.
**4. Resume Improvement Tips**
Provide practical and specific tips to improve the candidate's resume, using bullet points.
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.
""")
]
st.set_page_config(page_title="Smart JD Analyzer", page_icon="🧠", layout="wide")
st.markdown("""
<style>
.main-title { font-size: 36px; font-weight: bold; color: #4a7cfc; margin-bottom: 10px; }
.subtitle { font-size: 18px; color: #777777; margin-bottom: 30px; }
.textarea-style textarea {
border-radius: 10px;
padding: 20px;
font-size: 16px;
}
.output-container {
background-color: #f4f8ff;
border-radius: 10px;
padding: 25px;
margin-top: 20px;
box-shadow: 0 4px 8px rgba(0,0,0,0.05);
}
</style>
""", unsafe_allow_html=True)
st.markdown('<div class="main-title">🧠 Smart JD Analyzer</div>', unsafe_allow_html=True)
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)
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")
analyze = st.button("🔍 Analyze JD", use_container_width=True)
# --- RESPONSE ---
if analyze:
if jd_input.strip():
with st.spinner("Analyzing job description..."):
st.session_state.message_history.append(HumanMessage(content=jd_input))
try:
response = llama_model.invoke(st.session_state.message_history)
# st.session_state.message_history.append(AIMessage(content=response.content))
with st.container():
st.markdown('<div class="output-container">', unsafe_allow_html=True)
st.markdown("### 📝 **Analysis Output**")
st.markdown(response.content, unsafe_allow_html=True)
st.markdown("</div>", unsafe_allow_html=True)
except Exception as e:
st.error(f"❌ Error occurred: {e}")
else:
st.warning("⚠️ Please enter a valid job description before analyzing.")