Spaces:
Sleeping
Sleeping
JaphetHernandez
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import pandas as pd
|
2 |
from langchain.chains import LLMChain, RAGChain
|
3 |
from langchain.prompts import PromptTemplate
|
@@ -70,7 +111,7 @@ if uploaded_file:
|
|
70 |
st.write(df)
|
71 |
else:
|
72 |
st.write("No se ha subido un archivo")
|
73 |
-
|
74 |
'''
|
75 |
import pandas as pd
|
76 |
from langchain.chains import LLMChain
|
|
|
1 |
+
from langchain.llms import HuggingFace
|
2 |
+
from langchain.chains import LLMChain
|
3 |
+
from langchain.prompts import PromptTemplate
|
4 |
+
from langchain.indexes import RagIndex
|
5 |
+
from langchain.retrievers import HuggingFaceRetriever
|
6 |
+
|
7 |
+
# Inicializar el modelo LLaMA 3.2 desde Hugging Face
|
8 |
+
llm = HuggingFace(model="meta-llama/Llama-3.2-1B")
|
9 |
+
|
10 |
+
# Crear un prompt para la similitud de coseno
|
11 |
+
prompt_template = (
|
12 |
+
"Dado el siguiente par de frases, calcula la similitud de coseno: "
|
13 |
+
"Frase 1: '{phrase_1}' y Frase 2: '{phrase_2}'. "
|
14 |
+
"Proporciona solo el puntaje de similitud de coseno como un número entre 0 y 1."
|
15 |
+
)
|
16 |
+
|
17 |
+
# Crear el template de prompt
|
18 |
+
prompt = PromptTemplate.from_template(prompt_template)
|
19 |
+
|
20 |
+
# Crear un RAG Index usando LangChain y Hugging Face Retriever
|
21 |
+
retriever = HuggingFaceRetriever.from_pretrained(
|
22 |
+
"facebook/rag-token-nq", index_name="exact"
|
23 |
+
)
|
24 |
+
index = RagIndex(retriever=retriever)
|
25 |
+
|
26 |
+
# Crear la cadena LLM con el modelo LLaMA y el prompt
|
27 |
+
llm_chain = LLMChain(llm=llm, prompt=prompt)
|
28 |
+
|
29 |
+
# Definir las frases para calcular la similitud de coseno
|
30 |
+
phrase_1 = "Deep learning involves neural networks for complex data patterns."
|
31 |
+
phrase_2 = "Neural networks are core components in deep learning."
|
32 |
+
|
33 |
+
# Ejecutar la cadena con las frases dadas
|
34 |
+
result = llm_chain.run(phrase_1=phrase_1, phrase_2=phrase_2)
|
35 |
+
|
36 |
+
# Imprimir el puntaje de similitud de coseno
|
37 |
+
print(f"Cosine Similarity Score: {result}")
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
'''
|
42 |
import pandas as pd
|
43 |
from langchain.chains import LLMChain, RAGChain
|
44 |
from langchain.prompts import PromptTemplate
|
|
|
111 |
st.write(df)
|
112 |
else:
|
113 |
st.write("No se ha subido un archivo")
|
114 |
+
'''
|
115 |
'''
|
116 |
import pandas as pd
|
117 |
from langchain.chains import LLMChain
|