segoedu commited on
Commit
9c8bb20
1 Parent(s): 795f3cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -22
app.py CHANGED
@@ -11,29 +11,32 @@ from langchain_pinecone import PineconeVectorStore
11
  st.set_page_config('Opositor')
12
  st.header("Pregunta al trebep")
13
 
14
- # CARGAMOS LLM
15
- os.environ["GROQ_API_KEY"] = "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"
16
- model = 'llama3-8b-8192'
17
- llm = ChatGroq(model = model)
18
 
19
- # CARGAMOS MODELO DE EMBEDDING
20
- model_name = 'intfloat/multilingual-e5-base'
21
- embedding = HuggingFaceEmbeddings(model_name=model_name)
22
-
23
- # CARGAMOS EL VECTORSTORE DE PINECONE
24
- os.environ["PINECONE_API_KEY"] ='4bf0b4cf-4ced-4f70-8977-d60bb8ae405a'
25
- index_name = "boe-intfloat-multilingual-e5-base"
26
- namespace = "trebep"
27
- vectorstore = PineconeVectorStore(index_name=index_name, namespace=namespace, embedding=embedding)
28
-
29
- # CREAMOS EL RETRIEVAL
30
- qa = RetrievalQA.from_chain_type(
31
- llm=llm,
32
- chain_type="stuff",
33
- retriever=vectorstore.as_retriever(),
34
- return_source_documents=True,
35
- #verbose=True
36
- )
 
 
 
 
 
 
 
37
 
38
  # Función para mostrar logs
39
  def mostrar_logs(logs,hints):
@@ -55,6 +58,9 @@ logs = []
55
  user_question = st.text_input("¡A jugar! Haz una pregunta al trebep:")
56
  if user_question:
57
 
 
 
 
58
  # Obtenemos la respuesta
59
  respuesta = qa.invoke(user_question)
60
  docs = respuesta['source_documents']
 
11
  st.set_page_config('Opositor')
12
  st.header("Pregunta al trebep")
13
 
 
 
 
 
14
 
15
+ @st.cache_resource
16
+ def incializar():
17
+ # CARGAMOS LLM
18
+ os.environ["GROQ_API_KEY"] = "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"
19
+ model = 'llama3-8b-8192'
20
+ llm = ChatGroq(model = model)
21
+
22
+ # CARGAMOS MODELO DE EMBEDDING
23
+ model_name = 'intfloat/multilingual-e5-base'
24
+ embedding = HuggingFaceEmbeddings(model_name=model_name)
25
+
26
+ # CARGAMOS EL VECTORSTORE DE PINECONE
27
+ os.environ["PINECONE_API_KEY"] ='4bf0b4cf-4ced-4f70-8977-d60bb8ae405a'
28
+ index_name = "boe-intfloat-multilingual-e5-base"
29
+ namespace = "trebep"
30
+ vectorstore = PineconeVectorStore(index_name=index_name, namespace=namespace, embedding=embedding)
31
+
32
+ # CREAMOS EL RETRIEVAL
33
+ qa = RetrievalQA.from_chain_type(
34
+ llm=llm,
35
+ chain_type="stuff",
36
+ retriever=vectorstore.as_retriever(),
37
+ return_source_documents=True,
38
+ #verbose=True
39
+ )
40
 
41
  # Función para mostrar logs
42
  def mostrar_logs(logs,hints):
 
58
  user_question = st.text_input("¡A jugar! Haz una pregunta al trebep:")
59
  if user_question:
60
 
61
+ # Inicializar entorno
62
+ incializar()
63
+
64
  # Obtenemos la respuesta
65
  respuesta = qa.invoke(user_question)
66
  docs = respuesta['source_documents']