import os import random import string from datetime import datetime from supabase import create_client, Client from transformers import pipeline, AutoModelForSequenceClassification,AutoModelForCausalLM, AutoTokenizer from sentence_transformers import SentenceTransformer from huggingface_hub import login import gradio as gr import os from sentence_transformers import SentenceTransformer, util from transformers import pipeline from huggingface_hub import login import gradio as gr # Load environment variables (for Hugging Face integration) from dotenv import load_dotenv load_dotenv() # Hugging Face Authentication (for private models) huggingface_token = os.getenv("HUGGINGFACE_TOKEN") login(token=huggingface_token) # Authenticate with Hugging Face # Supabase setup SUPABASE_URL = os.getenv("SUPABASE_URL") SUPABASE_KEY = os.getenv("SUPABASE_KEY") supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY) # Load Sentence Transformer model model = SentenceTransformer('all-MiniLM-L6-v2') # Function to calculate skill matching score def calculate_skill_score(jd, cv): skills = [ # Core Programming Languages 'Python', 'Java', 'JavaScript', 'C++', 'C#', 'Ruby', 'Go', 'Rust', 'Swift', 'Kotlin', 'PHP', 'TypeScript', # Web Technologies 'React', 'Angular', 'Vue.js', 'Node.js', 'Django', 'Flask', 'Spring', '.NET', 'Express.js', 'Laravel', # Cloud & DevOps 'AWS', 'Azure', 'Google Cloud', 'Docker', 'Kubernetes', 'Jenkins', 'GitHub Actions', 'GitLab CI', 'Terraform', # Databases 'SQL', 'MongoDB', 'PostgreSQL', 'MySQL', 'Cassandra', 'Redis', 'Oracle', 'SQLite', 'MariaDB', # Data Science & AI 'Machine Learning', 'Data Analysis', 'Deep Learning', 'TensorFlow', 'PyTorch', 'Scikit-learn', 'Pandas', 'NumPy', 'Keras', 'Natural Language Processing', # Big Data 'Hadoop', 'Spark', 'Apache Kafka', 'Elasticsearch', # Cybersecurity 'Network Security', 'Penetration Testing', 'Ethical Hacking', # Mobile Development 'Android', 'iOS', 'React Native', 'Flutter', 'Xamarin'] jd_skills = [skill for skill in skills if skill.lower() in jd.lower()] cv_skills = [skill for skill in skills if skill.lower() in cv.lower()] common_skills = set(jd_skills) & set(cv_skills) return len(common_skills) / len(jd_skills) * 4 if jd_skills else 0 # Function to calculate role match score def calculate_role_score(jd, cv): roles = ['Software Engineer', 'Data Scientist', 'DevOps', 'Frontend Developer', 'Project Manager', 'Delivery Manager', 'Delivery Head', 'BI'] matched_roles = [role for role in roles if role.lower() in jd.lower() and role.lower() in cv.lower()] return len(matched_roles) / len(roles) * 3 if roles else 0 # Function to calculate textual similarity (JD and CV) def calculate_text_similarity(jd, cv): jd_embedding = model.encode(jd, convert_to_tensor=True) cv_embedding = model.encode(cv, convert_to_tensor=True) cosine_sim = util.pytorch_cos_sim(jd_embedding, cv_embedding) return cosine_sim.item() # Function to calculate the overall rating def calculate_profile_rating(jd, cv): skill_score = calculate_skill_score(jd, cv) role_score = calculate_role_score(jd, cv) text_similarity = calculate_text_similarity(jd, cv) text_similarity_score = text_similarity * 3 total_score = skill_score + role_score + text_similarity_score total_score = min(total_score, 10) # Ensure score doesn't exceed 10 return round(total_score, 1) # Gradio interface to interact with the model def process_jd_cv(jd, cv): # Truncate both JD and CV to the first 3500 characters jd = jd[:3500] cv = cv[:3500] # Calculate the final rating rating = calculate_profile_rating(jd, cv) return f"Profile Rating: {rating}/10" # Gradio interface to accept inputs from the user iface = gr.Interface(fn=process_jd_cv, inputs=["text", "text"], # JD and CV text inputs outputs="text", # Display the rating score live=True) # Launch the Gradio interface iface.launch(share=True)