Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
3 |
import pickle
|
|
|
|
|
4 |
import torch
|
5 |
import faiss
|
6 |
import numpy as np
|
7 |
-
from transformers import AutoTokenizer, AutoModel, pipeline
|
8 |
|
9 |
# Token para modelos privados si se requiere
|
10 |
hf_token = os.getenv("HF_KEY")
|
@@ -40,8 +40,10 @@ llm = pipeline(
|
|
40 |
trust_remote_code=True
|
41 |
)
|
42 |
|
43 |
-
# Función principal que ejecuta todo el proceso
|
44 |
def responder(pregunta):
|
|
|
|
|
|
|
45 |
pregunta_embedding = generar_embedding(pregunta)
|
46 |
distances, indices = index.search(pregunta_embedding.reshape(1, -1), k=20)
|
47 |
result_chunks = [chunks[i] for i in indices[0]]
|
@@ -87,14 +89,14 @@ RESPUESTA:
|
|
87 |
|
88 |
return solo_respuesta
|
89 |
|
90 |
-
# Interfaz Gradio
|
91 |
demo = gr.Interface(
|
92 |
fn=responder,
|
93 |
-
inputs=gr.Textbox(label="Escribe tu pregunta
|
94 |
outputs=gr.Textbox(label="Respuesta generada"),
|
95 |
title="Asistente Legal Colombiano",
|
96 |
description="Consulta el Código de Tránsito, Código de Policía y Código Penal colombiano."
|
97 |
)
|
98 |
|
99 |
if __name__ == "__main__":
|
100 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import pickle
|
3 |
+
import os
|
4 |
+
from transformers import AutoTokenizer, AutoModel, pipeline
|
5 |
import torch
|
6 |
import faiss
|
7 |
import numpy as np
|
|
|
8 |
|
9 |
# Token para modelos privados si se requiere
|
10 |
hf_token = os.getenv("HF_KEY")
|
|
|
40 |
trust_remote_code=True
|
41 |
)
|
42 |
|
|
|
43 |
def responder(pregunta):
|
44 |
+
if not pregunta:
|
45 |
+
return "Por favor ingresa una pregunta."
|
46 |
+
|
47 |
pregunta_embedding = generar_embedding(pregunta)
|
48 |
distances, indices = index.search(pregunta_embedding.reshape(1, -1), k=20)
|
49 |
result_chunks = [chunks[i] for i in indices[0]]
|
|
|
89 |
|
90 |
return solo_respuesta
|
91 |
|
92 |
+
# Interfaz de usuario con Gradio
|
93 |
demo = gr.Interface(
|
94 |
fn=responder,
|
95 |
+
inputs=gr.Textbox(label="Escribe tu pregunta"),
|
96 |
outputs=gr.Textbox(label="Respuesta generada"),
|
97 |
title="Asistente Legal Colombiano",
|
98 |
description="Consulta el Código de Tránsito, Código de Policía y Código Penal colombiano."
|
99 |
)
|
100 |
|
101 |
if __name__ == "__main__":
|
102 |
+
demo.launch()
|