Spaces:
Sleeping
Sleeping
USar variables de ambientes para OPENAI_API_KEY
Browse files
app.py
CHANGED
@@ -24,8 +24,10 @@ import re
|
|
24 |
import time
|
25 |
|
26 |
|
|
|
27 |
|
28 |
-
|
|
|
29 |
def extraer_texto(contenidoXML):
|
30 |
# Espacio de nombres del XML
|
31 |
namespaces = {'emas': 'http://www.leychile.cl/esquemas'}
|
@@ -80,21 +82,6 @@ norma = st.sidebar.selectbox(
|
|
80 |
"Selecciona una norma",
|
81 |
('DS49 (V. y U.) de 2011', 'Ley 21.442 (Ley de copropiedad inmobiliaria)'))
|
82 |
|
83 |
-
tmp = st.text_input("API key de OpenAI :", placeholder="sk-",type="password")
|
84 |
-
while True:
|
85 |
-
if 'openai_api_key' not in st.session_state:
|
86 |
-
if len(tmp) > 0:
|
87 |
-
st.write("DOS")
|
88 |
-
st.session_state.openai_api_key = tmp
|
89 |
-
st.write(len(st.session_state.openai_api_key))
|
90 |
-
st.write(st.session_state.openai_api_key)
|
91 |
-
break
|
92 |
-
|
93 |
-
openai_api_key = st.session_state.openai_api_key #st.text_input("API key de OpenAI :",placeholder="sk-",key="openai_api_key")
|
94 |
-
|
95 |
-
st.write("UNO")
|
96 |
-
st.write(len(openai_api_key))
|
97 |
-
st.write(openai_api_key)
|
98 |
|
99 |
#st.write(type(option))
|
100 |
if norma=='DS49 (V. y U.) de 2011':
|
@@ -106,14 +93,13 @@ else:
|
|
106 |
|
107 |
question = st.text_input("haz una pregunta:",placeholder=placeholder)
|
108 |
|
109 |
-
#st.write("pregunta")
|
110 |
|
111 |
######### FIN WEB ###########
|
112 |
|
113 |
-
os.environ['OPENAI_API_KEY'] = openai_api_key
|
114 |
|
115 |
contenidoXML = obtener_contenido_url(url) #<--contiene el XML de la norma en texto
|
116 |
-
st.write(url)
|
117 |
|
118 |
|
119 |
######################
|
@@ -130,7 +116,7 @@ textos = extraer_texto(contenidoXML)
|
|
130 |
#TEXTO normalizado COMPLETO DE LA NORMA en ascii (sin metadata)
|
131 |
texto='\n'.join(textos)
|
132 |
#i=i+1
|
133 |
-
st.write("HOLA1")
|
134 |
|
135 |
|
136 |
|
@@ -138,8 +124,8 @@ from langchain.schema import Document
|
|
138 |
|
139 |
documento = [Document(page_content=texto, metadata={"nombre": "norma"})] #<---- del tipo <class 'langchain.schema.document.Document'>
|
140 |
|
141 |
-
st.write(texto[:50])
|
142 |
-
st.write("HOLA2")
|
143 |
|
144 |
|
145 |
|
@@ -148,8 +134,8 @@ from langchain.indexes import VectorstoreIndexCreator
|
|
148 |
|
149 |
index = VectorstoreIndexCreator().from_documents(documento)
|
150 |
|
151 |
-
st.write("HOLA3")
|
152 |
-
st.write(texto[:100])
|
153 |
###############
|
154 |
|
155 |
####MUESRRA Respuesta 1
|
|
|
24 |
import time
|
25 |
|
26 |
|
27 |
+
openai_api_key = os.getenv("OPENAI_API_KEY")
|
28 |
|
29 |
+
#st.write(openai_api_key)
|
30 |
+
#st.write("HOLASAS")
|
31 |
def extraer_texto(contenidoXML):
|
32 |
# Espacio de nombres del XML
|
33 |
namespaces = {'emas': 'http://www.leychile.cl/esquemas'}
|
|
|
82 |
"Selecciona una norma",
|
83 |
('DS49 (V. y U.) de 2011', 'Ley 21.442 (Ley de copropiedad inmobiliaria)'))
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
#st.write(type(option))
|
87 |
if norma=='DS49 (V. y U.) de 2011':
|
|
|
93 |
|
94 |
question = st.text_input("haz una pregunta:",placeholder=placeholder)
|
95 |
|
|
|
96 |
|
97 |
######### FIN WEB ###########
|
98 |
|
99 |
+
#os.environ['OPENAI_API_KEY'] = openai_api_key
|
100 |
|
101 |
contenidoXML = obtener_contenido_url(url) #<--contiene el XML de la norma en texto
|
102 |
+
#st.write(url)
|
103 |
|
104 |
|
105 |
######################
|
|
|
116 |
#TEXTO normalizado COMPLETO DE LA NORMA en ascii (sin metadata)
|
117 |
texto='\n'.join(textos)
|
118 |
#i=i+1
|
119 |
+
#st.write("HOLA1")
|
120 |
|
121 |
|
122 |
|
|
|
124 |
|
125 |
documento = [Document(page_content=texto, metadata={"nombre": "norma"})] #<---- del tipo <class 'langchain.schema.document.Document'>
|
126 |
|
127 |
+
#st.write(texto[:50])
|
128 |
+
#st.write("HOLA2")
|
129 |
|
130 |
|
131 |
|
|
|
134 |
|
135 |
index = VectorstoreIndexCreator().from_documents(documento)
|
136 |
|
137 |
+
#st.write("HOLA3")
|
138 |
+
#st.write(texto[:100])
|
139 |
###############
|
140 |
|
141 |
####MUESRRA Respuesta 1
|