Spaces:
Runtime error
Runtime error
Commit
路
29cd488
1
Parent(s):
3b8e1b8
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
from setfit import SetFitModel
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
# Cargar el modelo
|
5 |
model = SetFitModel.from_pretrained("desarrolloasesoreslocales/SetFitPruebaRecorte")
|
6 |
|
@@ -8,10 +26,16 @@ model = SetFitModel.from_pretrained("desarrolloasesoreslocales/SetFitPruebaRecor
|
|
8 |
|
9 |
# Definir la funci贸n de predicci贸n
|
10 |
def predict(payload):
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
13 |
# return "\n".join([f"Label: {id2label[i]}, Score: {round(result.item()*100, 2)} %" for i, result in enumerate(results)])
|
14 |
-
|
|
|
15 |
|
16 |
# Crear una interfaz Gradio
|
17 |
iface = gr.Interface(
|
|
|
1 |
import gradio as gr
|
2 |
from setfit import SetFitModel
|
3 |
|
4 |
+
def cortar_en_bloques(texto, longitud_bloque):
|
5 |
+
palabras = texto.split()
|
6 |
+
bloques = []
|
7 |
+
bloque_actual = []
|
8 |
+
|
9 |
+
for palabra in palabras:
|
10 |
+
bloque_actual.append(palabra)
|
11 |
+
|
12 |
+
if len(bloque_actual) == longitud_bloque:
|
13 |
+
bloques.append(" ".join(bloque_actual))
|
14 |
+
bloque_actual = []
|
15 |
+
|
16 |
+
# Si queda un bloque parcial al final, agregarlo
|
17 |
+
if bloque_actual:
|
18 |
+
bloques.append(" ".join(bloque_actual))
|
19 |
+
|
20 |
+
return bloques
|
21 |
+
|
22 |
# Cargar el modelo
|
23 |
model = SetFitModel.from_pretrained("desarrolloasesoreslocales/SetFitPruebaRecorte")
|
24 |
|
|
|
26 |
|
27 |
# Definir la funci贸n de predicci贸n
|
28 |
def predict(payload):
|
29 |
+
recorte = ""
|
30 |
+
|
31 |
+
for chunk in cortar_en_bloques(payload, 100):
|
32 |
+
if model.predict([chunk]).item() == 1:
|
33 |
+
recorte_general += chunk
|
34 |
+
|
35 |
+
# results = model.predict_proba([payload])[0]
|
36 |
# return "\n".join([f"Label: {id2label[i]}, Score: {round(result.item()*100, 2)} %" for i, result in enumerate(results)])
|
37 |
+
|
38 |
+
return recorte
|
39 |
|
40 |
# Crear una interfaz Gradio
|
41 |
iface = gr.Interface(
|