Spaces:
Running
Running
| import streamlit as st | |
| import faiss | |
| import numpy as np | |
| from sentence_transformers import SentenceTransformer | |
| # Load resume data | |
| resume_data = { | |
| "name": "Pradeep Singh Sengar", | |
| "linkedin": "www.linkedin.com/in/ipradeepsengarr", | |
| "email": "pradeep19sengar@gmail.com", | |
| "github": "github.com/pradeepsengar", | |
| "mobile": "+91-7898367211", | |
| "education": "Bachelor of Engineering (Hons.) - Information Technology; CGPA: 8.31 (Oriental College Of Technology, Bhopal, 2019-2023)", | |
| "skills": "Python, HTML/CSS, Django, Reactjs, Node.js, Git, Web Scraping, Generative AI, Machine Learning (LLM)", | |
| "experience": "Graduate Engineer Trainee at Jio Platform Limited (Dec. 2023 - Present). Implemented chatbots with Docker, used Git/GitHub, worked with LLM concepts and Hugging Face.", | |
| "projects": "Room Rental System, Text to Image Generator, Fitness Tracker, Movie Recommendation System", | |
| "honors_awards": "Qualified for Round 1B of SnackDown (CodeChef), Startup Challenge (Top 10 teams)", | |
| "certifications": "Web Development (Internshala), The Complete Python Pro Bootcamp (Udemy), Data Science (LinkedIn Learning), Web Scraping (LinkedIn Learning)" | |
| } | |
| # Convert data to list of sentences for retrieval | |
| resume_keys = list(resume_data.keys()) | |
| resume_values = list(resume_data.values()) | |
| # Load embedding model | |
| model = SentenceTransformer('all-MiniLM-L6-v2') | |
| embeddings = model.encode(resume_values) | |
| # Store embeddings in FAISS index | |
| index = faiss.IndexFlatL2(embeddings.shape[1]) | |
| index.add(np.array(embeddings)) | |
| def get_response(query): | |
| query_embedding = model.encode([query]) | |
| D, I = index.search(query_embedding, 1) | |
| confidence = 1 - D[0][0] / 10 # Normalize confidence score | |
| # Keyword-based accuracy improvement | |
| query_lower = query.lower() | |
| for key, value in resume_data.items(): | |
| if key in query_lower or any(word in query_lower for word in key.split("_")): | |
| return f"**{key.capitalize()}**: {value}" | |
| if confidence > 0.5: | |
| key = resume_keys[I[0][0]] | |
| answer = resume_data[key] | |
| return f"**{key.capitalize()}**: {answer}" | |
| else: | |
| return "I'm not sure about this. Please try asking differently or be more specific." | |
| # Streamlit UI | |
| st.title("📝 Resume Chatbot") | |
| st.write("Ask anything about Pradeep's resume!") | |
| # Suggested Questions | |
| suggested_questions = [ | |
| "What is your name?", | |
| "What is your LinkedIn profile?", | |
| "What skills do you have?", | |
| "Tell me about your experience?", | |
| "What are your certifications?", | |
| "List your projects.", | |
| "What is your mobile number?" | |
| ] | |
| st.write("### Quick Questions") | |
| col1, col2 = st.columns(2) | |
| # Ensure session state exists | |
| if "user_input" not in st.session_state: | |
| st.session_state["user_input"] = "" | |
| def set_question(question): | |
| st.session_state["user_input"] = question | |
| st.rerun() | |
| for i, question in enumerate(suggested_questions): | |
| if i % 2 == 0: | |
| with col1: | |
| st.button(question, key=f"btn_{i}", on_click=set_question, args=(question,)) | |
| else: | |
| with col2: | |
| st.button(question, key=f"btn_{i}", on_click=set_question, args=(question,)) | |
| # User Input & Response | |
| user_input = st.text_input("Your question:", value=st.session_state["user_input"]) | |
| if user_input: | |
| response = get_response(user_input) | |
| st.success(response) | |