Wesamalnabki-bsc commited on
Commit
876b314
·
verified ·
1 Parent(s): 538d257

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +119 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ load_tokenizer=True)
8
+
9
+ examples = [
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
+ "ENFERMEDAD, SINTOMA",
37
+ 0.4,
38
+ False,
39
+ ],
40
+ ]
41
+
42
+
43
+ def ner(
44
+ text, labels: str, threshold: float, nested_ner: bool
45
+ ) -> Dict[str, Union[str, int, float]]:
46
+ labels = labels.split(",")
47
+ return {
48
+ "text": text,
49
+ "entities": [
50
+ {
51
+ "entity": entity["label"],
52
+ "word": entity["text"],
53
+ "start": entity["start"],
54
+ "end": entity["end"],
55
+ "score": 0,
56
+ }
57
+ for entity in model.predict_entities(
58
+ text, labels, flat_ner=not nested_ner, threshold=threshold
59
+ )
60
+ ],
61
+ }
62
+
63
+
64
+ with gr.Blocks(title="GLiNER for Chagas detection - NER ") as demo:
65
+
66
+ input_text = gr.Textbox(
67
+ value=examples[0][0], label="Text input", placeholder="Enter your text here"
68
+ )
69
+ with gr.Row() as row:
70
+ labels = gr.Textbox(
71
+ value=examples[0][1],
72
+ label="Labels",
73
+ placeholder="Enter your labels here (comma separated)",
74
+ scale=2,
75
+ )
76
+ threshold = gr.Slider(
77
+ 0,
78
+ 1,
79
+ value=0.3,
80
+ step=0.01,
81
+ label="Threshold",
82
+ info="Lower the threshold to increase how many entities get predicted.",
83
+ scale=1,
84
+ )
85
+ nested_ner = gr.Checkbox(
86
+ value=examples[0][2],
87
+ label="Nested NER",
88
+ info="Allow for nested NER?",
89
+ scale=0,
90
+ )
91
+ output = gr.HighlightedText(label="Predicted Entities")
92
+ submit_btn = gr.Button("Submit")
93
+ examples = gr.Examples(
94
+ examples,
95
+ fn=ner,
96
+ inputs=[input_text, labels, threshold, nested_ner],
97
+ outputs=output,
98
+ cache_examples=True,
99
+ )
100
+
101
+ # Submitting
102
+ input_text.submit(
103
+ fn=ner, inputs=[input_text, labels, threshold, nested_ner], outputs=output
104
+ )
105
+ labels.submit(
106
+ fn=ner, inputs=[input_text, labels, threshold, nested_ner], outputs=output
107
+ )
108
+ threshold.release(
109
+ fn=ner, inputs=[input_text, labels, threshold, nested_ner], outputs=output
110
+ )
111
+ submit_btn.click(
112
+ fn=ner, inputs=[input_text, labels, threshold, nested_ner], outputs=output
113
+ )
114
+ nested_ner.change(
115
+ fn=ner, inputs=[input_text, labels, threshold, nested_ner], outputs=output
116
+ )
117
+
118
+ demo.queue()
119
+ demo.launch(debug=True)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gliner