|
import gradio as gr |
|
import pandas as pd |
|
import matplotlib.pyplot as plt |
|
from transformers import pipeline |
|
from sentence_transformers import SentenceTransformer, util |
|
from langdetect import detect |
|
|
|
|
|
data = { |
|
'Company': ['Google', 'Amazon', 'Microsoft', 'Facebook', 'Tesla'], |
|
'Job_Description': [ |
|
"We are looking for a Senior Software Engineer with extensive experience in Python, Java, and cloud computing. The candidate should have experience working in an Agile environment and a deep understanding of machine learning.", |
|
"The Data Analyst will analyze large datasets to uncover trends, patterns, and insights. Proficiency in SQL, Python, and data visualization tools like PowerBI or Tableau is required.", |
|
"Hiring a Cloud Architect with experience in Azure, AWS, and cloud infrastructure design. The ideal candidate should have experience with Docker, Kubernetes, and network security.", |
|
"AI Research Scientist with expertise in machine learning, deep learning, and natural language processing (NLP). Experience with TensorFlow, PyTorch, and data-driven research.", |
|
"Looking for an Electrical Engineer with experience in circuit design, power electronics, and embedded systems. Proficiency in CAD tools and simulation software is a must." |
|
] |
|
} |
|
|
|
|
|
df = pd.DataFrame(data) |
|
|
|
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2') |
|
translator = pipeline(task="translation", model="facebook/nllb-200-distilled-600M") |
|
lang_code_mapping = { |
|
'ar': 'arb_Arab', |
|
'fr': 'fra_Latn', |
|
'es': 'spa_Latn', |
|
'de': 'deu_Latn', |
|
} |
|
|
|
|
|
def translate_to_english(cv_text): |
|
detected_lang = lang_code_mapping.get(detect(cv_text), "eng_Latn") |
|
|
|
|
|
if detected_lang != 'eng_Latn': |
|
translation = translator(cv_text, src_lang=detected_lang, tgt_lang="eng_Latn")[0]['translation_text'] |
|
return translation, detected_lang |
|
else: |
|
return cv_text, detected_lang |
|
|
|
|
|
def translate_job_description_if_needed(job_description, target_lang): |
|
if target_lang != 'eng_Latn': |
|
return translator(job_description, src_lang="eng_Latn", tgt_lang=target_lang)[0]['translation_text'] |
|
return job_description |
|
|
|
|
|
def find_top_matches(cv_text): |
|
if not cv_text: |
|
return "Error: CV is empty", None |
|
|
|
|
|
cv_text, detected_lang = translate_to_english(cv_text) |
|
|
|
|
|
descriptions = df['Job_Description'].tolist() |
|
|
|
|
|
descriptions_embeddings = model.encode(descriptions, convert_to_tensor=True) |
|
cv_embedding = model.encode([cv_text], convert_to_tensor=True) |
|
similarities = util.pytorch_cos_sim(cv_embedding, descriptions_embeddings)[0] |
|
|
|
|
|
top_3_indices = similarities.argsort(descending=True)[:3] |
|
top_3_matches = df.iloc[top_3_indices] |
|
top_3_similarities = similarities[top_3_indices].numpy() |
|
|
|
|
|
plt.bar(top_3_matches['Company'], top_3_similarities, color='skyblue') |
|
plt.ylabel('Similarity Score') |
|
plt.xlabel('Company') |
|
plt.title('Top 3 Job Description Matches') |
|
|
|
|
|
job_summaries = "" |
|
for _, row in top_3_matches.iterrows(): |
|
|
|
job_desc_translated = translate_job_description_if_needed(row['Job_Description'], detected_lang) |
|
|
|
if detected_lang == 'arb_Arab': |
|
|
|
job_summaries += f'<div dir="rtl"><strong>الشركة</strong>: {row["Company"]} <br>' |
|
job_summaries += f'<strong>وصف الوظيفه :</strong> {job_desc_translated}<br><br></div>' |
|
else: |
|
|
|
job_summaries += f"<strong>Company:</strong> {row['Company']}<br>" |
|
job_summaries += f"<strong>Job Description :</strong> {job_desc_translated}<br><br>" |
|
|
|
return job_summaries, plt |
|
|
|
|
|
demo = gr.Interface( |
|
fn=find_top_matches, |
|
inputs=gr.Textbox(lines=15, placeholder="Enter your CV text here...", label="CV Text"), |
|
outputs=[ |
|
gr.HTML(label="Job Summaries"), |
|
gr.Plot(label="Top 3 Matching Job Descriptions") |
|
], |
|
title="'Match CV to Job Description", |
|
description="Upload your CV to find the top 3 job descriptions that match from the available companies using semantic similarity." |
|
) |
|
|
|
|
|
demo.launch() |