Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,119 +1,118 @@
|
|
| 1 |
-
from typing import Dict, Union
|
| 2 |
-
from gliner import GLiNER
|
| 3 |
-
import gradio as gr
|
| 4 |
-
|
| 5 |
-
model = GLiNER.from_pretrained("BSC-NLP4BIA/chagas-ner",
|
| 6 |
-
revision="gliner-bi-small-v1.0_2025-02-11_15-59-05",
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
Sexo: Femenino
|
| 13 |
-
País de Nacimiento: Paraguay
|
| 14 |
-
Fecha de Nacimiento: XXXX
|
| 15 |
-
Resultado Chagas: Positivo
|
| 16 |
-
Informe: Seguimiento de consultas externas
|
| 17 |
-
Visita: Primera visita
|
| 18 |
-
Fecha: 20 de julio XXXX
|
| 19 |
-
Paciente paraguaya de 32 años diagnosticada con enfermedad de Chagas tras cribado comunitario. Sin antecedentes transfusionales ni de familiares afectados. Refiere buen estado general.
|
| 20 |
-
EF:
|
| 21 |
-
Buen estado general.
|
| 22 |
-
AC: rítmico, sin soplos.
|
| 23 |
-
AP: MVC sin hallazgos.
|
| 24 |
-
Abdomen blando, sin masas.
|
| 25 |
-
PLAN:
|
| 26 |
-
Solicitar estudio inicial de Chagas con ECG, ETT y serología.
|
| 27 |
-
Informe: Seguimiento de consultas externas
|
| 28 |
-
Visita: Seguimiento
|
| 29 |
-
Fecha: 10 de diciembre XXXX
|
| 30 |
-
Asintomática. PCR para T.cruzi negativa. ECG muestra ritmo sinusal con bloqueo de rama derecha. ETT sin alteraciones funcionales.
|
| 31 |
-
EF:
|
| 32 |
-
Sin cambios en exploración física.
|
| 33 |
-
PLAN:
|
| 34 |
-
Seguimiento anual con ECG y serología.
|
| 35 |
-
""
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
"
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
"
|
| 52 |
-
"
|
| 53 |
-
"
|
| 54 |
-
"
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
demo.
|
| 119 |
-
demo.launch(debug=True)
|
|
|
|
| 1 |
+
from typing import Dict, Union
|
| 2 |
+
from gliner import GLiNER
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
model = GLiNER.from_pretrained("BSC-NLP4BIA/chagas-ner",
|
| 6 |
+
# revision="gliner-bi-small-v1.0_2025-02-11_15-59-05",
|
| 7 |
+
revision="NuNER_Zero_2025-02-13_13-59-43_1"
|
| 8 |
+
load_tokenizer=True)
|
| 9 |
+
|
| 10 |
+
examples = [
|
| 11 |
+
[
|
| 12 |
+
"""Sexo: Femenino
|
| 13 |
+
País de Nacimiento: Paraguay
|
| 14 |
+
Fecha de Nacimiento: XXXX
|
| 15 |
+
Resultado Chagas: Positivo
|
| 16 |
+
Informe: Seguimiento de consultas externas
|
| 17 |
+
Visita: Primera visita
|
| 18 |
+
Fecha: 20 de julio XXXX
|
| 19 |
+
Paciente paraguaya de 32 años diagnosticada con enfermedad de Chagas tras cribado comunitario. Sin antecedentes transfusionales ni de familiares afectados. Refiere buen estado general.
|
| 20 |
+
EF:
|
| 21 |
+
Buen estado general.
|
| 22 |
+
AC: rítmico, sin soplos.
|
| 23 |
+
AP: MVC sin hallazgos.
|
| 24 |
+
Abdomen blando, sin masas.
|
| 25 |
+
PLAN:
|
| 26 |
+
Solicitar estudio inicial de Chagas con ECG, ETT y serología.
|
| 27 |
+
Informe: Seguimiento de consultas externas
|
| 28 |
+
Visita: Seguimiento
|
| 29 |
+
Fecha: 10 de diciembre XXXX
|
| 30 |
+
Asintomática. PCR para T.cruzi negativa. ECG muestra ritmo sinusal con bloqueo de rama derecha. ETT sin alteraciones funcionales.
|
| 31 |
+
EF:
|
| 32 |
+
Sin cambios en exploración física.
|
| 33 |
+
PLAN:
|
| 34 |
+
Seguimiento anual con ECG y serología.""",
|
| 35 |
+
"ENFERMEDAD, SINTOMA",
|
| 36 |
+
0.5,
|
| 37 |
+
False,
|
| 38 |
+
],
|
| 39 |
+
]
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def ner(
|
| 43 |
+
text, labels: str, threshold: float, nested_ner: bool
|
| 44 |
+
) -> Dict[str, Union[str, int, float]]:
|
| 45 |
+
labels = labels.split(",")
|
| 46 |
+
return {
|
| 47 |
+
"text": text,
|
| 48 |
+
"entities": [
|
| 49 |
+
{
|
| 50 |
+
"entity": entity["label"],
|
| 51 |
+
"word": entity["text"],
|
| 52 |
+
"start": entity["start"],
|
| 53 |
+
"end": entity["end"],
|
| 54 |
+
"score": 0,
|
| 55 |
+
}
|
| 56 |
+
for entity in model.predict_entities(
|
| 57 |
+
text, labels, flat_ner=not nested_ner, threshold=threshold
|
| 58 |
+
)
|
| 59 |
+
],
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
with gr.Blocks(title="GLiNER for Chagas detection - NER ") as demo:
|
| 64 |
+
|
| 65 |
+
input_text = gr.Textbox(
|
| 66 |
+
value=examples[0][0], label="Text input", placeholder="Enter your text here"
|
| 67 |
+
)
|
| 68 |
+
with gr.Row() as row:
|
| 69 |
+
labels = gr.Textbox(
|
| 70 |
+
value=examples[0][1],
|
| 71 |
+
label="Labels",
|
| 72 |
+
placeholder="Enter your labels here (comma separated)",
|
| 73 |
+
scale=2,
|
| 74 |
+
)
|
| 75 |
+
threshold = gr.Slider(
|
| 76 |
+
0,
|
| 77 |
+
1,
|
| 78 |
+
value=0.5,
|
| 79 |
+
step=0.01,
|
| 80 |
+
label="Threshold",
|
| 81 |
+
info="Lower the threshold to increase how many entities get predicted.",
|
| 82 |
+
scale=1,
|
| 83 |
+
)
|
| 84 |
+
nested_ner = gr.Checkbox(
|
| 85 |
+
value=examples[0][2],
|
| 86 |
+
label="Nested NER",
|
| 87 |
+
info="Allow for nested NER?",
|
| 88 |
+
scale=0,
|
| 89 |
+
)
|
| 90 |
+
output = gr.HighlightedText(label="Predicted Entities")
|
| 91 |
+
submit_btn = gr.Button("Submit")
|
| 92 |
+
examples = gr.Examples(
|
| 93 |
+
examples,
|
| 94 |
+
fn=ner,
|
| 95 |
+
inputs=[input_text, labels, threshold, nested_ner],
|
| 96 |
+
outputs=output,
|
| 97 |
+
cache_examples=True,
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
# Submitting
|
| 101 |
+
input_text.submit(
|
| 102 |
+
fn=ner, inputs=[input_text, labels, threshold, nested_ner], outputs=output
|
| 103 |
+
)
|
| 104 |
+
labels.submit(
|
| 105 |
+
fn=ner, inputs=[input_text, labels, threshold, nested_ner], outputs=output
|
| 106 |
+
)
|
| 107 |
+
threshold.release(
|
| 108 |
+
fn=ner, inputs=[input_text, labels, threshold, nested_ner], outputs=output
|
| 109 |
+
)
|
| 110 |
+
submit_btn.click(
|
| 111 |
+
fn=ner, inputs=[input_text, labels, threshold, nested_ner], outputs=output
|
| 112 |
+
)
|
| 113 |
+
nested_ner.change(
|
| 114 |
+
fn=ner, inputs=[input_text, labels, threshold, nested_ner], outputs=output
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
demo.queue()
|
| 118 |
+
demo.launch(debug=True)
|
|
|