Spaces:
Paused
Paused
Commit
·
9c95361
1
Parent(s):
d64d47b
new exm
Browse files
app.py
CHANGED
@@ -1,51 +1,66 @@
|
|
1 |
import re
|
2 |
import gradio as gr
|
3 |
|
4 |
-
#
|
5 |
SIM_ENTITIES = {
|
6 |
-
"
|
7 |
-
"
|
8 |
-
"
|
9 |
-
"
|
|
|
|
|
|
|
|
|
|
|
10 |
}
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
entities = []
|
14 |
for phrase, label in SIM_ENTITIES.items():
|
15 |
for m in re.finditer(re.escape(phrase), text):
|
16 |
entities.append({
|
17 |
-
"entity": label,
|
18 |
"start": m.start(),
|
19 |
"end": m.end(),
|
20 |
})
|
21 |
return {"text": text, "entities": entities}
|
22 |
|
23 |
with gr.Blocks() as demo:
|
24 |
-
gr.Markdown("##
|
25 |
-
"
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
value="The Household Survey Data for Ethiopia in 2020 was published by the World Bank.",
|
30 |
label="Input Text",
|
31 |
-
|
|
|
32 |
)
|
33 |
-
btn = gr.Button("Highlight")
|
34 |
-
|
35 |
-
|
36 |
-
#
|
37 |
-
btn.click(fn=
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
gr.Markdown("""
|
43 |
**Legend**
|
44 |
-
- **named dataset** →
|
45 |
-
- **data geography** →
|
46 |
-
- **
|
47 |
-
- **
|
|
|
|
|
|
|
|
|
48 |
""")
|
49 |
|
50 |
if __name__ == "__main__":
|
51 |
-
demo.launch(
|
|
|
1 |
import re
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# Your actual GLiNER predictions
|
5 |
SIM_ENTITIES = {
|
6 |
+
"Home Visits Survey": "named dataset",
|
7 |
+
"Jordan": "data geography",
|
8 |
+
"Round II": "version",
|
9 |
+
"HV": "acronym",
|
10 |
+
"UNHCR": "author",
|
11 |
+
"World Food Programme": "author",
|
12 |
+
"2013": "reference year",
|
13 |
+
"2014": "publication year",
|
14 |
+
"detailed socio-economic, health, and protection data": "data description",
|
15 |
}
|
16 |
|
17 |
+
SAMPLE_TEXT = (
|
18 |
+
"The Jordan Home Visits Survey, Round II (HV), was carried out by UNHCR and the World Food "
|
19 |
+
"Programme between November 2013 and September 2014. Through in-home visits to Syrian refugee "
|
20 |
+
"households in Jordan, it gathered detailed socio-economic, health, and protection data—each "
|
21 |
+
"household tagged with a unique ID to allow longitudinal tracking."
|
22 |
+
)
|
23 |
+
|
24 |
+
def highlight_text(text):
|
25 |
entities = []
|
26 |
for phrase, label in SIM_ENTITIES.items():
|
27 |
for m in re.finditer(re.escape(phrase), text):
|
28 |
entities.append({
|
29 |
+
"entity": label,
|
30 |
"start": m.start(),
|
31 |
"end": m.end(),
|
32 |
})
|
33 |
return {"text": text, "entities": entities}
|
34 |
|
35 |
with gr.Blocks() as demo:
|
36 |
+
gr.Markdown("## GLiNER NER + RE Highlighting\n"
|
37 |
+
"This demo uses your model’s actual predictions to annotate the sample sentence.\n\n"
|
38 |
+
"**Labels & spans** matching your `ner` and `relations` outputs will be colored below.")
|
39 |
+
|
40 |
+
txt_in = gr.Textbox(
|
|
|
41 |
label="Input Text",
|
42 |
+
lines=4,
|
43 |
+
value=SAMPLE_TEXT
|
44 |
)
|
45 |
+
btn = gr.Button("Highlight Entities")
|
46 |
+
txt_out = gr.HighlightedText(label="Annotated Entities")
|
47 |
+
|
48 |
+
# wire up
|
49 |
+
btn.click(fn=highlight_text, inputs=txt_in, outputs=txt_out)
|
50 |
+
txt_in.submit(fn=highlight_text, inputs=txt_in, outputs=txt_out)
|
51 |
+
demo.load(fn=highlight_text, inputs=txt_in, outputs=txt_out)
|
52 |
+
|
|
|
53 |
gr.Markdown("""
|
54 |
**Legend**
|
55 |
+
- **named dataset** → Home Visits Survey
|
56 |
+
- **data geography** → Jordan
|
57 |
+
- **version** → Round II
|
58 |
+
- **acronym** → HV
|
59 |
+
- **author** → UNHCR, World Food Programme
|
60 |
+
- **reference year** → 2013
|
61 |
+
- **publication year** → 2014
|
62 |
+
- **data description** → detailed socio-economic, health, and protection data
|
63 |
""")
|
64 |
|
65 |
if __name__ == "__main__":
|
66 |
+
demo.launch()
|