|
import sys
|
|
import os
|
|
import json
|
|
import gradio as gr
|
|
sys.path.append('src')
|
|
from procesador_de_cvs_con_llm import ProcesadorCV
|
|
|
|
use_dotenv = False
|
|
if use_dotenv:
|
|
from dotenv import load_dotenv
|
|
load_dotenv("../../../../../../apis/.env")
|
|
api_key = os.getenv("OPENAI_API_KEY")
|
|
|
|
else:
|
|
api_key = os.getenv("OPENAI_API_KEY")
|
|
|
|
unmasked_chars = 8
|
|
masked_key = api_key[:unmasked_chars] + '*' * (len(api_key) - unmasked_chars*2) + api_key[-unmasked_chars:]
|
|
print(f"API key: {masked_key}")
|
|
|
|
def process_cv(job_text, cv_text, req_experience, positions_cap, dist_threshold_low, dist_threshold_high):
|
|
if dist_threshold_low >= dist_threshold_high:
|
|
return {"error": "dist_threshold_low debe ser más bajo que dist_threshold_high."}
|
|
|
|
if not isinstance(cv_text, str) or not cv_text.strip():
|
|
return {"error": "Por favor, introduce el CV o sube un fichero."}
|
|
|
|
try:
|
|
procesador = ProcesadorCV(api_key, cv_text, job_text, ner_pre_prompt,
|
|
system_prompt, user_prompt, ner_schema, response_schema)
|
|
dict_respuesta = procesador.procesar_cv_completo(
|
|
req_experience=req_experience,
|
|
positions_cap=positions_cap,
|
|
dist_threshold_low=dist_threshold_low,
|
|
dist_threshold_high=dist_threshold_high
|
|
)
|
|
return dict_respuesta
|
|
except Exception as e:
|
|
return {"error": f"Error en el procesamiento: {str(e)}"}
|
|
|
|
|
|
job_text = "Generative AI engineer"
|
|
cv_sample_path = 'cv_examples/reddgr_cv.txt'
|
|
with open(cv_sample_path, 'r', encoding='utf-8') as file:
|
|
cv_text = file.read()
|
|
|
|
with open('prompts/ner_pre_prompt.txt', 'r', encoding='utf-8') as f:
|
|
ner_pre_prompt = f.read()
|
|
with open('prompts/system_prompt.txt', 'r', encoding='utf-8') as f:
|
|
system_prompt = f.read()
|
|
with open('prompts/user_prompt.txt', 'r', encoding='utf-8') as f:
|
|
user_prompt = f.read()
|
|
|
|
with open('json/ner_schema.json', 'r', encoding='utf-8') as f:
|
|
ner_schema = json.load(f)
|
|
with open('json/response_schema.json', 'r', encoding='utf-8') as f:
|
|
response_schema = json.load(f)
|
|
|
|
|
|
with open('cv_examples/reddgr_cv.txt', 'r', encoding='utf-8') as file:
|
|
cv_example = file.read()
|
|
|
|
default_parameters = [48, 10, 0.5, 0.7]
|
|
|
|
|
|
css = """
|
|
table tbody tr {
|
|
height: 2.5em; /* Set a fixed height for the rows */
|
|
overflow: hidden; /* Hide overflow content */
|
|
}
|
|
|
|
table tbody tr td {
|
|
overflow: hidden; /* Ensure content within cells doesn't overflow */
|
|
text-overflow: ellipsis; /* Add ellipsis for overflowing text */
|
|
white-space: nowrap; /* Prevent text from wrapping */
|
|
vertical-align: middle; /* Align text vertically within the fixed height */
|
|
}
|
|
"""
|
|
|
|
|
|
with gr.Blocks(css=css) as interface:
|
|
|
|
job_text_input = gr.Textbox(label="Título oferta de trabajo", lines=1, placeholder="Introduce el título de la oferta de trabajo")
|
|
cv_text_input = gr.Textbox(label="CV en formato texto", lines=5, max_lines=5, placeholder="Introduce el texto del CV")
|
|
|
|
|
|
with gr.Accordion("Opciones avanzadas", open=False):
|
|
req_experience_input = gr.Number(label="Experiencia requerida (en meses)", value=default_parameters[0], precision=0)
|
|
positions_cap_input = gr.Number(label="Número máximo de puestos a extraer", value=default_parameters[1], precision=0)
|
|
dist_threshold_low_slider = gr.Slider(
|
|
label="Umbral mínimo de distancia de embeddings (puesto equivalente)",
|
|
minimum=0, maximum=1, value=default_parameters[2], step=0.05
|
|
)
|
|
dist_threshold_high_slider = gr.Slider(
|
|
label="Umbral máximo de distancia de embeddings (puesto irrelevante)",
|
|
minimum=0, maximum=1, value=default_parameters[3], step=0.05
|
|
)
|
|
|
|
submit_button = gr.Button("Procesar")
|
|
clear_button = gr.Button("Limpiar")
|
|
|
|
output_json = gr.JSON(label="Resultado")
|
|
|
|
|
|
examples = gr.Examples(
|
|
examples=[
|
|
["Cajero de supermercado", "Trabajo de charcutero desde 2021. Antes trabajé 2 meses de camarero en un bar de tapas."] + default_parameters,
|
|
["Generative AI Engineer", cv_example] + default_parameters
|
|
],
|
|
inputs=[job_text_input, cv_text_input, req_experience_input, positions_cap_input, dist_threshold_low_slider, dist_threshold_high_slider]
|
|
)
|
|
|
|
|
|
submit_button.click(
|
|
fn=process_cv,
|
|
inputs=[
|
|
job_text_input,
|
|
cv_text_input,
|
|
req_experience_input,
|
|
positions_cap_input,
|
|
dist_threshold_low_slider,
|
|
dist_threshold_high_slider
|
|
],
|
|
outputs=output_json
|
|
)
|
|
|
|
|
|
clear_button.click(
|
|
fn=lambda: ("","",*default_parameters),
|
|
inputs=[],
|
|
outputs=[
|
|
job_text_input,
|
|
cv_text_input,
|
|
req_experience_input,
|
|
positions_cap_input,
|
|
dist_threshold_low_slider,
|
|
dist_threshold_high_slider
|
|
]
|
|
)
|
|
|
|
|
|
gr.Markdown("""
|
|
<footer>
|
|
<p>Puedes consultar el código completo de esta app y los notebooks explicativos en
|
|
<a href='https://github.com/reddgr/procesador-de-curriculos-cv' target='_blank'>GitHub</a></p>
|
|
<p>© 2024 <a href='https://talkingtochatbots.com' target='_blank'>talkingtochatbots.com</a></p>
|
|
</footer>
|
|
""")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
interface.launch() |