diff --git a/app.py b/app.py
index 2ecfd5e..6ba2143 100644
--- a/app.py
+++ b/app.py
@@ -59,14 +59,18 @@ if pdf_name:
docs_split, pdf_name, embedding_model
)
- # Cargamos el modelo LLM desde LangChain
- llm = langChainTools.load_llm_open_source()
+ # Cargamos el modelo LLM desde LangChain
+ llm = langChainTools.load_llm_open_source()
- # Creamos la cadena que integra Vectorstroe, el LLM para hacer consultas.
- # Para este caso la cadena tene el parametro de memoria.
- qa = langChainTools.define_retrieval_qa_memory(
- llm, docstorage, pdf_name, embedding_model
- )
+ # Creamos la cadena que integra Vectorstroe, el LLM para hacer consultas.
+ # Para este caso la cadena tene el parametro de memoria.
+
+ if "qa" not in st.session_state.keys():
+ st.session_state.qa = langChainTools.define_retrieval_qa_memory(
+ llm, pdf_name, embedding_model
+ )
+
+ # qa = langChainTools.define_retrieval_qa_memory(llm, pdf_name, embedding_model)
# Store conversation history
if "messages" not in st.session_state.keys():
@@ -110,13 +114,15 @@ if pdf_name:
with st.spinner("Thinking..."):
# Creamos la cadena que integra Vectorstroe, el LLM para hacer consultas.
# Para este caso la cadena tene el parametro de memoria.
- qa = langChainTools.define_retrieval_qa_memory(
- llm, docstorage, pdf_name, embedding_model
- )
+ # qa = langChainTools.define_retrieval_qa_memory(
+ # llm, docstorage, pdf_name, embedding_model
+ # )
input = "\n".join([msg["content"] for msg in st.session_state.messages])
- query = qa.invoke({"question": f"{prompt}"}, return_only_outputs=True)
+ query = st.session_state.qa.invoke(
+ {"question": f"{prompt}"}, return_only_outputs=True
+ )
response_text = query["answer"]
documents_source = query["source_documents"]
diff --git a/app_2.py b/app_2.py
index efd42cf..c62da1d 100644
--- a/app_2.py
+++ b/app_2.py
@@ -7,7 +7,7 @@ from streamlit_extras.add_vertical_space import add_vertical_space
from langchain_tools.pdf_tools import PdfLangChain
from langchain_tools.lc_tools import LangChainTools
from chats.chat_tools import MessageManager
-from langchain_community.llms import HuggingFaceEndpoint
+from langchain_community.llms import Ollama
# App title
@@ -52,13 +52,22 @@ if pdf_name:
# Cargamos el modelo de embeddings
embedding_model = langChainTools.load_embedding_opnai()
+ # Cargamos el modelo de embeddings
+ # embedding_model = langChainTools.load_embedding_hf()
+
# Creamos el vector store
docstorage = langChainTools.create_vector_strore(
docs_split, pdf_name, embedding_model
)
# Cargamos el modelo LLM desde LangChain
- llm = langChainTools.load_llm_open_source()
+ # llm = langChainTools.load_llm_open_source()
+
+ # Cargamos el modelo LLM desde LangChain
+ llm = langChainTools.load_llm_openai()
+
+ # Cargamos el modelo desde Ollama
+ # llm = Ollama(model="gemma")
# Creamos la cadena que integra Vectorstroe, el LLM para hacer consultas.
# Para este caso la cadena tene el parametro de memoria.
@@ -116,7 +125,7 @@ if pdf_name:
query = qa.invoke({"question": f"{prompt}"}, return_only_outputs=True)
- response_text_en = query["answer"]
+ response_text = query["answer"]
documents_source = query["source_documents"]
messageManager = MessageManager()
@@ -125,10 +134,10 @@ if pdf_name:
# st.markdown(citation)
with st.chat_message("assistant"):
- st.write(response_text_en)
- # st.write(translation)
+ st.write(response_text)
+
st.session_state.messages.append(
- {"role": "assistant", "content": response_text_en}
+ {"role": "assistant", "content": response_text}
)
expander = st.expander("Fuentes")
expander.markdown(citation)
diff --git a/chats/__pycache__/__init__.cpython-311.pyc b/chats/__pycache__/__init__.cpython-311.pyc
index fda2381..82999c6 100644
Binary files a/chats/__pycache__/__init__.cpython-311.pyc and b/chats/__pycache__/__init__.cpython-311.pyc differ
diff --git a/chats/__pycache__/chat_tools.cpython-311.pyc b/chats/__pycache__/chat_tools.cpython-311.pyc
index 6fe77b5..19e5817 100644
Binary files a/chats/__pycache__/chat_tools.cpython-311.pyc and b/chats/__pycache__/chat_tools.cpython-311.pyc differ
diff --git a/chats/__pycache__/streamlit_tools.cpython-311.pyc b/chats/__pycache__/streamlit_tools.cpython-311.pyc
index 049f17c..3930f35 100644
Binary files a/chats/__pycache__/streamlit_tools.cpython-311.pyc and b/chats/__pycache__/streamlit_tools.cpython-311.pyc differ
diff --git a/chats/streamlit_tools.py b/chats/streamlit_tools.py
index 2df08c1..be6d840 100644
--- a/chats/streamlit_tools.py
+++ b/chats/streamlit_tools.py
@@ -1,33 +1,48 @@
import streamlit as st
import os
+
# @st.cache_data
-
-
def import_file() -> str:
+ List_of_files: list = []
# Cargar el archivo pdf
- archivo = st.file_uploader(
- 'Arrastra o ingresa tu archivo .pdf', type=['.pdf'])
- nombre_archivo: str = ''
+ archivo = st.file_uploader("Arrastra o ingresa tu archivo .pdf", type=[".pdf"])
+ nombre_archivo: str = ""
# Verificar si se ha cargado un archivo
if archivo is not None:
-
nombre_archivo = archivo.name
- # Abrir un archivo en modo escritura binaria ('wb') para guardar el archivo de audio
- with open(f'documents/pdfs/{nombre_archivo}', 'wb') as new_file:
+ # Agregamos el nombre a la lista de archvios para luego podr verificarlos
+ List_of_files.append(nombre_archivo)
+ st.success(
+ f"El numero de archivos en la lista de archivos es de: {len(List_of_files)}"
+ )
+
+ # Abrir un archivo en modo escritura binaria ('wb') para guardar el archivo de audio
+ with open(f"documents/pdfs/{nombre_archivo}", "wb") as new_file:
# Leer los datos del archivo cargado y escribirlos en el nuevo archivo
new_file.write(archivo.read())
+ st.success(f"Se carga el archivo con nombre: {nombre_archivo}")
+
+ # Verificamos que en la lista solo haya un archivo, de lo contrario, limpiamos la session_state
+ if (
+ "archivo_anterior" in st.session_state
+ and st.session_state.archivo_anterior != nombre_archivo
+ ):
+ st.session_state.clear()
+
+ st.session_state.archivo_anterior = nombre_archivo
+
return nombre_archivo
+
# Define la función para borrar el caché
def clear_cache():
- cache_path = os.path.join(st.__path__[0], 'static', 'cache')
+ cache_path = os.path.join(st.__path__[0], "static", "cache")
for root, dirs, files in os.walk(cache_path):
for file in files:
os.remove(os.path.join(root, file))
- st.success('Cache limpio exitosamente.')
-
+ st.success("Cache limpio exitosamente.")
diff --git a/documents/pdfs/SocialBigDataSociologiaYCienciasSocialesComputacio.pdf b/documents/pdfs/SocialBigDataSociologiaYCienciasSocialesComputacio.pdf
new file mode 100644
index 0000000..babc98c
Binary files /dev/null and b/documents/pdfs/SocialBigDataSociologiaYCienciasSocialesComputacio.pdf differ
diff --git a/documents/pdfs/se está muriendo la democracia.pdf b/documents/pdfs/se está muriendo la democracia.pdf
new file mode 100644
index 0000000..6053e3e
--- /dev/null
+++ b/documents/pdfs/se está muriendo la democracia.pdf
@@ -0,0 +1,8531 @@
+%PDF-1.7
%
+1 0 obj
<>>>
endobj
2 0 obj
<>stream
+
+
+
+
+ uuid:65972b06-9a32-7b47-96bd-30d13de9fe42
+ adobe:docid:indd:7c45f236-c39b-11de-aeff-914aa68a996b
+ xmp.id:057306da-0aed-4e99-80db-2e38a755ae24
+ proof:pdf
+
+ xmp.iid:1f53c4c0-7644-4b3c-aa09-bce7b7ba62dc
+ adobe:docid:indd:7c45f236-c39b-11de-aeff-914aa68a996b
+ adobe:docid:indd:7c45f236-c39b-11de-aeff-914aa68a996b
+ default
+
+
+
+
+ converted
+ from application/x-indesign to application/pdf
+ Adobe InDesign CC 2017 (Macintosh)
+ /
+ 2019-07-22T12:52:48-03:00
+
+
+
+ 2019-07-22T12:52:48-03:00
+ 2019-07-22T12:52:48-03:00
+ 2019-07-22T12:52:48-03:00
+ Adobe InDesign CC 2017 (Macintosh)
+ application/pdf
+ Adobe PDF Library 15.0
+ False
+
+
+
+ Palatino
+ 11.0
+ 0
+ 0
+ Apple Computer
+ TrueType Collection
+ 1249692586
+ Palatino-Roman
+ 1249692586
+
+
+ Palatino
+ 11.0
+ 0
+ 0
+ Apple Computer
+ TrueType Collection
+ 2953539469
+ Palatino-Bold
+ 2953539469
+
+
+ Palatino
+ 11.0
+ 0
+ 0
+ Apple Computer
+ TrueType Collection
+ 2246150940
+ Palatino-Italic
+ 2246150940
+
+
+ Zapf Dingbats
+ 6.1
+ 0
+ 0
+ Galapagos Design Group
+ TrueType
+ 3734765074
+ ZapfDingbatsITC
+ 3734765074
+
+
+ Helvetica
+ 12.0
+ 0
+ 55796
+ Apple Computer
+ TrueType
+ 1087816235
+ Helvetica-Bold
+ 1087816235
+
+
+ Helvetica Neue
+ 12.0
+ 0
+ 54195
+ Linotype AG
+ TrueType
+ 4122342109
+ HelveticaNeue-Light
+ 4122342109
+
+
+ Helvetica Neue
+ 12.0
+ 0
+ 63794
+ Linotype AG
+ TrueType
+ 1162007284
+ HelveticaNeue-CondensedBold
+ 1162007284
+
+
+ Helvetica Neue
+ 12.0
+ 0
+ 54839
+ Linotype AG
+ TrueType
+ 1815683752
+ HelveticaNeue
+ 1815683752
+
+
+
+
+
+
+
endstream
endobj
5 0 obj
<>
endobj
3 0 obj
<>
endobj
7 0 obj
<>
endobj
8 0 obj
<>
endobj
14 0 obj
<>/ExtGState<>/Font<>/ProcSet[/PDF/Text/ImageC]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
15 0 obj
<>/Font<>/ProcSet[/PDF/Text]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
16 0 obj
<>/Font<>/ProcSet[/PDF/Text]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
17 0 obj
<>/Font<>/ProcSet[/PDF/Text]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
18 0 obj
<>/Font<>/ProcSet[/PDF/Text]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
19 0 obj
<>/Font<>/ProcSet[/PDF/Text]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
20 0 obj
<>/Font<>/ProcSet[/PDF/Text]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
21 0 obj
<>/Font<>/ProcSet[/PDF/Text]/XObject<>>>/TrimBox[0.0 0.0 453.543 651.969]/Type/Page>>
endobj
44 0 obj
<>stream
+HW]oݸ}U݈%JE!`IZYp'H6{_$mu%r8l1p״?zwr6jt{xEqrtLpx|닦
lW0iNmLjFíc[w
ȃ״]73<-mή7:qFgϛog1/fp%7d;w G4=Փ#pqf^4<Z**s'wzAy֏;KIw<ػ] {7B_;!U@uk##x