Spaces:
Sleeping
Sleeping
File size: 3,027 Bytes
f762e1b cf47d83 f762e1b 69e3a41 f762e1b 85ec4d4 f762e1b ea3c34e 275dee5 70ed6f0 f762e1b a3bc7ec f762e1b d37a28d 763be08 f762e1b a3bc7ec f762e1b ea3c34e f762e1b c2b4dad f762e1b 105c4c8 d37a28d f762e1b d37a28d f762e1b d37a28d f762e1b ee5951e d37a28d f762e1b 763be08 f762e1b d37a28d f762e1b 2b5a681 d37a28d 2b5a681 f762e1b d37a28d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import pandas as pd
import streamlit as st
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
from langchain.llms import HuggingFacePipeline
from huggingface_hub import login
# Token de Hugging Face (Secreto)
huggingface_token = st.secrets["HUGGINGFACEHUB_API_TOKEN"]
login(huggingface_token)
# Cargar el modelo Llama 3.1 y el tokenizador
model_id = "meta-llama/Llama-3.1-1B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
# Crear pipeline de generaci贸n de texto
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer, max_length=1024)
llm_pipeline = HuggingFacePipeline(pipeline=pipe)
# Interfaz de Streamlit
st.title("Cosine Similarity Simulation with Llama 3.1")
# Subir archivo CSV
uploaded_file = st.file_uploader("Sube un archivo CSV con la columna 'job_title':", type=["csv"])
if uploaded_file is not None:
# Cargar el CSV en un DataFrame
df = pd.read_csv(uploaded_file)
if 'job_title' in df.columns:
query = 'aspiring human resources specialist'
job_titles = df['job_title'].tolist()
# Definir el prompt para simular la similitud de coseno
prompt = (
f"You are an AI model trained to calculate semantic similarity using cosine similarity scores. "
f"The query is: '{query}'. You will compare this query to a list of job titles and estimate the cosine similarity score "
f"based on the semantic meaning. For each job title, assign a similarity score between 0 and 1. "
f"Output the results in the following format:\n\n"
f"1. Job Title: [Job Title], Score: [Cosine Similarity Score]\n"
f"2. Job Title: [Job Title], Score: [Cosine Similarity Score]\n"
f"...\n\n"
f"Job Titles:\n"
)
# Agregar los t铆tulos de trabajo al prompt
for i, title in enumerate(job_titles, 1):
prompt += f"{i}. {title}\n"
# Mostrar el prompt en la interfaz
st.write("Prompt enviado al LLM:")
st.write(prompt)
# Generar respuesta del LLM
if st.button("Generar puntajes de similitud"):
with st.spinner("Calculando similitudes con Llama 3.1..."):
try:
response = llm_pipeline(prompt)[0]['generated_text']
st.write("Respuesta del modelo:")
st.write(response)
# Simular la asignaci贸n de puntajes en la columna 'Score' (basado en la respuesta del modelo)
df['Score'] = [0.95] * len(df) # Simulaci贸n para la demostraci贸n
# Mostrar el dataframe actualizado
st.write("DataFrame con los puntajes de similitud:")
st.write(df)
except Exception as e:
st.error(f"Error durante la generaci贸n: {e}")
else:
st.error("La columna 'job_title' no se encuentra en el archivo CSV.")
|