Spaces:
Sleeping
Sleeping
Update app.py
Browse files1 unmodified line234567891011121314151612 unmodified lines2930313233343513 unmodified lines4950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969729 unmodified lines1271281291301311321331341351361371381391401411421431441451461471481491501511522 unmodified lines1551561571581591601611 unmodified lineimport requestsfrom bs4 import BeautifulSoupimport fitz # PyMuPDFimport spacyfrom sklearn.feature_extraction.text import TfidfVectorizerfrom sklearn.metrics.pairwise import cosine_similarityimport numpy as npimport re# Carregar modelo de linguagem para NLPnlp = spacy.load("pt_core_news_sm")# Configuração de coresTHEME = {"primary": "#1a1a2e", # Azul escuro12 unmodified linesresponse = requests.get(url, headers=headers)soup = BeautifulSoup(response.text, 'html.parser')# Tentativa de encontrar a descrição da vagadescription = soup.find('div', {'class': 'description__text'})if not description:description = soup.find('div', {'class': 'show-more-less-html__markup'})13 unmodified linesexcept Exception as e:return f"Erro ao extrair texto do PDF: {str(e)}"# Função para calcular similaridadedef calculate_match(job_text, resume_text):# Pré-processamentojob_doc = nlp(job_text.lower())resume_doc = nlp(resume_text.lower())# Extrair palavras-chavejob_keywords = [token.text for token in job_doc if not token.is_stop and not token.is_punct and token.is_alpha]resume_keywords = [token.text for token in resume_doc if not token.is_stop and not token.is_punct and token.is_alpha]# Vetorização e cálculo de similaridadevectorizer = TfidfVectorizer().fit_transform([' '.join(job_keywords), ' '.join(resume_keywords)])similarity = cosine_similarity(vectorizer[0:1], vectorizer[1:2])[0][0]return round(similarity * 100, 2)# Função para análise detalhadadef detailed_analysis(job_text, resume_text):job_doc = nlp(job_text.lower())resume_doc = nlp(resume_text.lower())# Extrair requisitos da vagarequirements = []for sent in job_doc.sents:if "requisito" in sent.text or "necessário" in sent.text or "desejável" in sent.text:requirements.append(sent.text)# Verificar correspondênciasmatches = []non_matches = []for req in requirements:req_doc = nlp(req)found = Falsefor token in req_doc:if token.text in resume_text.lower():matches.append(req)found = Truebreakif not found:non_matches.append(req)return matches, non_matches# Função principaldef analyze_match(job_url, resume_file):29 unmodified lines<div style='display: flex; justify-content: space-between; gap: 20px;'><div style='flex: 1; background-color: {THEME["background"]}; padding: 15px; border-radius: 8px;'><h3 style='color: {THEME["secondary"]};'>✔️ Correspondências Encontradas</h3><ul>{''.join([f"<li style='margin-bottom: 8px;'>{match}</li>" for match in matches[:5]])}</ul>{f"<p>+ {len(matches)-5} outras correspondências...</p>" if len(matches) > 5 else ""}</div><div style='flex: 1; background-color: {THEME["background"]}; padding: 15px; border-radius: 8px;'><h3 style='color: {THEME["secondary"]};'>✖️ Requisitos Não Atendidos</h3><ul>{''.join([f"<li style='margin-bottom: 8px;'>{non_match}</li>" for non_match in non_matches[:5]])}</ul>{f"<p>+ {len(non_matches)-5} outros requisitos não atendidos...</p>" if len(non_matches) > 5 else ""}</div></div><div style='margin-top: 20px; background-color: {THEME["background"]}; padding: 15px; border-radius: 8px;'><h3 style='color: {THEME["secondary"]};'>💡 Recomendações</h3>{f"<p style='color: #4CAF50;'>🎯 Você atende a maioria dos requisitos! Considere destacar {min(3, len(matches))} habilidades principais no topo do seu currículo.</p>" if match_percentage >= 70else f"<p style='color: #F44336;'>🔍 Foque em desenvolver: {', '.join([nm.split()[0] for nm in non_matches[:3]])}</p>"}</div></div>"""2 unmodified linesexcept Exception as e:return f"❌ Ocorreu um erro durante a análise: {str(e)}"# Interface Gradio com tema personalizadocss = f"""body {{background-color: {THEME["primary"]} !important;1 unmodified line2345678910111212 unmodified lines2526272829303113 unmodified lines45464748495051525354555657585960616263646566676869707172737429 unmodified lines1041051061071081091101111121131141151161171181191201211221231241251261272 unmodified lines1301311321331341351361 unmodified lineimport requestsfrom bs4 import BeautifulSoupimport fitz # PyMuPDFfrom sklearn.feature_extraction.text import TfidfVectorizerfrom sklearn.metrics.pairwise import cosine_similarityimport numpy as npimport re# Configuração de coresTHEME = {"primary": "#1a1a2e", # Azul escuro12 unmodified linesresponse = requests.get(url, headers=headers)soup = BeautifulSoup(response.text, 'html.parser')# Tentativa de encontrar a descrição da vagadescription = soup.find('div', {'class': 'description__text'})if not description:description = soup.find('div', {'class': 'show-more-less-html__markup'})13 unmodified linesexcept Exception as e:return f"Erro ao extrair texto do PDF: {str(e)}"# Função simplificada para calcular similaridade (sem spaCy)def calculate_match(job_text, resume_text):# Pré-processamento básicojob_text = job_text.lower()resume_text = resume_text.lower()# Vetorização e cálculo de similaridadevectorizer = TfidfVectorizer().fit_transform([job_text, resume_text])similarity = cosine_similarity(vectorizer[0:1], vectorizer[1:2])[0][0]return round(similarity * 100, 2)# Função para análise detalhada simplificadadef detailed_analysis(job_text, resume_text):# Extrair palavras-chave da vagajob_keywords = set(re.findall(r'\b\w{4,}\b', job_text.lower()))# Verificar correspondências no currículoresume_words = set(re.findall(r'\b\w{4,}\b', resume_text.lower()))matches = job_keywords & resume_wordsnon_matches = job_keywords - resume_wordsreturn list(matches)[:10], list(non_matches)[:10] # Limitando a 10 itens cada# Função principaldef analyze_match(job_url, resume_file):29 unmodified lines<div style='display: flex; justify-content: space-between; gap: 20px;'><div style='flex: 1; background-color: {THEME["background"]}; padding: 15px; border-radius: 8px;'><h3 style='color: {THEME["secondary"]};'>✔️ Palavras-chave Correspondentes</h3><ul>{''.join([f"<li style='margin-bottom: 8px;'>{match}</li>" for match in matches])}</ul></div><div style='flex: 1; background-color: {THEME["background"]}; padding: 15px; border-radius: 8px;'><h3 style='color: {THEME["secondary"]};'>✖️ Palavras-chave Faltantes</h3><ul>{''.join([f"<li style='margin-bottom: 8px;'>{non_match}</li>" for non_match in non_matches])}</ul></div></div><div style='margin-top: 20px; background-color: {THEME["background"]}; padding: 15px; border-radius: 8px;'><h3 style='color: {THEME["secondary"]};'>💡 Recomendações</h3>{f"<p style='color: #4CAF50;'>🎯 Seu currículo tem boa aderência à vaga! Considere destacar essas palavras-chave.</p>" if match_percentage >= 70else f"<p style='color: #F44336;'>🔍 Foque em incluir estas palavras-chave no seu currículo: {', '.join(non_matches[:3])}</p>"}</div></div>"""2 unmodified linesexcept Exception as e:return f"❌ Ocorreu um erro durante a análise: {str(e)}"# Interface Gradiocss = f"""body {{background-color: {THEME["primary"]} !important;
app.py+21-46