Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,69 @@
|
|
1 |
import pandas as pd
|
2 |
from langchain.chains import LLMChain
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from langchain_huggingface import HuggingFacePipeline
|
4 |
from transformers import LlamaForCausalLM, AutoTokenizer
|
5 |
from langchain.llms import HuggingFaceHub
|
@@ -49,3 +113,4 @@ if uploaded_file:
|
|
49 |
st.write(df)
|
50 |
else:
|
51 |
st.write("No se ha subido un archivo")
|
|
|
|
1 |
import pandas as pd
|
2 |
from langchain.chains import LLMChain
|
3 |
+
from langchain.prompts import PromptTemplate
|
4 |
+
from langchain.llms import HuggingFaceHub
|
5 |
+
from transformers import LlamaForCausalLM, AutoTokenizer
|
6 |
+
from huggingface_hub import login
|
7 |
+
import streamlit as st
|
8 |
+
import sys
|
9 |
+
|
10 |
+
# Inicializaci贸n de Hugging Face con el token de la API desde los secretos de Streamlit
|
11 |
+
huggingface_token = st.secrets["SECRET"]
|
12 |
+
login(huggingface_token)
|
13 |
+
|
14 |
+
# Cargar el archivo CSV
|
15 |
+
uploaded_file = st.file_uploader("Sube un archivo CSV con la columna 'job_title':", type=["csv"])
|
16 |
+
|
17 |
+
if uploaded_file:
|
18 |
+
df = pd.read_csv(uploaded_file)
|
19 |
+
st.dataframe(df)
|
20 |
+
|
21 |
+
# Ingreso del query
|
22 |
+
query = "aspiring human resources specialist"
|
23 |
+
|
24 |
+
# Crear un modelo LLaMA
|
25 |
+
model_name = "meta-llama/Llama-2-7b"
|
26 |
+
modelo = LlamaForCausalLM.from_pretrained(model_name)
|
27 |
+
|
28 |
+
try:
|
29 |
+
# Usar AutoTokenizer para manejar autom谩ticamente el tokenizador adecuado
|
30 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
|
31 |
+
print("Tokenizador cargado con 茅xito.")
|
32 |
+
except Exception as e:
|
33 |
+
print(f"Error al cargar el tokenizador: {e}")
|
34 |
+
sys.exit(1)
|
35 |
+
|
36 |
+
# Crear un prompt para la cadena LLM
|
37 |
+
prompt_template = PromptTemplate(
|
38 |
+
input_variables=["query", "texto"],
|
39 |
+
template=(
|
40 |
+
"Calcular el cosine similarity score entre '{query}' y '{texto}'. "
|
41 |
+
"Responde con el score como un valor num茅rico entre 0 y 1."
|
42 |
+
)
|
43 |
+
)
|
44 |
+
|
45 |
+
# Crear una cadena LLM con LangChain usando HuggingFaceHub y pasar el token
|
46 |
+
llm = HuggingFaceHub(repo_id=model_name, huggingfacehub_api_token=huggingface_token)
|
47 |
+
chain = LLMChain(llm=llm, prompt=prompt_template)
|
48 |
+
|
49 |
+
def calcular_similitud(texto):
|
50 |
+
resultado = chain.run({"query": query, "texto": texto})
|
51 |
+
return float(resultado)
|
52 |
+
|
53 |
+
# Calcular la similitud para cada job title
|
54 |
+
df['Score'] = df['job_title'].apply(calcular_similitud)
|
55 |
+
|
56 |
+
# Reportar los resultados
|
57 |
+
st.write(df)
|
58 |
+
else:
|
59 |
+
st.write("No se ha subido un archivo")
|
60 |
+
|
61 |
+
|
62 |
+
|
63 |
+
|
64 |
+
'''
|
65 |
+
import pandas as pd
|
66 |
+
from langchain.chains import LLMChain
|
67 |
from langchain_huggingface import HuggingFacePipeline
|
68 |
from transformers import LlamaForCausalLM, AutoTokenizer
|
69 |
from langchain.llms import HuggingFaceHub
|
|
|
113 |
st.write(df)
|
114 |
else:
|
115 |
st.write("No se ha subido un archivo")
|
116 |
+
'''
|