Upload 2 files
Browse files- pages/insertardocumentos.py +34 -0
- pages/resumen_word.py +56 -0
pages/insertardocumentos.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from sentence_transformers import SentenceTransformer
|
| 3 |
+
from Rag_milvus import pdfachunk,split_chunks,generaremben,insertarenqdra
|
| 4 |
+
from Llm_local import generarPages
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
col1, col2 = st.columns([1, 4])
|
| 8 |
+
with col1:
|
| 9 |
+
st.image("Procuradurialogo.jpg", width=600)
|
| 10 |
+
|
| 11 |
+
with col2:
|
| 12 |
+
st.markdown("""
|
| 13 |
+
<div style='display: flex; align-items: center; height: 100%;'>
|
| 14 |
+
<h1 style='margin: 0; text-align: center;'>ProcurIA</h1>
|
| 15 |
+
</div>
|
| 16 |
+
""", unsafe_allow_html=True)
|
| 17 |
+
|
| 18 |
+
st.sidebar.title("Menú de Funciones")
|
| 19 |
+
generarPages()
|
| 20 |
+
|
| 21 |
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
| 22 |
+
|
| 23 |
+
archivo = st.file_uploader("📂 Sube tus documentos PDF para chatear con ellos", type=["pdf", "txt"], accept_multiple_files=True)
|
| 24 |
+
|
| 25 |
+
if archivo:
|
| 26 |
+
for file in archivo:
|
| 27 |
+
nombre_coleccion = f"coleccion_{file.name.replace('.pdf', '').replace(' ', '_')}"
|
| 28 |
+
pdf_chunks = pdfachunk(file)
|
| 29 |
+
split_docs = split_chunks(pdf_chunks)
|
| 30 |
+
texts = [doc.page_content for doc in split_docs]
|
| 31 |
+
embeddings = generaremben(model, texts)
|
| 32 |
+
insertarenqdra(embeddings, texts, nombre_coleccion)
|
| 33 |
+
|
| 34 |
+
st.success("Archivos subidos en la base vectorial con éxito!")
|
pages/resumen_word.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from sentence_transformers import SentenceTransformer
|
| 3 |
+
from Llm_local import generarPages, informes_mistral,extraer_texto, extraer_texto_word, generar_docx, generar_pdf
|
| 4 |
+
|
| 5 |
+
col1, col2 = st.columns([1, 4])
|
| 6 |
+
with col1:
|
| 7 |
+
st.image("Procuradurialogo.jpg", width=600)
|
| 8 |
+
|
| 9 |
+
with col2:
|
| 10 |
+
st.markdown("""
|
| 11 |
+
<div style='display: flex; align-items: center; height: 100%;'>
|
| 12 |
+
<h1 style='margin: 0; text-align: center;'>ProcurIA</h1>
|
| 13 |
+
</div>
|
| 14 |
+
""", unsafe_allow_html=True)
|
| 15 |
+
|
| 16 |
+
st.sidebar.title("Menú de Funciones")
|
| 17 |
+
generarPages()
|
| 18 |
+
|
| 19 |
+
if "messages" not in st.session_state:
|
| 20 |
+
st.session_state.messages = [{"role": "assistant", "content": "Hola!, en qué puedo ayudarte?"}]
|
| 21 |
+
|
| 22 |
+
model = SentenceTransformer("all-MiniLM-L6-v2")
|
| 23 |
+
|
| 24 |
+
archivo = st.file_uploader("📂 Sube tus documentos PDF o WORD ¡Para hacer un informe!", type=["pdf", "txt"], accept_multiple_files=True)
|
| 25 |
+
|
| 26 |
+
if archivo:
|
| 27 |
+
texto_total = ""
|
| 28 |
+
|
| 29 |
+
for archivo_item in archivo:
|
| 30 |
+
contenido = ""
|
| 31 |
+
|
| 32 |
+
if archivo_item.name.endswith(".pdf"):
|
| 33 |
+
contenido = extraer_texto(archivo_item)
|
| 34 |
+
elif archivo_item.name.endswith(".docx"):
|
| 35 |
+
contenido = extraer_texto_word(archivo_item)
|
| 36 |
+
|
| 37 |
+
if contenido.strip():
|
| 38 |
+
texto_total += f"\n---\nDOCUMENTO: {archivo_item.name}\n{contenido.strip()}\n"
|
| 39 |
+
|
| 40 |
+
if texto_total.strip():
|
| 41 |
+
resumen_completo = [""]
|
| 42 |
+
#st.write(texto_total)
|
| 43 |
+
def resumen_streaming():
|
| 44 |
+
for palabra in informes_mistral(texto_total):
|
| 45 |
+
resumen_completo[0] += palabra
|
| 46 |
+
yield palabra
|
| 47 |
+
|
| 48 |
+
st.subheader("📄 Informe de todos los documentos:")
|
| 49 |
+
st.write_stream(resumen_streaming())
|
| 50 |
+
|
| 51 |
+
pdf_bytes = generar_pdf(resumen_completo[0])
|
| 52 |
+
st.download_button("📄 Descargar Informe en PDF", data=pdf_bytes, file_name="resumen_global.pdf", mime="application/pdf")
|
| 53 |
+
|
| 54 |
+
docx_buffer = generar_docx(resumen_completo[0])
|
| 55 |
+
st.download_button("📝 Descargar Informe en Word", data=docx_buffer, file_name="resumen_global.docx",
|
| 56 |
+
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|