Waflon commited on
Commit
e2eaff0
·
verified ·
1 Parent(s): 0407de3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -21
app.py CHANGED
@@ -16,27 +16,41 @@ os.environ["LANGCHAIN_TRACING_V2"] = "true"
16
  os.environ["LANGCHAIN_API_KEY"] = st.secrets['OPENAI']
17
 
18
 
19
- loader = PyPDFLoader("https://www.sii.cl/normativa_legislacion/circulares/2024/circu3.pdf")
20
- data = loader.load()
21
- text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=150)
22
- #Transformado a tipo de dato especifico para esto
23
- docs = text_splitter.split_documents(data) # 'data' holds the text you want to split, split the text into documents using the text splitter.
24
-
25
- #Modelo QA sentence similarity
26
- modelPath = 'sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2' #español
27
- model_kwargs = {'device':'cpu'} #or CPUmodel_kwargs = {'device':'cuda'} #or CPU
28
- encode_kwargs = {'normalize_embeddings': False}
29
-
30
- #Embeddings que transforman a vectores densos multidimensionales las preguntas del SII
31
- embeddings = HuggingFaceEmbeddings(
32
- model_name=modelPath, # Ruta a modelo Pre entrenado
33
- model_kwargs=model_kwargs, # Opciones de configuracion del modelo
34
- encode_kwargs=encode_kwargs # Opciones de Encoding
35
- )
36
-
37
- #DB y retriever
38
- db = FAISS.from_documents(docs, embeddings) # Create a retriever object from the 'db' with a search configuration where it retrieves up to 4 relevant splits/documents.
39
- retriever = db.as_retriever(search_kwargs={"k": 6})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  template = """Responde la pregunta basado unicamente en el siguiente contexto
42
 
 
16
  os.environ["LANGCHAIN_API_KEY"] = st.secrets['OPENAI']
17
 
18
 
19
+ def get_data():
20
+ return st.session_state["BD"].get(None)
21
+
22
+
23
+ def add_data(value: FAISS):
24
+ st.session_state["BD"]= value
25
+
26
+
27
+ try:
28
+ db = get_data()
29
+ except:
30
+ print("No hay datos previos")
31
+ loader = PyPDFLoader("https://www.sii.cl/normativa_legislacion/circulares/2024/circu3.pdf")
32
+ data = loader.load()
33
+ text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=150)
34
+ #Transformado a tipo de dato especifico para esto
35
+ docs = text_splitter.split_documents(data) # 'data' holds the text you want to split, split the text into documents using the text splitter.
36
+
37
+ #Modelo QA sentence similarity
38
+ modelPath = 'sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2' #español
39
+ model_kwargs = {'device':'cpu'} # o cuda
40
+ encode_kwargs = {'normalize_embeddings': False}
41
+
42
+ #Embeddings que transforman a vectores densos multidimensionales las preguntas del SII
43
+ embeddings = HuggingFaceEmbeddings(
44
+ model_name=modelPath, # Ruta a modelo Pre entrenado
45
+ model_kwargs=model_kwargs, # Opciones de configuracion del modelo
46
+ encode_kwargs=encode_kwargs # Opciones de Encoding
47
+ )
48
+
49
+ #DB y retriever
50
+ db = FAISS.from_documents(docs, embeddings) # Create a retriever object from the 'db' with a search configuration where it retrieves up to 4 relevant splits/documents.
51
+ add_data(db)
52
+
53
+ retriever = db.as_retriever(search_kwargs={"k": 3})
54
 
55
  template = """Responde la pregunta basado unicamente en el siguiente contexto
56