Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -5,18 +5,19 @@ from transformers import AutoTokenizer, AutoModel, pipeline
|
|
5 |
import torch
|
6 |
import faiss
|
7 |
import numpy as np
|
8 |
-
from spaces import GPU #
|
9 |
|
10 |
-
# Token para modelos privados
|
11 |
hf_token = os.getenv("HF_KEY")
|
12 |
|
13 |
# Cargar índice FAISS y los chunks
|
14 |
if os.path.exists("index.pkl"):
|
15 |
-
# justo después de cargar el index y los chunks
|
16 |
with open("index.pkl", "rb") as f:
|
17 |
-
|
|
|
|
|
18 |
|
19 |
-
# Filtro suave de limpieza (
|
20 |
def limpiar_chunks(chunks):
|
21 |
palabras_legales = ["artículo", "sanción", "pena", "multa", "prohibido", "infracción", "autoridad", "norma"]
|
22 |
nuevos_chunks = []
|
@@ -52,7 +53,7 @@ llm = pipeline(
|
|
52 |
trust_remote_code=True
|
53 |
)
|
54 |
|
55 |
-
@GPU #
|
56 |
def responder(pregunta):
|
57 |
if not pregunta:
|
58 |
return "Por favor ingresa una pregunta."
|
@@ -111,4 +112,4 @@ demo = gr.Interface(
|
|
111 |
)
|
112 |
|
113 |
if __name__ == "__main__":
|
114 |
-
demo.launch()
|
|
|
5 |
import torch
|
6 |
import faiss
|
7 |
import numpy as np
|
8 |
+
from spaces import GPU # Importante para ZeroGPU
|
9 |
|
10 |
+
# Token para modelos privados
|
11 |
hf_token = os.getenv("HF_KEY")
|
12 |
|
13 |
# Cargar índice FAISS y los chunks
|
14 |
if os.path.exists("index.pkl"):
|
|
|
15 |
with open("index.pkl", "rb") as f:
|
16 |
+
index, chunks = pickle.load(f)
|
17 |
+
else:
|
18 |
+
raise FileNotFoundError("No se encontró el archivo 'index.pkl'.")
|
19 |
|
20 |
+
# Filtro suave de limpieza (punto C)
|
21 |
def limpiar_chunks(chunks):
|
22 |
palabras_legales = ["artículo", "sanción", "pena", "multa", "prohibido", "infracción", "autoridad", "norma"]
|
23 |
nuevos_chunks = []
|
|
|
53 |
trust_remote_code=True
|
54 |
)
|
55 |
|
56 |
+
@GPU # Activar ZeroGPU
|
57 |
def responder(pregunta):
|
58 |
if not pregunta:
|
59 |
return "Por favor ingresa una pregunta."
|
|
|
112 |
)
|
113 |
|
114 |
if __name__ == "__main__":
|
115 |
+
demo.launch()
|