Prueba_1 / app.py
JaphetHernandez's picture
Update app.py
a3bc7ec verified
raw
history blame
2.09 kB
from transformers import AutoModelForCausalLM, AutoTokenizer
import streamlit as st
from huggingface_hub import login
import pandas as pd
# Token Secret of Hugging Face
huggingface_token = st.secrets["HUGGINGFACEHUB_API_TOKEN"]
login(huggingface_token)
# Cargar el modelo y el tokenizer
model_name = "meta-llama/Llama-3.2-1B-Instruct"
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Asignar el eos_token como pad_token
tokenizer.pad_token = tokenizer.eos_token
# Upload CSV file
uploaded_file = st.file_uploader("Upload a CSV file", type=["csv"])
# Leer el archivo CSV si se ha subido
if uploaded_file is not None:
df = pd.read_csv(uploaded_file)
st.write(df.head()) # Mostrar las primeras filas del dataframe
# Verificar si la columna 'job_title' est谩 en el dataframe
if 'job_title' in df.columns:
job_titles = df['job_title'].tolist()
else:
st.error("La columna 'job_title' no se encuentra en el archivo CSV.")
job_titles = [] # Asignar una lista vac铆a si la columna no existe
else:
st.warning("Por favor, sube un archivo CSV.")
job_titles = [] # Asignar una lista vac铆a si no se ha subido un archivo
# Definir la consulta
query = "aspiring human resources specialist"
st.write("Query:", query)
# Texto de entrada para la generaci贸n
input_text = (
f"You are an AI assistant. You have a list of job titles and a search query.\n"
f"Your task is to rank these job titles by their semantic similarity to the given query. "
f"Please provide the ranking from most relevant to least relevant. "
f"Do not calculate cosine similarity; instead, focus on understanding the semantic relevance of each job title to the query.\n"
f"\n"
f"Format your response like this:\n"
f"1. [Most Relevant Job Title]\n"
f"2. [Second Most Relevant Job Title]\n"
f"...\n"
f"N. [Least Relevant Job Title]\n"
f"\n"
f"Query: \"{query}\"\n"
f"Job Titles: {job_titles}\n"
)
st.write("Texto de entrada para la generaci贸n:", input_text)