Spaces:
Sleeping
Sleeping
Create app.js
Browse files
app.js
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# INTERFAZ USANDO GRADIO
|
2 |
+
|
3 |
+
from transformers import pipeline
|
4 |
+
import gradio as gr
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
# Cargar el modelo entrenado
|
8 |
+
model_path = "AleMarroquin18/beto-finetuned-ner"
|
9 |
+
nlp_ner = pipeline("token-classification", model=model_path, tokenizer=model_path)
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
# Funci贸n para predecir y estructurar los resultados
|
16 |
+
def predict_entities(text):
|
17 |
+
results = nlp_ner(text)
|
18 |
+
if not results: # Si no hay entidades detectadas
|
19 |
+
return "No se detectaron entidades."
|
20 |
+
|
21 |
+
# Crear un DataFrame para estructurar los resultados
|
22 |
+
data = {
|
23 |
+
"Token": [result["word"] for result in results],
|
24 |
+
"Etiqueta": [result["entity"] for result in results],
|
25 |
+
"Confianza (%)": [f'{result["score"]*100:.2f}' for result in results],
|
26 |
+
"Inicio": [result["start"] for result in results],
|
27 |
+
"Fin": [result["end"] for result in results]
|
28 |
+
}
|
29 |
+
df = pd.DataFrame(data)
|
30 |
+
return df
|
31 |
+
|
32 |
+
# Interfaz con una tabla como salida
|
33 |
+
interface_beto = gr.Interface(
|
34 |
+
fn=predict_entities,
|
35 |
+
inputs=gr.Textbox(lines=2, placeholder="Escribe un texto para analizar entidades"),
|
36 |
+
outputs=gr.Dataframe(headers=["Token", "entity", "Confianza (%)", "Inicio", "Fin"]),
|
37 |
+
title="BETO NER",
|
38 |
+
description="Prueba el modelo fine-tuneado de BETO en BioBERT para NER."
|
39 |
+
)
|
40 |
+
|
41 |
+
# Lanzar la interfaz
|
42 |
+
interface_beto.launch()
|